diff options
author | chai <chaifix@163.com> | 2021-07-22 18:34:47 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-07-22 18:34:47 +0800 |
commit | cb893e1e5e4820cb800836cf6b8a79a1cd986cdc (patch) | |
tree | c96f8020c760d89d418684b71de294556d6961d3 /Assets/ActionTool/Editor/ActionEventEditor.cs | |
parent | f7f2ebc0ce06aaf7d34325258c9bfe689043de94 (diff) |
*misc
Diffstat (limited to 'Assets/ActionTool/Editor/ActionEventEditor.cs')
-rw-r--r-- | Assets/ActionTool/Editor/ActionEventEditor.cs | 144 |
1 files changed, 138 insertions, 6 deletions
diff --git a/Assets/ActionTool/Editor/ActionEventEditor.cs b/Assets/ActionTool/Editor/ActionEventEditor.cs index 70a75011..82580b17 100644 --- a/Assets/ActionTool/Editor/ActionEventEditor.cs +++ b/Assets/ActionTool/Editor/ActionEventEditor.cs @@ -1,23 +1,155 @@ -using System.Collections;
+using System;
+using System.Collections;
using System.Collections.Generic;
+using System.Reflection;
using UnityEngine;
+using UnityEditor;
namespace ActionTool
{
- public class ActionEventEditor : MonoBehaviour
+ // 编辑事件
+ public class ActionEventEditor : EditorWindow
{
+ EditorWindow sceneView;
+ ActionEditorStyles styles;
+ AnimationEventBase animEvent;
- // Start is called before the first frame update
- void Start()
+ private void OnEnable()
{
+ titleContent = new GUIContent("Event Editor");
+ }
+ private void OnDisable()
+ {
+ ActionManager.OnSelectAnimationEvent(null);
+ }
+
+ private void Update()
+ {
}
- // Update is called once per frame
- 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(30));
+
+ GUILayout.Space(5);
+
+ 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 = "";
+ foreach(var attr in field.GetCustomAttributes())
+ {
+ if(attr.GetType() == typeof(TooltipAttribute))
+ {
+ TooltipAttribute tooltipattr = attr as TooltipAttribute;
+ if(tooltip != null)
+ {
+ tooltip = tooltipattr.tooltip;
+ }
+ }
+ }
+ 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)));
+ }
+ GUILayout.Space(5);
+ }
+ }
+
+ EditorGUILayout.EndScrollView();
+ }
+
+ 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, "");
+ }
+
}
}
\ No newline at end of file |