summaryrefslogtreecommitdiff
path: root/Assets/ActionTool/Editor/ActionEventEditor.cs
blob: 0fd9ea22288a5fedc876effe568d9729a29ffb0e (plain)
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEditor;

namespace ActionTool
{

    // 编辑事件
    public class ActionEventEditor : EditorWindow
    {
        EditorWindow sceneView;
        ActionEditorStyles styles;
        AnimationEventBase animEvent;

        private void OnEnable()
        {
            titleContent = new GUIContent("Event Editor");
        }

        private void OnDisable()
        {
            ActionManager.OnSelectAnimationEvent(null);
        }

        private void Update()
        {
        }

        Vector2 scroll;
        private void OnGUI()
        {
            animEvent = ActionManager.animationEvent;
            if (animEvent == null)
            {
                this.Close();
                return;
            }

            if (styles == null) styles = ActionEditorStyles.Get();

            string eventName = animEvent.name;
            int frame = animEvent.startFrame;

            Type type = animEvent.GetType();

            GUILayout.Space(2);

            EditorGUILayout.LabelField(eventName, styles.textBoldBig, GUILayout.Height(25));

            GUILayout.Space(2);

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Save"))
            {

            }
            if (GUILayout.Button("Revert"))
            {

            }
            Color prevColor = GUI.backgroundColor;
            GUI.backgroundColor = Color.red;
            if (GUILayout.Button("Delete"))
            {
                ActionManager.DeleteEvent(animEvent);
                ActionManager.OnSelectAnimationEvent(null);
            }
            GUI.backgroundColor = prevColor;
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(5);

            EditorGUILayout.LabelField("startFrame (int)", styles.textBold);
            GUI.enabled = false;
            EditorGUILayout.TextField(frame.ToString());
            GUI.enabled = true;

            GUILayout.Space(5);

            scroll = EditorGUILayout.BeginScrollView(scroll);

            GUILayout.Space(5);

            FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            if(fields != null && fields.Length > 0)
            {
                for(int i = 0; i < fields.Length; ++i)
                {
                    FieldInfo field = fields[i];
                    string name = field.Name + " (" + field.FieldType.Name + ")";
                    string tooltip = "";
					bool skip = false;
					bool isHDR = false;
					foreach (var attr in field.GetCustomAttributes())
                    {
                        if(attr.GetType() == typeof(TooltipAttribute))
                        {
                            TooltipAttribute tooltipattr = attr as TooltipAttribute;
                            if(tooltip != null)
                            {
                                tooltip = tooltipattr.tooltip;
							}
                        }
                        else if (attr.GetType() == typeof(DisallowModifiyInGUI))
                        {
                            GUI.enabled = false;
                        }
                        else if (attr.GetType() == typeof(WhenAttribute))
                        {
							WhenAttribute when = attr as WhenAttribute;
							string conditionName = when.conditionName;
							FieldInfo condition = type.GetField(conditionName);
							if (!when.IsSatisfied((int)condition.GetValue(animEvent)))
							{
								skip = true;
								break;
							}
						}
						else if (attr.GetType() == typeof(AndWhenAttribute))
						{
							AndWhenAttribute when = attr as AndWhenAttribute;
							string conditionName = when.conditionName;
							FieldInfo condition = type.GetField(conditionName);
							if (!when.IsSatisfied((int)condition.GetValue(animEvent)))
							{
								skip = true;
								break;
							}
						}
						else if (attr.GetType() == typeof(WhenNotAttribute))
                        {
                            WhenNotAttribute when = attr as WhenNotAttribute;
                            string conditionName = when.conditionName;
                            FieldInfo condition = type.GetField(conditionName);
                            if ((int)condition.GetValue(animEvent) == when.value)
                            {
                                skip = true;
                                break;
                            }
                        }
                        else if (attr.GetType() == typeof(IfAttribute))
                        {
                            IfAttribute when = attr as IfAttribute;
                            string conditionName = when.conditionName;
                            FieldInfo condition = type.GetField(conditionName);
                            if (!(bool)condition.GetValue(animEvent))
                            {
                                skip = true;
                                break;
                            }
                        }
                        else if (attr.GetType() == typeof(IfNotAttribute))
                        {
                            IfNotAttribute when = attr as IfNotAttribute;
                            string conditionName = when.conditionName;
                            FieldInfo condition = type.GetField(conditionName);
                            if ((bool)condition.GetValue(animEvent))
                            {
                                skip = true;
                                break;
                            }
                        }
                        else if (attr.GetType() == typeof(SpaceAttribute))
                        {
                            SpaceAttribute space = attr as SpaceAttribute;
                            GUILayout.Space(space.height);
                        }
						else if (attr.GetType() == typeof(CommentAttribute))
						{
							CommentAttribute comment = attr as CommentAttribute;
							GUIStyle style = GUI.skin.GetStyle("Label");
							TextAnchor preanchor = style.alignment;
							style.alignment = comment.alignment;
							GUI_Label(new GUIContent(comment.comment), style);
							style.alignment = preanchor;
						}
						else if (attr.GetType() == typeof(WhenAttribute))
                        {
                            WhenAttribute when = attr as WhenAttribute;
                            string conditionName = when.conditionName;
                            FieldInfo condition = type.GetField(conditionName);
                            if ((float)condition.GetValue(animEvent) != when.value)
                            {
                                skip = true;
                                break;
                            }
                        }
                        else if (attr.GetType() == typeof(WhenNotAttribute))
                        {
                            WhenNotAttribute when = attr as WhenNotAttribute;
                            string conditionName = when.conditionName;
                            FieldInfo condition = type.GetField(conditionName);
                            if ((float)condition.GetValue(animEvent) == when.value)
                            {
                                skip = true;
                                break;
                            }
                        }
                        else if (attr.GetType() == typeof(IfAttribute))
                        {
                            IfAttribute when = attr as IfAttribute;
                            string conditionName = when.conditionName;
                            FieldInfo condition = type.GetField(conditionName);
                            if (!(bool)condition.GetValue(animEvent))
                            {
                                skip = true;
                                break;
                            }
                        }
                        else if (attr.GetType() == typeof(IfNotAttribute))
                        {
                            IfNotAttribute when = attr as IfNotAttribute;
                            string conditionName = when.conditionName;
                            FieldInfo condition = type.GetField(conditionName);
                            if ((bool)condition.GetValue(animEvent))
                            {
                                skip = true;
                                break;
                            }
                        }
						else if(attr.GetType() == typeof(HDRAttribute))
						{
							isHDR = true;
						}
                    }
					if (skip)
					{
						GUI.enabled = true;
						continue;
					}
					EditorGUILayout.LabelField(new GUIContent(name, tooltip), styles.textBold);
                    if (field.FieldType == typeof(Vector3))
                    {
                        field.SetValue(animEvent, GUI_Vector3((Vector3)field.GetValue(animEvent)));
                    }
                    else if (field.FieldType == typeof(Vector2))
                    {
                        field.SetValue(animEvent, GUI_Vector2((Vector2)field.GetValue(animEvent)));
                    }
                    else if (field.FieldType == typeof(string))
                    {
                        field.SetValue(animEvent, GUI_String((string)field.GetValue(animEvent)));
                    }
                    else if (field.FieldType == typeof(bool))
                    {
                        field.SetValue(animEvent, GUI_Bool((bool)field.GetValue(animEvent)));
                    }
                    else if(field.FieldType == typeof(AnimationCurve))
                    {
                        field.SetValue(animEvent, GUI_Curve(field.GetValue(animEvent) as AnimationCurve));
                    }
                    else if(field.FieldType.IsEnum)
                    {
                        field.SetValue(animEvent, GUI_Enum((Enum)field.GetValue(animEvent)));
                    }
                    else if(field.FieldType == typeof(float))
                    {
                        field.SetValue(animEvent, GUI_Float((float)field.GetValue(animEvent)));
                    }
                    else if (field.FieldType == typeof(int))
                    {
                        field.SetValue(animEvent, GUI_Int((int)field.GetValue(animEvent)));
                    }
					else if(field.FieldType == typeof(Color))
					{
						if(isHDR)
						{
							field.SetValue(animEvent, GUI_ColorHDR((Color)field.GetValue(animEvent)));
						}
						else
						{
							field.SetValue(animEvent, GUI_Color((Color)field.GetValue(animEvent)));
						}
					}
					GUILayout.Space(5);
                }
            }

            EditorGUILayout.EndScrollView();
        }

