unity3d 第十一天
来源:互联网 发布:姓名签名设计软件 编辑:程序博客网 时间:2024/05/23 19:32
昨天的改好了 但还是有问题
Texture_text.cs
using UnityEngine;using System.Collections;public class Texture_test : MonoBehaviour {Texture2D texSingle;Object[] texAll;// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () {}void OnGUI(){//Resources.Load 返回的是object Resources.LoadAll() 返回的是object[];if (GUI.Button (new Rect (0, 10, 100, 50), "加载一张贴图")) {if(texSingle == null){//texSingle = (Resources.Load("3"))as Texture2D;texSingle = (Texture2D)Resources.Load("3");}}if (GUI.Button (new Rect (0, 130, 100, 50), "加载一组贴图")) {if(texAll == null){//加载所有贴图texAll = Resources.LoadAll("Textures");//texAll = Resources.LoadAll("Textures", typeof(Texture2D));}}if (texSingle != null){//绘制一张贴图GUI.DrawTexture(new Rect(110,10,120,120),texSingle,ScaleMode.StretchToFill,true,0);}if (texAll != null) {for (int i =0; i<texAll.Length; i++) {GUI.DrawTexture (new Rect (110 + i * 1, 130, 120, 120), (Texture2D)texAll[i], ScaleMode.StretchToFill, true, 0);}int j = texAll.Length;Debug.Log (j);} else {GUI.Label(new Rect(140,130,100,50),"asd");}}}
加载所有贴图出问题了 texAll.length 始终为 0.
问题解决了 Resources.LoadAll("path") path 为Resources文件夹下 的目录或者图片名 才能正常载入
改了之后只显示最后一张是因为 GUI.DrawTexture(new Rect(110+i * 1,130,120,120) 在测试时120 改为了1 ,所以重叠了。
完整代码
using UnityEngine;using System.Collections;public class Texture_test : MonoBehaviour {Texture2D texSingle;Object[] texAll;// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () {}void OnGUI(){//Resources.Load 返回的是object Resources.LoadAll() 返回的是object[];if (GUI.Button (new Rect (0, 10, 100, 50), "加载一张贴图")) {if(texSingle == null){//texSingle = (Resources.Load("3"))as Texture2D;texSingle = (Texture2D)Resources.Load("3");}}if (GUI.Button (new Rect (0, 130, 100, 50), "加载一组贴图")) {if(texAll == null){//加载所有贴图texAll = Resources.LoadAll("texture");//texAll = Resources.LoadAll("Textures", typeof(Texture2D));}}if (texSingle != null){//绘制一张贴图GUI.DrawTexture(new Rect(110,10,120,120),texSingle,ScaleMode.StretchToFill,true,0);}if (texAll != null) {for (int i =0; i<texAll.Length; i++) {GUI.DrawTexture (new Rect (110 + i * 120, 130, 120, 120), (Texture2D)texAll[i], ScaleMode.StretchToFill, true, 0);}int j = texAll.Length;Debug.Log (j);} else {GUI.Label(new Rect(140,130,100,50),"asd");}}}
0 0
- unity3d 第十一天
- 学习Unity3D第十一天之方法重载。
- Unity3D笔记第十一天——碰撞器
- 第十一天
- 第十一天
- 第十一天
- 第十一天
- 第十一天
- 第十一天
- 世界杯第十一天
- 第十一天 优先级
- 第十一天:听课笔记
- 第十一天:总结
- 第十一天总结0403
- 5.20 第十一天 坚决
- 星海第十一天
- 实习日记->第十一天
- 程序学习第十一天
- session入redis
- CSVs in Python 2
- EasyUI ComboBox(下拉列表框)
- 构造对象 的使用 以及 引入static
- shell--指“提供使用者使用界面”的软件(命令解析器)
- unity3d 第十一天
- protobuf语言指南
- MachineLearning03_SVM算法
- 杭电女生赛—Combine String
- win10MySQL数据库安装与配置详解
- 【HDU 1025】Constructing Roads In JGShining's Kingdom(最长上升子序列LIS)
- cpuinfo和lscpu查看CPU相关的信息
- hdoj 1037 今年暑假不AC (区间问题 至少问题)
- DL学习笔记【4】caffe+win10+VS2013+cuda6.5+python安装过程