mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 01:54:35 +08:00
update entity bar display
This commit is contained in:
parent
5dfe28e87d
commit
6ad3668114
@ -42,7 +42,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
{
|
{
|
||||||
bool isConnected = Target.Entity.TryUnpackForUnityEditor(out int id, out short gen, out short worldID, out EcsWorld world);
|
bool isConnected = Target.Entity.TryUnpackForUnityEditor(out int id, out short gen, out short worldID, out EcsWorld world);
|
||||||
EcsGUI.EntityStatus status = IsMultipleTargets ? EcsGUI.EntityStatus.Undefined : isConnected ? EcsGUI.EntityStatus.Alive : EcsGUI.EntityStatus.NotAlive;
|
EcsGUI.EntityStatus status = IsMultipleTargets ? EcsGUI.EntityStatus.Undefined : isConnected ? EcsGUI.EntityStatus.Alive : EcsGUI.EntityStatus.NotAlive;
|
||||||
EcsGUI.Layout.EntityBar(status, id, gen, worldID);
|
EcsGUI.Layout.EntityBarForAlive(status, id, gen, worldID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawTemplates()
|
private void DrawTemplates()
|
||||||
|
@ -18,7 +18,8 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
var (labelRect, barRect) = RectUtility.HorizontalSliceLeft(position, EditorGUIUtility.labelWidth * 0.65f);
|
var (labelRect, barRect) = RectUtility.HorizontalSliceLeft(position, EditorGUIUtility.labelWidth * 0.65f);
|
||||||
|
|
||||||
EditorGUI.LabelField(labelRect, label);
|
EditorGUI.LabelField(labelRect, label);
|
||||||
EcsGUI.EntityBar(barRect, EcsGUI.EntityStatus.Alive, slotInfo.id, slotInfo.gen, slotInfo.world);
|
bool isAlive = EcsWorld.GetWorld(slotInfo.world).IsAlive(slotInfo.id, slotInfo.gen);
|
||||||
|
EcsGUI.EntityBar(barRect, false, isAlive ? EcsGUI.EntityStatus.Alive : EcsGUI.EntityStatus.NotAlive, slotInfo.id, slotInfo.gen, slotInfo.world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
public override void OnInspectorGUI()
|
public override void OnInspectorGUI()
|
||||||
{
|
{
|
||||||
bool isAlive = Target.Entity.TryUnpackForUnityEditor(out int id, out short gen, out short worldID, out EcsWorld world);
|
bool isAlive = Target.Entity.TryUnpackForUnityEditor(out int id, out short gen, out short worldID, out EcsWorld world);
|
||||||
EcsGUI.Layout.EntityBar(isAlive ? EcsGUI.EntityStatus.Alive : EcsGUI.EntityStatus.NotAlive, id, gen, worldID);
|
EcsGUI.Layout.EntityBarForAlive(isAlive ? EcsGUI.EntityStatus.Alive : EcsGUI.EntityStatus.NotAlive, id, gen, worldID);
|
||||||
EcsGUI.Layout.DrawRuntimeComponents(Target.Entity, false);
|
EcsGUI.Layout.DrawRuntimeComponents(Target.Entity, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,33 +9,47 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
{
|
{
|
||||||
internal static class EcsGUI
|
internal static class EcsGUI
|
||||||
{
|
{
|
||||||
|
#region Scores
|
||||||
|
public struct LabelWidthScore : IDisposable
|
||||||
|
{
|
||||||
|
private readonly float _value;
|
||||||
|
public LabelWidthScore(float value)
|
||||||
|
{
|
||||||
|
_value = EditorGUIUtility.labelWidth;
|
||||||
|
EditorGUIUtility.labelWidth = value;
|
||||||
|
}
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
EditorGUIUtility.labelWidth = _value;
|
||||||
|
}
|
||||||
|
}
|
||||||
public struct ColorScope : IDisposable
|
public struct ColorScope : IDisposable
|
||||||
{
|
{
|
||||||
private readonly Color _oldColor;
|
private readonly Color _value;
|
||||||
public ColorScope(Color color)
|
public ColorScope(Color value)
|
||||||
{
|
{
|
||||||
_oldColor = GUI.color;
|
_value = GUI.color;
|
||||||
GUI.color = color;
|
GUI.color = value;
|
||||||
}
|
}
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
GUI.color = _oldColor;
|
GUI.color = _value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct ContentColorScope : IDisposable
|
public struct ContentColorScope : IDisposable
|
||||||
{
|
{
|
||||||
private readonly Color _oldColor;
|
private readonly Color _value;
|
||||||
public ContentColorScope(Color color)
|
public ContentColorScope(Color value)
|
||||||
{
|
{
|
||||||
_oldColor = GUI.contentColor;
|
_value = GUI.contentColor;
|
||||||
GUI.contentColor = color;
|
GUI.contentColor = value;
|
||||||
}
|
}
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
GUI.contentColor = _oldColor;
|
GUI.contentColor = _value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
internal readonly static Color GrayColor = new Color32(100, 100, 100, 255);
|
internal readonly static Color GrayColor = new Color32(100, 100, 100, 255);
|
||||||
internal readonly static Color GreenColor = new Color32(75, 255, 0, 255);
|
internal readonly static Color GreenColor = new Color32(75, 255, 0, 255);
|
||||||
@ -149,17 +163,57 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
{
|
{
|
||||||
return IconButton(position, Icons.Instance.CloseIcon, 0f, "Delete Entity");
|
return IconButton(position, Icons.Instance.CloseIcon, 0f, "Delete Entity");
|
||||||
}
|
}
|
||||||
public static void EntityBar(Rect position, EntityStatus status, int id, short gen, short world)
|
|
||||||
|
|
||||||
|
public static void EntityBarForAlive(Rect position, EntityStatus status, int id, short gen, short world)
|
||||||
|
{
|
||||||
|
EntityBar(position, status != EntityStatus.Alive, status, id, gen, world);
|
||||||
|
}
|
||||||
|
public static void EntityBar(Rect position, int id, short gen, short world)
|
||||||
|
{
|
||||||
|
EntityBar_Internal(position, false, id, gen, world);
|
||||||
|
}
|
||||||
|
public static void EntityBar(Rect position)
|
||||||
|
{
|
||||||
|
EntityBar_Internal(position, true);
|
||||||
|
}
|
||||||
|
public static void EntityBar(Rect position, bool isPlaceholder, EntityStatus status, int id = 0, short gen = 0, short world = 0)
|
||||||
|
{
|
||||||
|
using (new LabelWidthScore(0f))
|
||||||
{
|
{
|
||||||
var (entityInfoRect, statusRect) = RectUtility.VerticalSliceBottom(position, 3f);
|
var (entityInfoRect, statusRect) = RectUtility.VerticalSliceBottom(position, 3f);
|
||||||
|
|
||||||
|
Color statusColor;
|
||||||
|
switch (status)
|
||||||
|
{
|
||||||
|
case EntityStatus.NotAlive:
|
||||||
|
statusColor = EcsGUI.RedColor;
|
||||||
|
break;
|
||||||
|
case EntityStatus.Alive:
|
||||||
|
statusColor = EcsGUI.GreenColor;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
statusColor = new Color32(200, 200, 200, 255);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
statusColor.a = 0.6f;
|
||||||
|
EditorGUI.DrawRect(statusRect, statusColor);
|
||||||
|
|
||||||
|
EntityBar_Internal(entityInfoRect, isPlaceholder, id, gen, world);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static void EntityBar_Internal(Rect position, bool isPlaceHolder, int id = 0, short gen = 0, short world = 0)
|
||||||
|
{
|
||||||
|
using (new LabelWidthScore(0f))
|
||||||
|
{
|
||||||
Color w = Color.gray;
|
Color w = Color.gray;
|
||||||
w.a = 0.6f;
|
w.a = 0.6f;
|
||||||
Color b = Color.black;
|
Color b = Color.black;
|
||||||
b.a = 0.55f;
|
b.a = 0.55f;
|
||||||
EditorGUI.DrawRect(entityInfoRect, w);
|
EditorGUI.DrawRect(position, w);
|
||||||
|
|
||||||
var (idRect, genWorldRect) = RectUtility.HorizontalSliceLerp(entityInfoRect, 0.4f);
|
var (idRect, genWorldRect) = RectUtility.HorizontalSliceLerp(position, 0.4f);
|
||||||
var (genRect, worldRect) = RectUtility.HorizontalSliceLerp(genWorldRect, 0.5f);
|
var (genRect, worldRect) = RectUtility.HorizontalSliceLerp(genWorldRect, 0.5f);
|
||||||
|
|
||||||
idRect = RectUtility.AddPadding(idRect, 2, 1, 0, 0);
|
idRect = RectUtility.AddPadding(idRect, 2, 1, 0, 0);
|
||||||
@ -169,26 +223,10 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
EditorGUI.DrawRect(genRect, b);
|
EditorGUI.DrawRect(genRect, b);
|
||||||
EditorGUI.DrawRect(worldRect, b);
|
EditorGUI.DrawRect(worldRect, b);
|
||||||
|
|
||||||
|
GUIStyle style = UnityEditorUtility.GetInputFieldCenterAnhor();
|
||||||
|
|
||||||
GUIStyle style = new GUIStyle(EditorStyles.numberField);
|
if (isPlaceHolder)
|
||||||
style.alignment = TextAnchor.MiddleCenter;
|
|
||||||
style.font = EditorStyles.boldFont;
|
|
||||||
if (status == EntityStatus.Alive)
|
|
||||||
{
|
{
|
||||||
Color statusColor = EcsGUI.GreenColor;
|
|
||||||
statusColor.a = 0.6f;
|
|
||||||
EditorGUI.DrawRect(statusRect, statusColor);
|
|
||||||
|
|
||||||
EditorGUI.IntField(idRect, id, style);
|
|
||||||
EditorGUI.IntField(genRect, gen, style);
|
|
||||||
EditorGUI.IntField(worldRect, world, style);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Color statusColor = status == EntityStatus.Undefined ? new Color32(200, 200, 200, 255) : EcsGUI.RedColor;
|
|
||||||
statusColor.a = 0.6f;
|
|
||||||
EditorGUI.DrawRect(statusRect, statusColor);
|
|
||||||
|
|
||||||
using (new EditorGUI.DisabledScope(true))
|
using (new EditorGUI.DisabledScope(true))
|
||||||
{
|
{
|
||||||
GUI.Label(idRect, "Entity ID", style);
|
GUI.Label(idRect, "Entity ID", style);
|
||||||
@ -196,6 +234,13 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
GUI.Label(worldRect, "World ID", style);
|
GUI.Label(worldRect, "World ID", style);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EditorGUI.IntField(idRect, id, style);
|
||||||
|
EditorGUI.IntField(genRect, gen, style);
|
||||||
|
EditorGUI.IntField(worldRect, world, style);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool AddComponentButtons(Rect position)
|
public static bool AddComponentButtons(Rect position)
|
||||||
@ -235,12 +280,31 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
EditorGUILayout.IntField("Leaked Entites", leakedEntitesCount, EditorStyles.boldLabel);
|
EditorGUILayout.IntField("Leaked Entites", leakedEntitesCount, EditorStyles.boldLabel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void EntityBar(EntityStatus status, int id, short gen, short world)
|
public static void EntityBarForAlive(EntityStatus status, int id, short gen, short world)
|
||||||
{
|
{
|
||||||
float width = EditorGUIUtility.currentViewWidth;
|
float width = EditorGUIUtility.currentViewWidth;
|
||||||
float height = EntityBarHeight;
|
float height = EntityBarHeight;
|
||||||
EcsGUI.EntityBar(GUILayoutUtility.GetRect(width, height), status, id, gen, world);
|
EcsGUI.EntityBarForAlive(GUILayoutUtility.GetRect(width, height), status, id, gen, world);
|
||||||
}
|
}
|
||||||
|
public static void EntityBar(EntityStatus status, bool isPlaceholder, int id, short gen, short world)
|
||||||
|
{
|
||||||
|
float width = EditorGUIUtility.currentViewWidth;
|
||||||
|
float height = EntityBarHeight;
|
||||||
|
EcsGUI.EntityBar(GUILayoutUtility.GetRect(width, height), isPlaceholder, status, id, gen, world);
|
||||||
|
}
|
||||||
|
public static void EntityBar(int id, short gen, short world)
|
||||||
|
{
|
||||||
|
float width = EditorGUIUtility.currentViewWidth;
|
||||||
|
float height = EntityBarHeight;
|
||||||
|
EcsGUI.EntityBar(GUILayoutUtility.GetRect(width, height), id, gen, world);
|
||||||
|
}
|
||||||
|
public static void EntityBar()
|
||||||
|
{
|
||||||
|
float width = EditorGUIUtility.currentViewWidth;
|
||||||
|
float height = EntityBarHeight;
|
||||||
|
EcsGUI.EntityBar(GUILayoutUtility.GetRect(width, height));
|
||||||
|
}
|
||||||
|
|
||||||
public static bool AddComponentButtons()
|
public static bool AddComponentButtons()
|
||||||
{
|
{
|
||||||
return EcsGUI.AddComponentButtons(GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, 36f));
|
return EcsGUI.AddComponentButtons(GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, 36f));
|
||||||
|
@ -112,9 +112,20 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
private static SparseArray<GUIStyle> colorBoxeStyles = new SparseArray<GUIStyle>();
|
private static SparseArray<GUIStyle> colorBoxeStyles = new SparseArray<GUIStyle>();
|
||||||
private static GUIContent _singletonIconContent = null;
|
private static GUIContent _singletonIconContent = null;
|
||||||
private static GUIContent _singletonContent = null;
|
private static GUIContent _singletonContent = null;
|
||||||
|
private static GUIStyle _inputFieldCenterAnhor = null;
|
||||||
|
|
||||||
#region Label
|
#region Label
|
||||||
|
public static GUIStyle GetInputFieldCenterAnhor()
|
||||||
|
{
|
||||||
|
if (_inputFieldCenterAnhor == null)
|
||||||
|
{
|
||||||
|
GUIStyle style = new GUIStyle(EditorStyles.numberField);
|
||||||
|
style.alignment = TextAnchor.MiddleCenter;
|
||||||
|
style.font = EditorStyles.boldFont;
|
||||||
|
_inputFieldCenterAnhor = style;
|
||||||
|
}
|
||||||
|
return _inputFieldCenterAnhor;
|
||||||
|
}
|
||||||
public static GUIContent GetLabelTemp()
|
public static GUIContent GetLabelTemp()
|
||||||
{
|
{
|
||||||
if (_singletonContent == null)
|
if (_singletonContent == null)
|
||||||
|
Loading…
Reference in New Issue
Block a user