		void GUI_Label(GUIContent label, GUIStyle style)
		{
			Rect rect = EditorGUILayout.GetControlRect();
			EditorGUI.LabelField(rect, label, style);
		}

		float GUI_Float(float value)
        {
            Rect rect = EditorGUILayout.GetControlRect();
            return EditorGUI.FloatField(rect, "", value);
        }

        int GUI_Int(int value)
        {
            Rect rect = EditorGUILayout.GetControlRect();
            return EditorGUI.IntField(rect, "", value);
        }

        AnimationCurve GUI_Curve(AnimationCurve curve)
        {
            Rect rect = EditorGUILayout.GetControlRect();
            return EditorGUI.CurveField(rect, "", curve);
        }

        Enum GUI_Enum(Enum enumValue)
        {
            Rect rect = EditorGUILayout.GetControlRect();
            return EditorGUI.EnumPopup(rect, "", enumValue);
        }

        Vector3 GUI_Vector3(Vector3 value)
        {
            Rect rect = EditorGUILayout.GetControlRect();
            return EditorGUI.Vector3Field(rect, "", value);
        }

        Vector2 GUI_Vector2(Vector2 value)
        {
            Rect rect = EditorGUILayout.GetControlRect();
            return EditorGUI.Vector2Field(rect, "", value);
        }

        string GUI_String(string value)
        {
            Rect rect = EditorGUILayout.GetControlRect();
            return EditorGUI.TextField(rect, "", value);
        }

        bool GUI_Bool(bool value)
        {
            Rect rect = EditorGUILayout.GetControlRect();
            return GUI.Toggle(rect, value, "Check");
        }

		Color GUI_Color(Color col)
		{
			Rect rect = EditorGUILayout.GetControlRect();
			return EditorGUI.ColorField(rect, col);
		}

		Color GUI_ColorHDR(Color col)
		{
			Rect rect = EditorGUILayout.GetControlRect();
			return EditorGUI.ColorField(rect, new GUIContent(""), col, true, true, true);
		}

	}
}