From b13f7eaa4c61e8ffdb1015e6e200dd50c545ffa3 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Tue, 5 Mar 2024 03:35:38 +0800 Subject: [PATCH] update --- src/Connectors/EcsEntityConnect.cs | 64 +++++++++++-------- src/Editor/EditorUtility.cs | 41 ++++++++---- src/Editor/RectUtility.cs | 15 +++-- .../Editor/EntityTemplateEditor.cs | 10 ++- 4 files changed, 81 insertions(+), 49 deletions(-) diff --git a/src/Connectors/EcsEntityConnect.cs b/src/Connectors/EcsEntityConnect.cs index 1e66505..7b610fc 100644 --- a/src/Connectors/EcsEntityConnect.cs +++ b/src/Connectors/EcsEntityConnect.cs @@ -120,8 +120,6 @@ namespace DCFApixels.DragonECS.Unity.Editors { targets[i] = (EcsEntityConnect)this.targets[i]; } - DrawTop(); - DrawEntityInfo(targets); DrawTemplates(); @@ -129,52 +127,64 @@ namespace DCFApixels.DragonECS.Unity.Editors DrawButtons(); DrawComponents(targets); } - private void DrawTop() - { - var iterator = serializedObject.GetIterator(); - iterator.NextVisible(true); - using (new EditorGUI.DisabledScope(true)) - { - EditorGUILayout.PropertyField(iterator, true); - } - } + private const float line1 = 1f; + private const float line2 = 2f; private void DrawEntityInfo(EcsEntityConnect[] targets) { float width = EditorGUIUtility.currentViewWidth; float height = EditorGUIUtility.singleLineHeight; - Rect entityRect = GUILayoutUtility.GetRect(width, height + 3f); + Rect entityRect = GUILayoutUtility.GetRect(width, height + line2 * 2f); - var (entityInfoRect, statusRect) = RectUtility.VerticalSliceBottom(entityRect, 3f); + Color w = Color.gray; + w.a = 0.6f; + Color b = Color.black; + b.a = 0.55f; + EditorGUI.DrawRect(entityRect, w); + + entityRect = RectUtility.AddPadding(entityRect, line1, line1, line2, 0); + var (entityInfoRect, statusRect) = RectUtility.VerticalSliceBottom(entityRect, line2); var (idRect, genWorldRect) = RectUtility.HorizontalSliceLerp(entityInfoRect, 0.5f); var (genRect, worldRect) = RectUtility.HorizontalSliceLerp(genWorldRect, 0.5f); + idRect = RectUtility.AddPadding(idRect, line1, 0); + genRect = RectUtility.AddPadding(genRect, line1, 0); + worldRect = RectUtility.AddPadding(worldRect, line1, 0); + + EditorGUI.DrawRect(idRect, b); + EditorGUI.DrawRect(genRect, b); + EditorGUI.DrawRect(worldRect, b); bool isConnected = Target.Entity.TryUnpack(out int id, out short gen, out short world); - + GUIStyle style = new GUIStyle(EditorStyles.boldLabel); + style.alignment = TextAnchor.MiddleCenter; if (IsMultipleTargets == false && isConnected) { Color statusColor = EcsGUI.GreenColor; - statusColor.a = 0.32f; + statusColor.a = 0.4f; EditorGUI.DrawRect(statusRect, statusColor); - EditorGUI.IntField(idRect, id); - EditorGUI.IntField(genRect, gen); - EditorGUI.IntField(worldRect, world); + + EditorGUI.IntField(idRect, id, style); + EditorGUI.IntField(genRect, gen, style); + EditorGUI.IntField(worldRect, world, style); } else { - using (new EditorGUI.DisabledScope(true)) - { - Color statusColor = IsMultipleTargets ? EcsGUI.GrayColor : EcsGUI.RedColor; - statusColor.a = 0.32f; - EditorGUI.DrawRect(statusRect, statusColor); - EditorGUI.TextField(idRect, "Entity ID"); - EditorGUI.TextField(genRect, "Gen"); - EditorGUI.TextField(worldRect, "World ID"); - } + Color statusColor = IsMultipleTargets ? new Color32(200, 200, 200, 255) : EcsGUI.RedColor; + statusColor.a = 0.4f; + EditorGUI.DrawRect(statusRect, statusColor); + + Color dc = GUI.color; + Color ndc = Color.white; + ndc.a = 0.4f; + GUI.color = ndc; + GUI.Label(idRect, "Entity ID", EditorStyles.boldLabel); + GUI.Label(genRect, "Generation", EditorStyles.boldLabel); + GUI.Label(worldRect, "World ID", EditorStyles.boldLabel); + GUI.color = dc; } } diff --git a/src/Editor/EditorUtility.cs b/src/Editor/EditorUtility.cs index 36c126b..c0bc07c 100644 --- a/src/Editor/EditorUtility.cs +++ b/src/Editor/EditorUtility.cs @@ -138,19 +138,18 @@ namespace DCFApixels.DragonECS.Unity.Editors } GUILayout.EndVertical(); - GUILayout.Space(2f); } } private static bool DrawRuntimeData(Type fieldType, GUIContent label, ExpandMatrix expandMatrix, object data, out object outData) { Type type = data.GetType(); - UnityEngine.Object uobj = data as UnityEngine.Object; + bool isUnityObject = typeof(UnityEngine.Object).IsAssignableFrom(fieldType); ref bool isExpanded = ref expandMatrix.Down(); bool changed = false; outData = data; - if (uobj == null && (type.IsGenericType || !type.IsSerializable)) + if (isUnityObject == false && (type.IsGenericType || !type.IsSerializable)) { isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(isExpanded, label, EditorStyles.foldout); EditorGUILayout.EndFoldoutHeaderGroup(); @@ -174,18 +173,32 @@ namespace DCFApixels.DragonECS.Unity.Editors } else { - EditorGUI.BeginChangeCheck(); - WrapperBase w = uobj == null ? RefEditorWrapper.Take(data) : UnityObjEditorWrapper.Take(uobj); - - w.IsExpanded = isExpanded; - EditorGUILayout.PropertyField(w.Property, label, true); - isExpanded = w.IsExpanded; - - if (EditorGUI.EndChangeCheck()) + if (isUnityObject) { - w.SO.ApplyModifiedProperties(); - outData = w.Data; - changed = true; + EditorGUI.BeginChangeCheck(); + UnityEngine.Object uobj = (UnityEngine.Object)data; + uobj = EditorGUILayout.ObjectField(label, uobj, fieldType, true); + if (EditorGUI.EndChangeCheck()) + { + outData = uobj; + changed = true; + } + } + else + { + EditorGUI.BeginChangeCheck(); + WrapperBase w = RefEditorWrapper.Take(data); + + w.IsExpanded = isExpanded; + EditorGUILayout.PropertyField(w.Property, label, true); + isExpanded = w.IsExpanded; + + if (EditorGUI.EndChangeCheck()) + { + w.SO.ApplyModifiedProperties(); + outData = w.Data; + changed = true; + } } } diff --git a/src/Editor/RectUtility.cs b/src/Editor/RectUtility.cs index 76d7825..53fe4dd 100644 --- a/src/Editor/RectUtility.cs +++ b/src/Editor/RectUtility.cs @@ -48,15 +48,18 @@ namespace DCFApixels.DragonECS.Unity.Internal public static Rect AddPadding(Rect rect, float verticalHorizontal) { - return AddPadding(rect, verticalHorizontal, verticalHorizontal); + return AddPadding(rect, verticalHorizontal, verticalHorizontal, verticalHorizontal, verticalHorizontal); } - public static Rect AddPadding(Rect rect, float vertical, float horizontal) { - rect.xMax -= horizontal; - rect.xMin += horizontal; - rect.yMax -= vertical; - rect.yMin += vertical; + return AddPadding(rect, vertical, vertical, horizontal, horizontal); + } + public static Rect AddPadding(Rect rect, float left, float right, float top, float bottom) + { + rect.xMin += left; + rect.xMax -= right; + rect.yMin += top; + rect.yMax -= bottom; return rect; } } diff --git a/src/EntityTemplate/Editor/EntityTemplateEditor.cs b/src/EntityTemplate/Editor/EntityTemplateEditor.cs index 1eda107..ec40dd5 100644 --- a/src/EntityTemplate/Editor/EntityTemplateEditor.cs +++ b/src/EntityTemplate/Editor/EntityTemplateEditor.cs @@ -178,15 +178,21 @@ namespace DCFApixels.DragonECS.Unity.Editors #region Draw Component Block EditorGUI.DrawRect(propertyFullRect, alphaPanelColor); propertyRect = RectUtility.AddPadding(propertyRect, padding); + bool isRemoveComponent = false; + if (GUI.Button(removeButtonRect, "x")) + { + isRemoveComponent = true; + } + if (isEmpty) { GUI.Label(propertyRect, label); } else { - EditorGUI.PropertyField(propertyRect, componentProperty, label, true); + EditorGUI.PropertyField(propertyFullRect, componentProperty, label, true); } - if (GUI.Button(removeButtonRect, "x")) + if (isRemoveComponent) { OnRemoveComponentAt(index); }