private static List <UISpriteData> GetSprites() { var gameObject = GameObject.Find("/NGUI Root (2D)/ItemIconAtlas"); if (gameObject == null) { SendOutput("Atlas object not found"); return(null); } var component = gameObject.GetComponent <DynamicUIAtlas>(); if (component == null) { SendOutput("Atlas component not found"); return(null); } var prebakedAtlas = component.PrebakedAtlas; if (!DynamicUIAtlasTools.ReadPrebakedAtlasDescriptor(prebakedAtlas, out var sprites, out int _, out int _)) { SendOutput("Could not read dynamic atlas descriptor"); return(null); } if (!DynamicUIAtlasTools.ReadPrebakedAtlasTexture(prebakedAtlas, out var texture2D)) { SendOutput("Could not read dynamic atlas texture"); return(null); } Resources.UnloadAsset(texture2D); return(sprites); }
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); }