// LoadAdditionalIconsInAtlas(uiAtlas, "C:/SDXModding/Game/Working/Mods/SDX/UI/Icons") public static void LoadAdditionalIconsInAtlas(UIAtlas atlas, string iconsPath) { DynamicUIAtlas dynUiAtlas = atlas as DynamicUIAtlas; //DynamicUIAtlas dynUiAtlas = uiAtlas.gameObject.GetComponent<DynamicUIAtlas>(); if (dynUiAtlas == null) { DebugMsg("No DynamicUIAtlas component on uiAtlas"); return; } //DynamicUIAtlas dynUiAtlas = new DynamicUIAtlas(); dynUiAtlas.ResetAtlas(); Dictionary <string, Texture2D> dictionary = new Dictionary <string, Texture2D>(); DebugMsg("uiAtlas DynamicUIAtlas PrebakedAtlas = " + dynUiAtlas.PrebakedAtlas); //string path = "C:/SDXModding/Game/Working/Mods/SDX/UI/Icons"; if (Directory.Exists(iconsPath)) { string[] array = Directory.GetFiles(iconsPath); foreach (string image in array) { if (image.ToLower().EndsWith(".png")) { DebugMsg("Adding icon to UIAtlas: " + image); Texture2D texture2D = new Texture2D(1, 1, TextureFormat.ARGB32, false); if (texture2D.LoadImage(File.ReadAllBytes(image))) { dictionary.Add(Path.GetFileNameWithoutExtension(image), texture2D); } else { UnityEngine.Object.Destroy(texture2D); } } } dynUiAtlas.LoadAdditionalSprites(dictionary); foreach (Texture2D obj in dictionary.Values) { UnityEngine.Object.Destroy(obj); } dynUiAtlas.Compress(); } else { DebugMsg("Cannot find path: " + iconsPath); } }
public override void Execute(List <string> _params, CommandSenderInfo _senderInfo) { string exportPath = Utils.GetGameDir("ItemIcons"); GameObject atlasObj = GameObject.Find("/NGUI Root (2D)/ItemIconAtlas"); if (atlasObj == null) { SdtdConsole.Instance.Output("Atlas object not found"); return; } DynamicUIAtlas atlas = atlasObj.GetComponent <DynamicUIAtlas> (); if (atlas == null) { SdtdConsole.Instance.Output("Atlas component not found"); return; } Texture2D atlasTex = atlas.texture as Texture2D; if (Directory.Exists(exportPath)) { SdtdConsole.Instance.Output("Export path (" + exportPath + ") already exists"); return; } Directory.CreateDirectory(exportPath); foreach (UISpriteData data in atlas.spriteList) { string name = data.name; Texture2D tex = new Texture2D(data.width, data.height, TextureFormat.ARGB32, false); tex.SetPixels(atlasTex.GetPixels(data.x, atlasTex.height - data.height - data.y, data.width, data.height)); byte[] pixData = tex.EncodeToPNG(); File.WriteAllBytes(exportPath + "/" + name + ".png", pixData); UnityEngine.Object.Destroy(tex); } }
public static void WriteItemIconAtlasImageToDisc() { //EntityPlayerLocal player = GameManager.Instance.World.GetLocalPlayer() as EntityPlayerLocal; EntityPlayerLocal player = GameManager.Instance.World.GetPrimaryPlayer(); if (player == null) { Debug.LogError("WriteItemIconAtlasImageToDisc: Cannot find Local Player, aborting!"); return; } LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(player); UIAtlas uiAtlas = uiforPlayer.xui.GetAtlasByName("UIAtlas"); UIAtlas itemIconAtlas = uiforPlayer.xui.GetAtlasByName("itemIconAtlas"); DynamicUIAtlas dynItemIconAtlas = itemIconAtlas.gameObject.GetComponent <DynamicUIAtlas>(); if (dynItemIconAtlas != null) { DebugMsg("itemIconAtlas PrebakedAtlas: " + dynItemIconAtlas.PrebakedAtlas); } else { DebugMsg("Cannot find dynItemIconAtlas"); } Texture2D texture2Dsrc; //if (!DynamicUIAtlasTools.ReadPrebakedAtlasTexture(dynItemIconAtlas.PrebakedAtlas, out texture2DSrc)) if (!DynamicUIAtlasTools.ReadPrebakedAtlasTexture("GUI/Atlases/UIAtlas", out texture2Dsrc)) { DebugMsg("Could not read dynamic atlas texture"); return; } DebugMsg("itemIconAtlas Texture: " + texture2Dsrc.name + " (" + texture2Dsrc.width.ToString() + "x" + texture2Dsrc.height.ToString() + ")"); Texture2D texture2D = new Texture2D(texture2Dsrc.width, texture2Dsrc.height, TextureFormat.ARGB32, false); texture2D.SetPixels(texture2Dsrc.GetPixels()); byte[] bytes = texture2D.EncodeToPNG(); //File.WriteAllBytes("C:/SDXModding/Gimp/itemIconAtlas_extract.png", bytes); File.WriteAllBytes("C:/SDXModding/Gimp/ui_atlas_extract.png", bytes); UnityEngine.Object.Destroy(texture2D); Resources.UnloadAsset(texture2Dsrc); //Texture2D texture2Dsrc; if (!DynamicUIAtlasTools.ReadPrebakedAtlasTexture(dynItemIconAtlas.PrebakedAtlas, out texture2D)) { SingletonMonoBehaviour <SdtdConsole> .Instance.Output("Could not read dynamic atlas texture"); return; } //DebugMsg("uiAtlas Texture: " + uiAtlas.texture.name + " (" + uiAtlas.texture.width.ToString() + "x" + uiAtlas.texture.height.ToString() + ")"); texture2D = new Texture2D(uiAtlas.texture.width, uiAtlas.texture.height, TextureFormat.ARGB32, false); texture2D.SetPixels(((Texture2D)uiAtlas.texture).GetPixels()); bytes = texture2D.EncodeToPNG(); File.WriteAllBytes("C:/SDXModding/Gimp/ui_atlas_extract.png", bytes); //DebugMsg("itemIconAtlas Texture: " + itemIconAtlas.texture.name + " (" + itemIconAtlas.texture.width.ToString() + "x" + itemIconAtlas.texture.height.ToString() + ")"); texture2D = new Texture2D(itemIconAtlas.texture.width, itemIconAtlas.texture.height, TextureFormat.ARGB32, false); texture2D.SetPixels(((Texture2D)itemIconAtlas.texture).GetPixels()); bytes = texture2D.EncodeToPNG(); File.WriteAllBytes("C:/SDXModding/Gimp/itemIconAtlas_extract.png", bytes); UnityEngine.Object.Destroy(texture2D); Resources.UnloadAsset(texture2Dsrc); }