summaryrefslogtreecommitdiff
path: root/Assets/ActionTool/Editor/ActionColliderEditor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/ActionTool/Editor/ActionColliderEditor.cs')
-rw-r--r--Assets/ActionTool/Editor/ActionColliderEditor.cs169
1 files changed, 118 insertions, 51 deletions
diff --git a/Assets/ActionTool/Editor/ActionColliderEditor.cs b/Assets/ActionTool/Editor/ActionColliderEditor.cs
index d75fd8fc..346cadbc 100644
--- a/Assets/ActionTool/Editor/ActionColliderEditor.cs
+++ b/Assets/ActionTool/Editor/ActionColliderEditor.cs
@@ -1,82 +1,149 @@
-using System.Collections;
+using System;
+using System.Collections;
using System.Collections.Generic;
+using System.Reflection;
using UnityEngine;
using UnityEditor;
namespace ActionTool
{
- // 编辑collider帧
+ // 编辑事件
public class ActionColliderEditor : EditorWindow
{
- EditorWindow sceneView;
+ EditorWindow sceneView;
+ ActionEditorStyles styles;
+
+ ColliderBox collider;
private void OnEnable()
{
- titleContent = new GUIContent("Collider Editor");
- maxSize = new Vector2(300, 150);
- minSize = maxSize;
-
- if(!sceneView)
- sceneView = EditorWindow.GetWindow<SceneView>();
- }
-
- private void OnDisable()
+ titleContent = new GUIContent("Collider Editor");
+ }
+
+ private void OnDisable()
{
- // sceneView = null;
- ActionManager.OnSelectColliderFrame(null);
}
- private void Update()
- {
- }
+ private void Update()
+ {
+ }
- private void OnGUI()
+ Vector2 scroll;
+ private void OnGUI()
{
- var frame = ActionManager.editColliderFrame;
- if (frame == null)
+ if (ActionManager.colliderData == null)
{
this.Close();
return;
}
- GUI.changed = false;
+ collider = ActionManager.colliderData.collider;
+ if (collider == null)
+ return;
- GUILayout.Space(5);
+ if (styles == null) styles = ActionEditorStyles.Get();
- EditorGUILayout.BeginHorizontal();
- EditorGUILayout.LabelField("frame: ");
- EditorGUILayout.LabelField(frame.frame.ToString());
- EditorGUILayout.EndHorizontal();
+ GUILayout.Space(2);
- EditorGUILayout.BeginHorizontal();
- EditorGUILayout.LabelField("active: ");
- frame.active = EditorGUILayout.Toggle(frame.active);
- EditorGUILayout.EndHorizontal();
+ scroll = EditorGUILayout.BeginScrollView(scroll);
- EditorGUILayout.LabelField("position: ");
- frame.position = EditorGUILayout.Vector3Field("", frame.position);
+ Type type = collider.GetType();
+ 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;
+ 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(ColliderTypeAttribute))
+ {
+ ColliderTypeAttribute t = attr as ColliderTypeAttribute;
+ if (t.type != collider.type)
+ {
+ skip = true;
+ break;
+ }
+ }
+ }
+ if(skip)
+ {
+ GUI.enabled = true;
+ continue;
+ }
+ EditorGUILayout.LabelField(new GUIContent(name, tooltip), styles.textBold);
+ if (field.FieldType == typeof(Vector3))
+ {
+ field.SetValue(collider, GUI_Vector3((Vector3)field.GetValue(collider)));
+ }
+ else if (field.FieldType == typeof(Vector2))
+ {
+ field.SetValue(collider, GUI_Vector2((Vector2)field.GetValue(collider)));
+ }
+ else if (field.FieldType == typeof(string))
+ {
+ field.SetValue(collider, GUI_String((string)field.GetValue(collider)));
+ }
+ else if (field.FieldType == typeof(bool))
+ {
+ field.SetValue(collider, GUI_Bool((bool)field.GetValue(collider)));
+ }
+ else
+ {
+ GUI_Enum(field.GetValue(collider).ToString());
+ }
+ GUI.enabled = true;
+ GUILayout.Space(5);
+ }
+ }
+ EditorGUILayout.EndScrollView();
+ }
- EditorGUILayout.LabelField("size: ");
- frame.size = EditorGUILayout.Vector3Field("", frame.size);
+ Vector3 GUI_Vector3(Vector3 value)
+ {
+ Rect rect = EditorGUILayout.GetControlRect();
+ return EditorGUI.Vector3Field(rect, "", value);
+ }
- GUILayout.Space(10);
+ Vector2 GUI_Vector2(Vector2 value)
+ {
+ Rect rect = EditorGUILayout.GetControlRect();
+ return EditorGUI.Vector2Field(rect, "", value);
+ }
- Color prevColor = GUI.backgroundColor;
- GUI.backgroundColor = Color.red;
- if (GUILayout.Button("Delete"))
- {
- ActionManager.DeleteCurFrame();
- }
- GUI.backgroundColor = prevColor;
-
- if (GUI.changed)
- {
- if (sceneView != null)
- sceneView.Repaint();
- if (ActionManager.PreviewWindow != null)
- ActionManager.PreviewWindow.Repaint();
- }
+ 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");
+ }
+
+ void GUI_Enum(string value)
+ {
+ Rect rect = EditorGUILayout.GetControlRect();
+ GUI.Label(rect, value);
+ }
+
}
-} \ No newline at end of file
+} \ No newline at end of file