Tanoda
TextPicIconListCopier.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;
30using System.Collections.Generic;
31
33{
34
35 public class TextPicIconListCopier : EditorWindow {
36 [MenuItem("Window/UI/Extensions/TextPic Copy Icon Lists")]
37 protected static void ShowTextPicIconListCopier() {
38 var wnd = GetWindow<TextPicIconListCopier>();
39 wnd.titleContent.text = "Copy Icons in TextPic";
40 wnd.Show();
41 }
42
43 private List<TextPic> textPicList = new List<TextPic>();
44
45 #if UNITY_EDITOR
46 void OnSelectionChange() {
47 if (Selection.objects.Length > 1 )
48 {
49 Debug.Log ("Length? " + Selection.objects.Length);
50 textPicList.Clear();
51
52 foreach ( Object o in Selection.objects ) {
53 if ( o is GameObject ) {
54 TextPic tp = ((GameObject)o).GetComponent<TextPic>();
55 if (tp != null) {
56 textPicList.Add(tp);
57 }
58 }
59 }
60 }
61 else if (Selection.activeObject is GameObject) {
62 textPicList.Clear();
63 TextPic tp = ((GameObject)Selection.activeObject).GetComponent<TextPic>();
64 if (tp != null) {
65 textPicList.Add(tp);
66 }
67 }
68 else {
69 textPicList.Clear();
70 }
71
72 this.Repaint();
73 }
74 #endif
75
76 private static int columnWidth = 300;
77
78 private TextPic textPic;
79
80 public void Copy() {
81 #if UNITY_EDITOR
82 foreach(TextPic tp in textPicList) {
83 if (tp != null) {
84 tp.inspectorIconList = new TextPic.IconName[textPic.inspectorIconList.Length];
85 textPic.inspectorIconList.CopyTo(tp.inspectorIconList, 0);
86
87 tp.ResetIconList();
88
89 Debug.Log("Copied icons to " + tp.name);
90 }
91 }
92 #endif
93 }
94
95 public void OnGUI() {
96 GUILayout.Label("TextPic to copy icons", EditorStyles.boldLabel);
97 EditorGUILayout.Separator();
98 GUILayout.Label("TextPic", EditorStyles.boldLabel);
99
100 EditorGUI.BeginChangeCheck();
101
102 textPic = EditorGUILayout.ObjectField(textPic, typeof(TextPic), true) as TextPic;
103 EditorGUI.EndChangeCheck();
104
105 if (textPicList.Count > 0) {
106 if ( textPicList.Count == 1 )
107 {
108 textPicList[0] = ((TextPic)EditorGUILayout.ObjectField(
109 textPicList[0],
110 typeof(TextPic),
111 true,
112 GUILayout.Width(columnWidth))
113 );
114 }
115 else
116 {
117 GUILayout.Label("Multiple TextPic: " + textPicList.Count, GUILayout.Width(columnWidth));
118 }
119
120 if (textPic != null) {
121
122 EditorGUILayout.BeginHorizontal();
123 if (GUILayout.Button("Copy Icons")) {
124 #if UNITY_EDITOR
125 Copy();
126 #endif
127 }
128
129 EditorGUILayout.EndHorizontal();
130
131 EditorGUILayout.Separator();
132 }
133 }
134 else {
135 GUILayout.Label("Please select objects that have a TextPic component", EditorStyles.boldLabel);
136 }
137 }
138 }
139
140}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
void ResetIconList()
METHODS ///.
Definition: TextPic.cs:197
Credit Erdener Gonenc - @PixelEnvision.
UnityEngine.Object Object