Update style

This commit is contained in:
Mikhail 2023-03-27 20:31:58 +08:00
parent 0ccedb80a1
commit 51df885c61
5 changed files with 67 additions and 9 deletions

8
src/Debug/Editor.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ac4f146726b3ca444978fd7af0f5f883
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f72bc8ca8108c2b4aac41df126dba1e1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -86,10 +86,10 @@ namespace DCFApixels.DragonECS.Unity
string name = type.Name;
Color color = (GetAttribute<DebugColorAttribute>(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<DebugColorAttribute>(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<object>().Select(o => o.GetType().Name)));
GUILayout.EndVertical();
GUI.backgroundColor = defaultBackgroundColor;
//GUI.backgroundColor = defaultBackgroundColor;
}
private TAttribute GetAttribute<TAttribute>(Type target) where TAttribute : Attribute

View File

@ -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);
}
}
}