[238] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.IO;
|
---|
| 4 |
|
---|
| 5 | using UnityEngine;
|
---|
| 6 |
|
---|
| 7 | namespace AllocsFixes.CustomCommands
|
---|
| 8 | {
|
---|
| 9 | public class ExportItemIcons : ConsoleCmdAbstract
|
---|
| 10 | {
|
---|
| 11 | public override string GetDescription ()
|
---|
| 12 | {
|
---|
| 13 | return "Exports all ItemIcons";
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | public override string GetHelp () {
|
---|
| 17 | return "Exports all ItemIcons currently in the game to the folder \"ItemIcons\" in the game root";
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | public override string[] GetCommands ()
|
---|
| 21 | {
|
---|
| 22 | return new string[] { "exportitemicons" };
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
|
---|
| 26 | string exportPath = Utils.GetGameDir ("ItemIcons");
|
---|
| 27 |
|
---|
| 28 | GameObject atlasObj = GameObject.Find ("/NGUI Root (2D)/ItemIconAtlas");
|
---|
| 29 | if (atlasObj == null) {
|
---|
| 30 | SdtdConsole.Instance.Output ("Atlas object not found");
|
---|
| 31 | return;
|
---|
| 32 | }
|
---|
| 33 | DynamicUIAtlas atlas = atlasObj.GetComponent<DynamicUIAtlas> ();
|
---|
| 34 | if (atlas == null) {
|
---|
| 35 | SdtdConsole.Instance.Output ("Atlas component not found");
|
---|
| 36 | return;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | Texture2D atlasTex = atlas.texture as Texture2D;
|
---|
| 40 |
|
---|
| 41 | if (Directory.Exists (exportPath)) {
|
---|
| 42 | SdtdConsole.Instance.Output ("Export path (" + exportPath + ") already exists");
|
---|
| 43 | return;
|
---|
| 44 | }
|
---|
| 45 | Directory.CreateDirectory (exportPath);
|
---|
| 46 |
|
---|
| 47 | foreach (UISpriteData data in atlas.spriteList) {
|
---|
| 48 | string name = data.name;
|
---|
| 49 | Texture2D tex = new Texture2D (data.width, data.height, TextureFormat.ARGB32, false);
|
---|
| 50 | tex.SetPixels (atlasTex.GetPixels (data.x, atlasTex.height - data.height - data.y, data.width, data.height));
|
---|
| 51 | byte[] pixData = tex.EncodeToPNG ();
|
---|
| 52 | File.WriteAllBytes (exportPath + "/" + name + ".png", pixData);
|
---|
| 53 |
|
---|
| 54 | UnityEngine.Object.Destroy (tex);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 | }
|
---|