From 24ac089d1ec89bb10f6d622124c4bdbce9173f99 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 16 May 2024 23:27:45 +0800 Subject: [PATCH] update --- .../Editor/ComponentTemplatePropertyDrawer.cs | 13 +--------- .../Editor/EntityTemplateEditor.cs | 14 +--------- src/Internal/Editor/EcsGUI.cs | 26 +++++++++++++++++-- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs b/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs index 2552384..d16f9ab 100644 --- a/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs +++ b/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs @@ -188,18 +188,7 @@ namespace DCFApixels.DragonECS.Unity.Editors if (propCount <= 0) { label.text = $"{label.text} ({name})"; - EditorGUI.LabelField(paddingPosition, label); - Rect emptyPos = paddingPosition; - emptyPos.xMin += EditorGUIUtility.labelWidth; - if (isEmpty) - { - using (new EcsGUI.ContentColorScope(1f, 1f, 1f, 0.4f)) - { - GUI.Label(emptyPos, "empty"); - } - } - EditorGUI.BeginProperty(paddingPosition, label, componentRefProp); - EditorGUI.EndProperty(); + EcsGUI.DrawEmptyComponentProperty(paddingPosition, componentRefProp, label.text, isEmpty); } else { diff --git a/src/EntityTemplate/Editor/EntityTemplateEditor.cs b/src/EntityTemplate/Editor/EntityTemplateEditor.cs index f5654e8..5b5ac16 100644 --- a/src/EntityTemplate/Editor/EntityTemplateEditor.cs +++ b/src/EntityTemplate/Editor/EntityTemplateEditor.cs @@ -194,19 +194,7 @@ namespace DCFApixels.DragonECS.Unity.Editors if (propCount <= 0) { - GUIContent label = UnityEditorUtility.GetLabel(name); - EditorGUILayout.LabelField(name); - Rect emptyPos = GUILayoutUtility.GetLastRect(); - emptyPos.xMin += EditorGUIUtility.labelWidth; - if (isEmpty) - { - using (new EcsGUI.ContentColorScope(1f, 1f, 1f, 0.4f)) - { - GUI.Label(emptyPos, "empty"); - } - } - EditorGUI.BeginProperty(GUILayoutUtility.GetLastRect(), label, componentRefProp); - EditorGUI.EndProperty(); + EcsGUI.Layout.DrawEmptyComponentProperty(componentRefProp, name, isEmpty); } else { diff --git a/src/Internal/Editor/EcsGUI.cs b/src/Internal/Editor/EcsGUI.cs index 0ad07d1..9b900d6 100644 --- a/src/Internal/Editor/EcsGUI.cs +++ b/src/Internal/Editor/EcsGUI.cs @@ -335,11 +335,33 @@ namespace DCFApixels.DragonECS.Unity.Editors return AddClearComponentButton.None; } + public static void DrawEmptyComponentProperty(Rect position, SerializedProperty property, string name, bool isDisplayEmpty) + { + DrawEmptyComponentProperty(position, property, UnityEditorUtility.GetLabel(name), isDisplayEmpty); + } + public static void DrawEmptyComponentProperty(Rect position, SerializedProperty property, GUIContent label, bool isDisplayEmpty) + { + EditorGUI.LabelField(position, label); + if (isDisplayEmpty) + { + using (SetContentColor(1f, 1f, 1f, 0.4f)) + { + GUI.Label(position.AddPadding(EditorGUIUtility.labelWidth, 0, 0, 0), "empty"); + } + } + EditorGUI.BeginProperty(position, label, property); + EditorGUI.EndProperty(); + } + public static class Layout { - public static void DrawEmptyComponentProperty(bool isDisplayEmpty) + public static void DrawEmptyComponentProperty(SerializedProperty property, string name, bool isDisplayEmpty) { - + EcsGUI.DrawEmptyComponentProperty(GUILayoutUtility.GetRect(UnityEditorUtility.GetLabel(name), EditorStyles.label), property, name, isDisplayEmpty); + } + public static void DrawEmptyComponentProperty(SerializedProperty property, GUIContent label, bool isDisplayEmpty) + { + EcsGUI.DrawEmptyComponentProperty(GUILayoutUtility.GetRect(label, EditorStyles.label), property, label, isDisplayEmpty); } public static void DrawWorldBaseInfo(EcsWorld world) {