From 3a71eb54456519256f573a6542b46f9c29443b22 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 23 Aug 2021 21:48:45 +0800 Subject: *misc --- Assets/ActionTool/Editor/ActionColliderEditor.cs | 77 +++++++++++++++++------- 1 file changed, 56 insertions(+), 21 deletions(-) (limited to 'Assets/ActionTool/Editor/ActionColliderEditor.cs') diff --git a/Assets/ActionTool/Editor/ActionColliderEditor.cs b/Assets/ActionTool/Editor/ActionColliderEditor.cs index 9aa9b788..a883bd46 100644 --- a/Assets/ActionTool/Editor/ActionColliderEditor.cs +++ b/Assets/ActionTool/Editor/ActionColliderEditor.cs @@ -18,6 +18,8 @@ namespace ActionTool Dictionary m_Foldout = new Dictionary (); + int indent = 0; + private void OnEnable() { titleContent = new GUIContent("Collider Editor"); @@ -175,6 +177,7 @@ namespace ActionTool m_Foldout.Add(foldout.title, false); m_Foldout[foldout.title] = EditorGUILayout.Foldout(m_Foldout[foldout.title], foldout.title); foldoutElementCount = 0; + indent = 13; } } } @@ -185,19 +188,21 @@ namespace ActionTool if(foldout != null && (++foldoutElementCount) <= foldout.count) { skip |= !m_Foldout[foldout.title]; - if (foldoutElementCount == foldout.count) - { - foldout = null; - foldoutElementCount = 0; - } - } + } if (skip) { - GUI.enabled = true; + if (foldout != null && foldoutElementCount == foldout.count) + { + foldout = null; + foldoutElementCount = 0; + indent = 0; + } + GUI.enabled = true; continue; } - EditorGUILayout.LabelField(new GUIContent(name, tooltip), styles.textBold); + GUI_Label(new GUIContent(name, tooltip), styles.textBold); + if (field.FieldType == typeof(Vector3)) { field.SetValue(collider, GUI_Vector3((Vector3)field.GetValue(collider))); @@ -206,7 +211,11 @@ namespace ActionTool { field.SetValue(collider, GUI_Vector2((Vector2)field.GetValue(collider))); } - else if (field.FieldType == typeof(string)) + else if(field.FieldType == typeof(Color)) + { + field.SetValue(collider, GUI_Color((Color)field.GetValue(collider))); + } + else if (field.FieldType == typeof(string)) { field.SetValue(collider, GUI_String((string)field.GetValue(collider))); } @@ -232,65 +241,91 @@ namespace ActionTool } GUI.enabled = true; GUILayout.Space(5); - } - } + + if (foldout != null && foldoutElementCount == foldout.count) + { + foldout = null; + foldoutElementCount = 0; + indent = 0; + } + } + } EditorGUILayout.EndScrollView(); } + Rect GetControlRect() + { + Rect rect = EditorGUILayout.GetControlRect(); + rect.x += indent; + rect.width -= indent; + return rect; + } + + void GUI_Label(GUIContent label, GUIStyle style) + { + Rect rect = GetControlRect(); + EditorGUI.LabelField(rect, label, style); + } + Vector3 GUI_Vector3(Vector3 value) { - Rect rect = EditorGUILayout.GetControlRect(); + Rect rect = GetControlRect(); return EditorGUI.Vector3Field(rect, "", value); } Vector2 GUI_Vector2(Vector2 value) { - Rect rect = EditorGUILayout.GetControlRect(); + Rect rect = GetControlRect(); return EditorGUI.Vector2Field(rect, "", value); } string GUI_String(string value) { - Rect rect = EditorGUILayout.GetControlRect(); + Rect rect = GetControlRect(); return EditorGUI.TextField(rect, "", value); } bool GUI_Bool(bool value) { - Rect rect = EditorGUILayout.GetControlRect(); + Rect rect = GetControlRect(); return GUI.Toggle(rect, value, "Check"); } void GUI_Enum(string value) { - Rect rect = EditorGUILayout.GetControlRect(); + Rect rect = GetControlRect(); GUI.Label(rect, value); } float GUI_Float(float value) { - Rect rect = EditorGUILayout.GetControlRect(); + Rect rect = GetControlRect(); return EditorGUI.FloatField(rect, "", value); } int GUI_Int(int value) { - Rect rect = EditorGUILayout.GetControlRect(); + Rect rect = GetControlRect(); return EditorGUI.IntField(rect, "", value); } AnimationCurve GUI_Curve(AnimationCurve curve) { - Rect rect = EditorGUILayout.GetControlRect(); + Rect rect = GetControlRect(); return EditorGUI.CurveField(rect, "", curve); } Enum GUI_Enum(Enum enumValue) { - Rect rect = EditorGUILayout.GetControlRect(); + Rect rect = GetControlRect(); return EditorGUI.EnumPopup(rect, "", enumValue); } + Color GUI_Color(Color col) + { + Rect rect = GetControlRect(); + return EditorGUI.ColorField(rect, col); + } - } + } } \ No newline at end of file -- cgit v1.1-26-g67d0