diff --git a/Editor/TextPicIconEditor.cs b/Editor/TextPicIconEditor.cs new file mode 100644 index 0000000..c99ad8f --- /dev/null +++ b/Editor/TextPicIconEditor.cs @@ -0,0 +1,130 @@ +/* +The MIT License (MIT) + +Copyright (c) 2017 Play-Em + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif +using System; +using System.Collections; + +namespace UnityEngine.UI.Extensions +{ + + public class TextPicIconEditor : EditorWindow { + [MenuItem("Window/UI/Extensions/TextPic Edit Icons")] + protected static void ShowTextPicIconEditor() { + var wnd = GetWindow(); + wnd.titleContent.text = "Edit Icons in TextPic"; + wnd.Show(); + } + + private GameObject o; + + private static int columnWidth = 300; + + private string iconName; + private Sprite icon; + + public void Swap(GameObject o) { + #if UNITY_EDITOR + Debug.Log("Editing icons for " + o.name); + + + TextPic[] children = o.GetComponentsInChildren(true); + for(int i = 0; i < children.Length; i++) { + if (children[i] != null) { + for (int j = 0; j < children[i].inspectorIconList.Length; j++) { + if (!string.IsNullOrEmpty(iconName) + && children[i].inspectorIconList[j].name == iconName) { + children[i].inspectorIconList[j].sprite = icon; + Debug.Log("Swapped icon for " + children[i].inspectorIconList[j].name); + } + } + children[i].ResetIconList(); + + Debug.Log("Swapped icons for " + children[i].name); + } + } + #endif + } + + public void OnGUI() { + GUILayout.Label("Select a GameObject to edit TextPic icons", EditorStyles.boldLabel); + EditorGUILayout.Separator(); + GUILayout.Label("GameObject", EditorStyles.boldLabel); + + EditorGUI.BeginChangeCheck(); + + if (Selection.activeGameObject != null) { + o = Selection.activeGameObject; + } + EditorGUILayout.ObjectField(o, typeof(GameObject), true); + EditorGUI.EndChangeCheck(); + + if (o != null) { + EditorGUILayout.BeginHorizontal(); + + GUILayout.Label("Icon Name:", GUILayout.Width(columnWidth)); + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + + iconName = EditorGUILayout.TextField(iconName, GUILayout.Width(columnWidth)); + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.Separator(); + + EditorGUILayout.BeginHorizontal(); + + GUILayout.Label("New Sprite:", GUILayout.Width(columnWidth)); + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.Separator(); + + EditorGUILayout.BeginHorizontal(); + + icon = (Sprite)EditorGUILayout.ObjectField(icon, typeof(Sprite), false, GUILayout.Width(columnWidth)); + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.Separator(); + + EditorGUILayout.BeginHorizontal(); + if (GUILayout.Button("Edit Icons")) { + #if UNITY_EDITOR + Swap(o); + #endif + } + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.Separator(); + } + } + } + +} \ No newline at end of file diff --git a/Editor/TextPicIconListCopier.cs b/Editor/TextPicIconListCopier.cs new file mode 100644 index 0000000..72c1628 --- /dev/null +++ b/Editor/TextPicIconListCopier.cs @@ -0,0 +1,140 @@ +/* +The MIT License (MIT) + +Copyright (c) 2017 Play-Em + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif +using System; +using System.Collections; +using System.Collections.Generic; + +namespace UnityEngine.UI.Extensions +{ + + public class TextPicIconListCopier : EditorWindow { + [MenuItem("Window/UI/Extensions/TextPic Copy Icon Lists")] + protected static void ShowTextPicIconListCopier() { + var wnd = GetWindow(); + wnd.titleContent.text = "Copy Icons in TextPic"; + wnd.Show(); + } + + private List textPicList = new List(); + + #if UNITY_EDITOR + void OnSelectionChange() { + if (Selection.objects.Length > 1 ) + { + Debug.Log ("Length? " + Selection.objects.Length); + textPicList.Clear(); + + foreach ( Object o in Selection.objects ) { + if ( o is GameObject ) { + TextPic tp = ((GameObject)o).GetComponent(); + if (tp != null) { + textPicList.Add(tp); + } + } + } + } + else if (Selection.activeObject is GameObject) { + textPicList.Clear(); + TextPic tp = ((GameObject)Selection.activeObject).GetComponent(); + if (tp != null) { + textPicList.Add(tp); + } + } + else { + textPicList.Clear(); + } + + this.Repaint(); + } + #endif + + private static int columnWidth = 300; + + private TextPic textPic; + + public void Copy() { + #if UNITY_EDITOR + foreach(TextPic tp in textPicList) { + if (tp != null) { + tp.inspectorIconList = new TextPic.IconName[textPic.inspectorIconList.Length]; + textPic.inspectorIconList.CopyTo(tp.inspectorIconList, 0); + + tp.ResetIconList(); + + Debug.Log("Copied icons to " + tp.name); + } + } + #endif + } + + public void OnGUI() { + GUILayout.Label("TextPic to copy icons", EditorStyles.boldLabel); + EditorGUILayout.Separator(); + GUILayout.Label("TextPic", EditorStyles.boldLabel); + + EditorGUI.BeginChangeCheck(); + + textPic = EditorGUILayout.ObjectField(textPic, typeof(TextPic), true) as TextPic; + EditorGUI.EndChangeCheck(); + + if (textPicList.Count > 0) { + if ( textPicList.Count == 1 ) + { + textPicList[0] = ((TextPic)EditorGUILayout.ObjectField( + textPicList[0], + typeof(TextPic), + true, + GUILayout.Width(columnWidth)) + ); + } + else + { + GUILayout.Label("Multiple TextPic: " + textPicList.Count, GUILayout.Width(columnWidth)); + } + + if (textPic != null) { + + EditorGUILayout.BeginHorizontal(); + if (GUILayout.Button("Copy Icons")) { + #if UNITY_EDITOR + Copy(); + #endif + } + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.Separator(); + } + } + else { + GUILayout.Label("Please select objects that have a TextPic component", EditorStyles.boldLabel); + } + } + } + +} \ No newline at end of file diff --git a/Editor/TextPicRenameEditor.cs b/Editor/TextPicRenameEditor.cs new file mode 100644 index 0000000..d723ee9 --- /dev/null +++ b/Editor/TextPicRenameEditor.cs @@ -0,0 +1,161 @@ +/* +The MIT License (MIT) + +Copyright (c) 2014 Play-Em + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif +using System; +using System.Collections; + +namespace UnityEngine.UI.Extensions +{ + + public class TextPicRenameEditor : EditorWindow { + [MenuItem("Window/UI/Extensions/TextPic Rename Icons and Text")] + protected static void ShowTextPicRenameEditor() { + var wnd = GetWindow(); + wnd.titleContent.text = "Rename Icon List"; + wnd.Show(); + } + + private GameObject o; + + private static int columnWidth = 300; + + private string prefix; + private string suffix; + private string originalText; + private string replacementText; + + public void Rename(GameObject o) { + #if UNITY_EDITOR + Debug.Log("Changing icons and text for " + o.name); + + + TextPic[] children = o.GetComponentsInChildren(true); + for(int i = 0; i < children.Length; i++) { + if (children[i] != null) { + for (int j = 0; j < children[i].inspectorIconList.Length; j++) { + if (!string.IsNullOrEmpty(originalText) + && children[i].inspectorIconList[j].name.Contains(originalText)) { + children[i].text.Replace(originalText, replacementText); + children[i].inspectorIconList[j].name = children[i].inspectorIconList[j].name.Replace(originalText, replacementText); + Debug.Log("Renamed icon for " + children[i].inspectorIconList[j].name); + } + + if (!string.IsNullOrEmpty(prefix) + && !string.IsNullOrEmpty(suffix) + && !children[i].inspectorIconList[j].name.StartsWith(prefix) + && !children[i].inspectorIconList[j].name.EndsWith(suffix)) { + children[i].text.Replace(children[i].inspectorIconList[j].name, prefix + children[i].inspectorIconList[j].name + suffix); + children[i].inspectorIconList[j].name = prefix + children[i].inspectorIconList[j].name + suffix; + Debug.Log("Renamed icon for " + children[i].inspectorIconList[j].name); + } + } + children[i].ResetIconList(); + + Debug.Log("Renamed icons for " + children[i].name); + } + } + #endif + } + + public void OnGUI() { + GUILayout.Label("Select a GameObject to rename TextPic icons and text", EditorStyles.boldLabel); + EditorGUILayout.Separator(); + GUILayout.Label("GameObject", EditorStyles.boldLabel); + + EditorGUI.BeginChangeCheck(); + + if (Selection.activeGameObject != null) { + o = Selection.activeGameObject; + } + EditorGUILayout.ObjectField(o, typeof(GameObject), true); + EditorGUI.EndChangeCheck(); + + if (o != null) { + + EditorGUILayout.BeginHorizontal(); + + GUILayout.Label("Prefix:", GUILayout.Width(columnWidth)); + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + + prefix = EditorGUILayout.TextField(prefix, GUILayout.Width(columnWidth)); + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.Separator(); + + EditorGUILayout.BeginHorizontal(); + + GUILayout.Label("Original Text:", GUILayout.Width(columnWidth)); + + GUILayout.Label("Replacement Text:", GUILayout.Width(columnWidth)); + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.Separator(); + + EditorGUILayout.BeginHorizontal(); + + originalText = EditorGUILayout.TextField(originalText, GUILayout.Width(columnWidth)); + + replacementText = EditorGUILayout.TextField(replacementText, GUILayout.Width(columnWidth)); + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.Separator(); + + EditorGUILayout.BeginHorizontal(); + GUILayout.Label("Suffix:", GUILayout.Width(columnWidth)); + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.Separator(); + + EditorGUILayout.BeginHorizontal(); + suffix = EditorGUILayout.TextField(suffix, GUILayout.Width(columnWidth)); + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.Separator(); + + EditorGUILayout.BeginHorizontal(); + if (GUILayout.Button("Rename Icons and Text")) { + #if UNITY_EDITOR + Rename(o); + #endif + } + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.Separator(); + } + } + } + +} \ No newline at end of file