1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
/// ProFlares - v1.08 - Copyright 2014-2015 All rights reserved - ProFlares.com
/// <summary>
/// ProFlareAtlasInspector.cs
/// Custom inspector for the ProFlareAtlas
/// </summary>
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(ProFlareAtlas))]
public class ProFlareAtlasInspector : Editor {
ProFlareAtlas _ProFlareAtlas;
public string renameString;
bool listeningForGuiChanges;
bool guiChanged = false;
private void CheckUndo()
{
#if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0
Event e = Event.current;
if ( e.type == EventType.MouseDown && e.button == 0 || e.type == EventType.KeyUp && ( e.keyCode == KeyCode.Tab ) ) {
//Debug.Log("record1");
Undo.RecordObject(_ProFlareAtlas,"ProFlareAtlas Undo");
listeningForGuiChanges = true;
guiChanged = false;
}
if ( listeningForGuiChanges && guiChanged ) {
//Debug.Log("record2");
Undo.RecordObject(_ProFlareAtlas,"ProFlareAtlas Undo");
listeningForGuiChanges = false;
}
#else
Event e = Event.current;
if ( e.type == EventType.MouseDown && e.button == 0 || e.type == EventType.KeyUp && ( e.keyCode == KeyCode.Tab ) ) {
Undo.SetSnapshotTarget( _ProFlareAtlas, "ProFlareAtlas Undo" );
Undo.CreateSnapshot();
Undo.ClearSnapshotTarget();
listeningForGuiChanges = true;
guiChanged = false;
}
if ( listeningForGuiChanges && guiChanged ) {
Undo.SetSnapshotTarget( _ProFlareAtlas, "ProFlareAtlas Undo" );
Undo.RegisterSnapshot();
Undo.ClearSnapshotTarget();
listeningForGuiChanges = false;
}
#endif
}
public override void OnInspectorGUI () {
_ProFlareAtlas = target as ProFlareAtlas;
CheckUndo();
// base.OnInspectorGUI();
FlareEditorHelper.DrawGuiDivider();
GUIStyle title = FlareEditorHelper.TitleStyle();
GUIStyle thinButton = FlareEditorHelper.ThinButtonStyle();
GUIStyle enumDropDown = FlareEditorHelper.EnumStyleButton();
GUIStyle redButton = FlareEditorHelper.ThinButtonRedStyle();
EditorGUILayout.LabelField("ProFlare Atlas Editor",title);
GUILayout.Space(10f);
_ProFlareAtlas.texture = EditorGUILayout.ObjectField("Flare Atlas Texture", _ProFlareAtlas.texture, typeof(Texture2D), false) as Texture2D;
if(_ProFlareAtlas.texture == null){
EditorGUILayout.HelpBox("Assign a texture to the atlas.", MessageType.Warning,true);
return;
}
TextAsset ta = EditorGUILayout.ObjectField("Atlas JSON Import", null, typeof(TextAsset), false) as TextAsset;
if (ta != null)
{
FlareJson.LoadSpriteData(_ProFlareAtlas, ta);
Updated = true;
}
FlareEditorHelper.DrawGuiDivider();
EditorGUILayout.LabelField("Atlas Elements",title);
GUILayout.Space(6f);
EditorGUILayout.BeginHorizontal();
if(_ProFlareAtlas.elementsList.Count < 1)
EditorGUILayout.HelpBox("No Elements in flare atlas", MessageType.Warning,true);
else{
_ProFlareAtlas.elementNameList = new string[_ProFlareAtlas.elementsList.Count];
for(int i = 0; i < _ProFlareAtlas.elementNameList.Length; i++)
_ProFlareAtlas.elementNameList[i] = _ProFlareAtlas.elementsList[i].name;
int _ProFlareAtlasElementNumber = EditorGUILayout.Popup(_ProFlareAtlas.elementNumber, _ProFlareAtlas.elementNameList,enumDropDown);
if(_ProFlareAtlasElementNumber != _ProFlareAtlas.elementNumber){
_ProFlareAtlas.elementNumber = _ProFlareAtlasElementNumber;
renameString = _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].name;
}
if(GUILayout.Button("EDIT",thinButton)){Updated = true;
if(_ProFlareAtlas.editElements)
_ProFlareAtlas.editElements = false;
else
_ProFlareAtlas.editElements = true;
}
}
if(GUILayout.Button("ADD NEW",thinButton)){
_ProFlareAtlas.editElements = true;
ProFlareAtlas.Element element = new ProFlareAtlas.Element();
element.name = "New Element " + _ProFlareAtlas.elementsList.Count;
renameString = element.name;
element.Imported = false;
_ProFlareAtlas.elementsList.Add(element);
_ProFlareAtlas.elementNumber = _ProFlareAtlas.elementsList.Count-1;
Updated = true;
}
EditorGUILayout.EndHorizontal();
if(_ProFlareAtlas.elementsList.Count < 1)
return;
EditorGUILayout.BeginVertical("box");
GUILayout.Space(20f);
Rect lastRect = GUILayoutUtility.GetLastRect();
Rect outerRect2 = new Rect(lastRect.center.x,0+lastRect.yMin,200,200);
if(_ProFlareAtlas.elementsList.Count > 0){
GUI.DrawTextureWithTexCoords(outerRect2, _ProFlareAtlas.texture, _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].UV, false);
GUILayout.Space(200f);
}
GUI.enabled = _ProFlareAtlas.editElements;
if(_ProFlareAtlas.editElements){
int extra = 0;
#if UNITY_4_3
extra = 10;
#endif
Rect outerRect3 = new Rect(107+extra,lastRect.yMin,0.5f,200);
Rect rect = new Rect(0,0,1,1);
GUI.DrawTextureWithTexCoords(outerRect3, EditorGUIUtility.whiteTexture, rect, false);
Rect outerRect4 = new Rect(7+extra,100+lastRect.yMin,200,0.5f);
GUI.DrawTextureWithTexCoords(outerRect4, EditorGUIUtility.whiteTexture, rect, true);
}
GUILayout.BeginHorizontal();
if(!_ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].Imported){
renameString = EditorGUILayout.TextField("Name",renameString);
if(GUILayout.Button("RENAME")){
Updated = true;
_ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].name = renameString;
}
}else
EditorGUILayout.LabelField("Name - "+renameString);
GUILayout.EndHorizontal();
EditorGUILayout.Toggle("Imported :", _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].Imported);
float width = EditorGUILayout.Slider("Width", _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].UV.width,0f,1f);
float height = EditorGUILayout.Slider("Height", _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].UV.height,0f,1f);
float CenterX = EditorGUILayout.Slider("Center X", _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].UV.center.x,0f,1f);
float CenterY = EditorGUILayout.Slider("Center Y", _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].UV.center.y,0f,1f);
float xMin = _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].UV.xMin;
float yMin = _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].UV.yMin;
Rect newRect = new Rect(xMin,yMin,width,height);
newRect.center = new Vector2(CenterX,CenterY);
GUILayout.Space(40f);
_ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].UV = newRect;
if(GUILayout.Button("DELETE ELEMENT",redButton)){
Updated = true;
_ProFlareAtlas.elementsList.Remove(_ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber]);
_ProFlareAtlas.elementNumber = 0;
}
EditorGUILayout.EndVertical();
GUI.enabled = true;
if (GUI.changed || Updated)
{
Updated = false;
guiChanged = true;
EditorUtility.SetDirty (target);
}
FlareEditorHelper.DrawGuiDivider();
}
bool Updated = false;
}
|