From 50b817126e135d22ab80a82ec673b783ab7c025d Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sat, 4 May 2024 01:43:39 +0800 Subject: [PATCH] fix name display --- src/EntityTemplate/Editor/EntityTemplateEditor.cs | 5 ++++- src/Internal/Editor/UnityEditorUtility.cs | 13 +++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/EntityTemplate/Editor/EntityTemplateEditor.cs b/src/EntityTemplate/Editor/EntityTemplateEditor.cs index 43ad564..097a5ac 100644 --- a/src/EntityTemplate/Editor/EntityTemplateEditor.cs +++ b/src/EntityTemplate/Editor/EntityTemplateEditor.cs @@ -161,7 +161,6 @@ namespace DCFApixels.DragonECS.Unity.Editors Color panelColor = meta.Color.ToUnityColor().Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE); //GUIContent label = new GUIContent(name); - GUIContent label = UnityEditorUtility.GetLabel(name); bool isEmpty = componentType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length <= 0; float padding = EditorGUIUtility.standardVerticalSpacing; Color alphaPanelColor = panelColor; @@ -172,6 +171,8 @@ namespace DCFApixels.DragonECS.Unity.Editors EditorGUI.BeginChangeCheck(); GUILayout.BeginVertical(UnityEditorUtility.GetStyle(alphaPanelColor)); + + #region Draw Component Block bool isRemoveComponent = false; removeButtonRect.yMin = removeButtonRect.yMax; @@ -186,12 +187,14 @@ namespace DCFApixels.DragonECS.Unity.Editors if (isEmpty) { + GUIContent label = UnityEditorUtility.GetLabel(name); GUILayout.Label(label); EditorGUI.BeginProperty(GUILayoutUtility.GetLastRect(), label, componentRefProp); EditorGUI.EndProperty(); } else { + GUIContent label = UnityEditorUtility.GetLabel(name); EditorGUILayout.PropertyField(componentProperty, label, true); } if (isRemoveComponent) diff --git a/src/Internal/Editor/UnityEditorUtility.cs b/src/Internal/Editor/UnityEditorUtility.cs index 3592a44..da3175a 100644 --- a/src/Internal/Editor/UnityEditorUtility.cs +++ b/src/Internal/Editor/UnityEditorUtility.cs @@ -110,6 +110,7 @@ namespace DCFApixels.DragonECS.Unity.Editors colorBoxeStyles = new SparseArray(); } private static SparseArray colorBoxeStyles = new SparseArray(); + private static GUIContent _singletonIconContent = null; private static GUIContent _singletonContent = null; @@ -135,14 +136,14 @@ namespace DCFApixels.DragonECS.Unity.Editors } public static GUIContent GetLabel(Texture image, string tooltip = null) { - if (_singletonContent == null) + if (_singletonIconContent == null) { - _singletonContent = new GUIContent(); + _singletonIconContent = new GUIContent(); } - _singletonContent.text = string.Empty; - _singletonContent.image = image; - _singletonContent.tooltip = tooltip; - return _singletonContent; + _singletonIconContent.text = string.Empty; + _singletonIconContent.image = image; + _singletonIconContent.tooltip = tooltip; + return _singletonIconContent; } #endregion