// 从文件中添加资源 public static UITextureAtlas AddTextureAtlasFromFile(string[] spriteNames, string Path) { createStaticAtlas(); Texture2D[] textures = new Texture2D[spriteNames.Length]; for (int i = 0; i < spriteNames.Length; i++) { textures[i] = MUIUtil.loadTextureFromFile(Path + spriteNames[i] + ".png"); textures[i].name = spriteNames[i]; } AddTextures(textures); //Rect[] regions = new Rect[spriteNames.Length]; //regions = ((Texture2D)(m_atlas.material.mainTexture)).PackTextures(textures, 2, 1024); //for (int i = 0; i < spriteNames.Length; i++) //{ // UITextureAtlas.SpriteInfo item = new UITextureAtlas.SpriteInfo // { // name = spriteNames[i], // texture = textures[i], // region = regions[i], // }; // m_atlas.AddSprite(item); //} return(m_atlas); }
public static void AddTextureSpriteInfoFromFile(string spriteName, string file, RectOffset Border) { Texture2D texture = MUIUtil.loadTextureFromFile(file); if (texture == null) { return; } UITextureAtlas.SpriteInfo sprite = new UITextureAtlas.SpriteInfo { name = spriteName, texture = texture, border = Border }; AddTextureSpriteInfo(sprite); }