Tanoda
TextPicIconEditor.cs
Go to the documentation of this file.
1/*
2The MIT License (MIT)
3
4Copyright (c) 2017 Play-Em
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22THE SOFTWARE.
23*/
24using UnityEngine;
25#if UNITY_EDITOR
26using UnityEditor;
27#endif
28using System;
29using System.Collections;
30
32{
33
34 public class TextPicIconEditor : EditorWindow {
35 [MenuItem("Window/UI/Extensions/TextPic Edit Icons")]
36 protected static void ShowTextPicIconEditor() {
37 var wnd = GetWindow<TextPicIconEditor>();
38 wnd.titleContent.text = "Edit Icons in TextPic";
39 wnd.Show();
40 }
41
42 private GameObject o;
43
44 private static int columnWidth = 300;
45
46 private string iconName;
47 private Sprite icon;
48
49 public void Swap(GameObject o) {
50 #if UNITY_EDITOR
51 Debug.Log("Editing icons for " + o.name);
52
53
54 TextPic[] children = o.GetComponentsInChildren<TextPic>(true);
55 for(int i = 0; i < children.Length; i++) {
56 if (children[i] != null) {
57 for (int j = 0; j < children[i].inspectorIconList.Length; j++) {
58 if (!string.IsNullOrEmpty(iconName)
59 && children[i].inspectorIconList[j].name == iconName) {
60 children[i].inspectorIconList[j].sprite = icon;
61 Debug.Log("Swapped icon for " + children[i].inspectorIconList[j].name);
62 }
63 }
64 children[i].ResetIconList();
65
66 Debug.Log("Swapped icons for " + children[i].name);
67 }
68 }
69 #endif
70 }
71
72 public void OnGUI() {
73 GUILayout.Label("Select a GameObject to edit TextPic icons", EditorStyles.boldLabel);
74 EditorGUILayout.Separator();
75 GUILayout.Label("GameObject", EditorStyles.boldLabel);
76
77 EditorGUI.BeginChangeCheck();
78
79 if (Selection.activeGameObject != null) {
80 o = Selection.activeGameObject;
81 }
82 EditorGUILayout.ObjectField(o, typeof(GameObject), true);
83 EditorGUI.EndChangeCheck();
84
85 if (o != null) {
86 EditorGUILayout.BeginHorizontal();
87
88 GUILayout.Label("Icon Name:", GUILayout.Width(columnWidth));
89
90 EditorGUILayout.EndHorizontal();
91
92 EditorGUILayout.BeginHorizontal();
93
94 iconName = EditorGUILayout.TextField(iconName, GUILayout.Width(columnWidth));
95
96 EditorGUILayout.EndHorizontal();
97
98 EditorGUILayout.Separator();
99
100 EditorGUILayout.BeginHorizontal();
101
102 GUILayout.Label("New Sprite:", GUILayout.Width(columnWidth));
103
104 EditorGUILayout.EndHorizontal();
105
106 EditorGUILayout.Separator();
107
108 EditorGUILayout.BeginHorizontal();
109
110 icon = (Sprite)EditorGUILayout.ObjectField(icon, typeof(Sprite), false, GUILayout.Width(columnWidth));
111
112 EditorGUILayout.EndHorizontal();
113
114 EditorGUILayout.Separator();
115
116 EditorGUILayout.BeginHorizontal();
117 if (GUILayout.Button("Edit Icons")) {
118 #if UNITY_EDITOR
119 Swap(o);
120 #endif
121 }
122
123 EditorGUILayout.EndHorizontal();
124
125 EditorGUILayout.Separator();
126 }
127 }
128 }
129
130}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
void ResetIconList()
METHODS ///.
Definition: TextPic.cs:197
Credit Erdener Gonenc - @PixelEnvision.