summaryrefslogtreecommitdiff
path: root/Assets/Tools/ActionTool/Editor/ActionEventEditor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Tools/ActionTool/Editor/ActionEventEditor.cs')
-rw-r--r--Assets/Tools/ActionTool/Editor/ActionEventEditor.cs368
1 files changed, 368 insertions, 0 deletions
diff --git a/Assets/Tools/ActionTool/Editor/ActionEventEditor.cs b/Assets/Tools/ActionTool/Editor/ActionEventEditor.cs
new file mode 100644
index 00000000..b0eb86cf
--- /dev/null
+++ b/Assets/Tools/ActionTool/Editor/ActionEventEditor.cs
@@ -0,0 +1,368 @@
+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.BeginHorizontal();
+ if (GUILayout.Button("Copy"))
+ {
+ ActionManager.CopyAnimationEvent(animEvent);
+ }
+ 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)));
+ }
+ }
+ else
+ {
+ Color c = GUI.color;
+ GUI.color = Color.red;
+ GUI_Label(new GUIContent("Unknown Type " + field.FieldType), GUI.skin.GetStyle("Label"));
+ GUI.color = c;
+ }
+ 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);
+ }
+
+ }
+} \ No newline at end of file