您好,登錄后才能下訂單哦!
注意文件以及文件夾必須寄宿在Resources目錄下,才能順利調用Resources.Load()和Resources.loadAll()這兩個函數得到所需要的圖像文件。
public class GUITest : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
private Texture2D texSingle;
private Texture2D[] texAll;
void OnGUI()
{
if (GUI.Button(new Rect(0,10,100,50),"加載一張貼圖"))
{
if (texSingle==null)
{
texSingle = Resources.Load("single/0") as Texture2D; //這里不需要加后綴
}
}
if (GUI.Button(new Rect(0,130,100,50),"加載一組貼圖"))
{
if (texAll==null)
{
var textures = Resources.LoadAll("textures");
int countAll=textures.Length;
texAll=new Texture2D[countAll];
for (int i = 0; i < countAll; i++)
{
texAll[i] = textures[i] as Texture2D;
}
}
}
//繪制貼圖
if (texSingle!=null)
{
GUI.DrawTexture(new Rect(110,10,80,80),texSingle,ScaleMode.ScaleToFit,true,0);
}
if (texAll!=null)
{
int countOfAll = texAll.Length;
for (int i = 0; i < countOfAll; i++)
{
GUI.DrawTexture(new Rect(110+i*80,130,80,80),texAll[i],ScaleMode.ScaleToFit,true,0);
}
}
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。