From 51df885c617b07432248ec8de450d3d3f4fbbc4f Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Mon, 27 Mar 2023 20:31:58 +0800 Subject: [PATCH] Update style --- src/Debug/Editor.meta | 8 +++++++ src/Debug/Editor/EcsEditor.cs | 34 +++++++++++++++++++++++++++++ src/Debug/Editor/EcsEditor.cs.meta | 11 ++++++++++ src/Debug/SystemsDebugSystem.cs | 17 ++++++++------- src/Utils/DebugColorAttributeExt.cs | 6 ++++- 5 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 src/Debug/Editor.meta create mode 100644 src/Debug/Editor/EcsEditor.cs create mode 100644 src/Debug/Editor/EcsEditor.cs.meta diff --git a/src/Debug/Editor.meta b/src/Debug/Editor.meta new file mode 100644 index 0000000..39af79b --- /dev/null +++ b/src/Debug/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ac4f146726b3ca444978fd7af0f5f883 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Debug/Editor/EcsEditor.cs b/src/Debug/Editor/EcsEditor.cs new file mode 100644 index 0000000..5dbc09d --- /dev/null +++ b/src/Debug/Editor/EcsEditor.cs @@ -0,0 +1,34 @@ +#if UNITY_EDITOR +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEditor; + +namespace DCFApixels.DragonECS.Unity.Editors +{ + public static class EcsEditor + { + public static GUIStyle GetStyle(Color color) + { + GUIStyle style = new GUIStyle(GUI.skin.box); + Color componentColor = color; + componentColor.a = 0.15f; + style.normal.background = CreateTexture(2, 2, componentColor); + + return style; + } + + private static Texture2D CreateTexture(int width, int height, Color color) + { + var pixels = new Color[width * height]; + for (var i = 0; i < pixels.Length; ++i) + pixels[i] = color; + + var result = new Texture2D(width, height); + result.SetPixels(pixels); + result.Apply(); + return result; + } + } +} +#endif diff --git a/src/Debug/Editor/EcsEditor.cs.meta b/src/Debug/Editor/EcsEditor.cs.meta new file mode 100644 index 0000000..1ab7889 --- /dev/null +++ b/src/Debug/Editor/EcsEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f72bc8ca8108c2b4aac41df126dba1e1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Debug/SystemsDebugSystem.cs b/src/Debug/SystemsDebugSystem.cs index b1ce958..9a4b30c 100644 --- a/src/Debug/SystemsDebugSystem.cs +++ b/src/Debug/SystemsDebugSystem.cs @@ -86,10 +86,10 @@ namespace DCFApixels.DragonECS.Unity string name = type.Name; Color color = (GetAttribute(type) ?? _fakeDebugColorAttribute).GetUnityColor(); - Color defaultBackgroundColor = GUI.backgroundColor; + //Color defaultBackgroundColor = GUI.backgroundColor; - GUI.backgroundColor = color; - GUILayout.BeginVertical(EditorStyles.helpBox); + //GUI.backgroundColor = color; + GUILayout.BeginVertical(EcsEditor.GetStyle(color)); if (Target.showInterfaces) { GUILayout.Label(string.Join(", ", type.GetInterfaces().Select(o => o.Name)), _interfacesStyle); @@ -97,20 +97,21 @@ namespace DCFApixels.DragonECS.Unity GUILayout.Label(name, EditorStyles.boldLabel); GUILayout.EndVertical(); - GUI.backgroundColor = defaultBackgroundColor; + //GUI.backgroundColor = defaultBackgroundColor; } private void DrawRunner(IEcsRunner runner) { Type type = runner.GetType(); Color color = (GetAttribute(type) ?? _fakeDebugColorAttribute).GetUnityColor(); - Color defaultBackgroundColor = GUI.backgroundColor; - GUI.backgroundColor = color; - GUILayout.BeginVertical(EditorStyles.helpBox); + //Color defaultBackgroundColor = GUI.backgroundColor; + //GUI.backgroundColor = color; + GUILayout.BeginVertical(EcsEditor.GetStyle(color)); + //GUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Label(type.Name, EditorStyles.boldLabel); GUILayout.Label(string.Join(", ", runner.Targets.Cast().Select(o => o.GetType().Name))); GUILayout.EndVertical(); - GUI.backgroundColor = defaultBackgroundColor; + //GUI.backgroundColor = defaultBackgroundColor; } private TAttribute GetAttribute(Type target) where TAttribute : Attribute diff --git a/src/Utils/DebugColorAttributeExt.cs b/src/Utils/DebugColorAttributeExt.cs index a9aed87..21f8526 100644 --- a/src/Utils/DebugColorAttributeExt.cs +++ b/src/Utils/DebugColorAttributeExt.cs @@ -6,7 +6,11 @@ namespace DCFApixels.DragonECS.Unity { public static Color GetUnityColor(this DebugColorAttribute self) { - return new Color(self.r / 255f, self.g / 255f, self.b / 255f); + return new Color(self.rn, self.gn, self.bn); + } + public static Color32 GetUnityColor32(this DebugColorAttribute self) + { + return new Color32(self.r, self.g, self.b, 255); } } }