Unity3D实现读取图片的简单示例

UISprite2D spMoney;

// 第一unity3d www.1unity3d.com

// 钻石建造卷图标
string path = ResourcePath.Icon.money + "/" + "";                   // 读取本地路径
spMoney.sprite2D = NGUITools.LoadAsset<Sprite>(path);        // 将读取的路径转化成sprite格式
  
// 金币建造卷图标
Texture2D textureGoldBuild = Resources.Load("Icon/money/") as Texture2D;   // 将读取的本地的路径转化成Texture2D类型
Sprite spriteGoldBuild = Sprite.Create(
   textureGoldBuild,
   new Rect(0, 0, textureGoldBuild.width, textureGoldBuild.height),
   new Vector2(0.5f, 0.5f)
);
spMoney.sprite2D = spriteGoldBuild;

case 1:

// 第一unity3d www.1unity3d.com
//金币
ResourcePath.Icon.money = "Icon/money";

path = ResourcePath.Icon.money + "/" + "gold";
mustGetRewardIcon.sprite2D = NGUITools.LoadAsset<Sprite>(path);

 

未经允许不得转载:第一Unity3D » Unity3D实现读取图片的简单示例

赞 (0)