source: binary-improvements/AllocsCommands/Commands/ExportItemIcons.cs@ 284

Last change on this file since 284 was 238, checked in by alloc, 9 years ago

Server fixes for A12

File size: 1.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.IO;
4
5using UnityEngine;
6
7namespace 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}
Note: See TracBrowser for help on using the repository browser.