Tanoda
TextPicRenameEditor.cs
Go to the documentation of this file.
1/*
2The MIT License (MIT)
3
4Copyright (c) 2014 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 TextPicRenameEditor : EditorWindow {
35 [MenuItem("Window/UI/Extensions/TextPic Rename Icons and Text")]
36 protected static void ShowTextPicRenameEditor() {
37 var wnd = GetWindow<TextPicRenameEditor>();
38 wnd.titleContent.text = "Rename Icon List";
39 wnd.Show();
40 }
41
42 private GameObject o;
43
44 private static int columnWidth = 300;
45
46 private string prefix;
47 private string suffix;
48 private string originalText;
49 private string replacementText;
50
51 public void Rename(GameObject o) {
52 #if UNITY_EDITOR
53 Debug.Log("Changing icons and text for " + o.name);
54
55
56 TextPic[] children = o.GetComponentsInChildren<TextPic>(true);
57 for(int i = 0; i < children.Length; i++) {
58 if (children[i] != null) {
59 for (int j = 0; j < children[i].inspectorIconList.Length; j++) {
60 if (!string.IsNullOrEmpty(originalText)
61 && children[i].inspectorIconList[j].name.Contains(originalText)) {
62 children[i].text.Replace(originalText, replacementText);
63 children[i].inspectorIconList[j].name = children[i].inspectorIconList[j].name.Replace(originalText, replacementText);
64 Debug.Log("Renamed icon for " + children[i].inspectorIconList[j].name);
65 }
66
67 if (!string.IsNullOrEmpty(prefix)
68 && !string.IsNullOrEmpty(suffix)
69 && !children[i].inspectorIconList[j].name.StartsWith(prefix)
70 && !children[i].inspectorIconList[j].name.EndsWith(suffix)) {
71 children[i].text.Replace(children[i].inspectorIconList[j].name, prefix + children[i].inspectorIconList[j].name + suffix);
72 children[i].inspectorIconList[j].name = prefix + children[i].inspectorIconList[j].name + suffix;
73 Debug.Log("Renamed icon for " + children[i].inspectorIconList[j].name);
74 }
75 }
76 children[i].ResetIconList();
77
78 Debug.Log("Renamed icons for " + children[i].name);
79 }
80 }
81 #endif
82 }
83
84 public void OnGUI() {
85 GUILayout.Label("Select a GameObject to rename TextPic icons and text", EditorStyles.boldLabel);
86 EditorGUILayout.Separator();
87 GUILayout.Label("GameObject", EditorStyles.boldLabel);
88
89 EditorGUI.BeginChangeCheck();
90
91 if (Selection.activeGameObject != null) {
92 o = Selection.activeGameObject;
93 }
94 EditorGUILayout.ObjectField(o, typeof(GameObject), true);
95 EditorGUI.EndChangeCheck();
96
97 if (o != null) {
98
99 EditorGUILayout.BeginHorizontal();
100
101 GUILayout.Label("Prefix:", GUILayout.Width(columnWidth));
102
103 EditorGUILayout.EndHorizontal();
104
105 EditorGUILayout.BeginHorizontal();
106
107 prefix = EditorGUILayout.TextField(prefix, GUILayout.Width(columnWidth));
108
109 EditorGUILayout.EndHorizontal();
110
111 EditorGUILayout.Separator();
112
113 EditorGUILayout.BeginHorizontal();
114
115 GUILayout.Label("Original Text:", GUILayout.Width(columnWidth));
116
117 GUILayout.Label("Replacement Text:", GUILayout.Width(columnWidth));
118
119 EditorGUILayout.EndHorizontal();
120
121 EditorGUILayout.Separator();
122
123 EditorGUILayout.BeginHorizontal();
124
125 originalText = EditorGUILayout.TextField(originalText, GUILayout.Width(columnWidth));
126
127 replacementText = EditorGUILayout.TextField(replacementText, GUILayout.Width(columnWidth));
128
129 EditorGUILayout.EndHorizontal();
130
131 EditorGUILayout.Separator();
132
133 EditorGUILayout.BeginHorizontal();
134 GUILayout.Label("Suffix:", GUILayout.Width(columnWidth));
135
136 EditorGUILayout.EndHorizontal();
137
138 EditorGUILayout.Separator();
139
140 EditorGUILayout.BeginHorizontal();
141 suffix = EditorGUILayout.TextField(suffix, GUILayout.Width(columnWidth));
142
143 EditorGUILayout.EndHorizontal();
144
145 EditorGUILayout.Separator();
146
147 EditorGUILayout.BeginHorizontal();
148 if (GUILayout.Button("Rename Icons and Text")) {
149 #if UNITY_EDITOR
150 Rename(o);
151 #endif
152 }
153
154 EditorGUILayout.EndHorizontal();
155
156 EditorGUILayout.Separator();
157 }
158 }
159 }
160
161}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
void ResetIconList()
METHODS ///.
Definition: TextPic.cs:197
Credit Erdener Gonenc - @PixelEnvision.