您好,登錄后才能下訂單哦!
注意文件以及文件夾必須寄宿在Resources目錄下,才能順利調(diào)用Resources.Load()和Resources.loadAll()這兩個函數(shù)得到所需要的圖像文件。
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);
}
}
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。