From 0d9c0dc8a1fb573902582bd7bdbb28c68b760c41 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Tue, 23 May 2023 01:48:54 +0800 Subject: [PATCH] update --- src/Debug/Editor/DebugMonitorPrefs.cs | 2 ++ src/Debug/Editor/EcsEditor.cs | 34 +++--------------------- src/Debug/Systems/PipelineDebugSystem.cs | 2 +- src/Debug/Systems/WorldDebugSystem.cs | 3 ++- src/EntityTemplate/EntityTemplate.cs | 19 +++++++++++++ src/EntityTemplate/ITemplate.cs | 2 +- src/EntityTemplate/TemplateComponent.cs | 12 ++++++++- src/Extensions/UnityComponents.cs | 26 ++++++++++++++++++ src/Extensions/UnityGameObject.cs | 2 +- 9 files changed, 66 insertions(+), 36 deletions(-) diff --git a/src/Debug/Editor/DebugMonitorPrefs.cs b/src/Debug/Editor/DebugMonitorPrefs.cs index a05ade7..276f963 100644 --- a/src/Debug/Editor/DebugMonitorPrefs.cs +++ b/src/Debug/Editor/DebugMonitorPrefs.cs @@ -1,5 +1,6 @@ #if UNITY_EDITOR using UnityEditor; +using UnityEngine; namespace DCFApixels.DragonECS.Editors { @@ -34,6 +35,7 @@ namespace DCFApixels.DragonECS.Editors Save(false); } } + } } #endif diff --git a/src/Debug/Editor/EcsEditor.cs b/src/Debug/Editor/EcsEditor.cs index bf7f92e..1597de2 100644 --- a/src/Debug/Editor/EcsEditor.cs +++ b/src/Debug/Editor/EcsEditor.cs @@ -1,6 +1,5 @@ #if UNITY_EDITOR using System; -using System.Reflection; using System.Runtime.InteropServices; using UnityEngine; @@ -48,40 +47,13 @@ namespace DCFApixels.DragonECS.Editors } - public static string GetGenericName(Type type) - { - string friendlyName = type.Name; - if (type.IsGenericType) - { - int iBacktick = friendlyName.IndexOf('`'); - if (iBacktick > 0) - friendlyName = friendlyName.Remove(iBacktick); - - friendlyName += "<"; - Type[] typeParameters = type.GetGenericArguments(); - for (int i = 0; i < typeParameters.Length; ++i) - { - string typeParamName = GetGenericName(typeParameters[i]); - friendlyName += (i == 0 ? typeParamName : "," + typeParamName); - } - friendlyName += ">"; - } - return friendlyName; - } + public static string GetGenericName(Type type) => EcsDebugUtility.GetGenericTypeName(type); public static string GetName() => GetName(typeof(T)); - public static string GetName(Type type) - { - var atr = type.GetCustomAttribute(); - return atr != null ? atr.name : GetGenericName(type); - } + public static string GetName(Type type) => EcsDebugUtility.GetName(type); public static string GetDescription() => GetDescription(typeof(T)); - public static string GetDescription(Type type) - { - var atr = type.GetCustomAttribute(); - return atr != null ? atr.description : string.Empty; - } + public static string GetDescription(Type type) => EcsDebugUtility.GetDescription(type); #region Utils [StructLayout(LayoutKind.Explicit, Pack = 1, Size = 4)] diff --git a/src/Debug/Systems/PipelineDebugSystem.cs b/src/Debug/Systems/PipelineDebugSystem.cs index 5deb86f..033f766 100644 --- a/src/Debug/Systems/PipelineDebugSystem.cs +++ b/src/Debug/Systems/PipelineDebugSystem.cs @@ -61,7 +61,7 @@ namespace DCFApixels.DragonECS [CustomEditor(typeof(PipelineDebugMonitor))] public class PipelineDebugMonitorEditor : Editor { - private DebugColorAttribute _fakeDebugColorAttribute = new DebugColorAttribute(DebugColor.White); + private DebugColorAttribute _fakeDebugColorAttribute = new DebugColorAttribute(190, 190, 190); private Type _debugColorAttributeType = typeof(DebugColorAttribute); private GUIStyle _headerStyle; private GUIStyle _interfacesStyle; diff --git a/src/Debug/Systems/WorldDebugSystem.cs b/src/Debug/Systems/WorldDebugSystem.cs index 6378b66..7b92448 100644 --- a/src/Debug/Systems/WorldDebugSystem.cs +++ b/src/Debug/Systems/WorldDebugSystem.cs @@ -88,6 +88,7 @@ namespace DCFApixels.DragonECS public override void OnInspectorGUI() { _scroll = GUILayout.BeginScrollView(_scroll, GUILayout.Height(800f)); + var pools = Target.world.AllPools.ToArray().Where(o => !o.IsNullOrDummy()).OfType(); GUILayout.Label("", GUILayout.ExpandWidth(true)); @@ -158,7 +159,7 @@ namespace DCFApixels.DragonECS textStyle2.wordWrap = true; textStyle2.alignment = TextAnchor.LowerCenter; string name = EcsEditor.GetGenericName(pool.ComponentType); - GUIContent label = new GUIContent(name, $"t({name})"); + GUIContent label = new GUIContent(name, $"{name} e:{count}"); GUI.Label(AddMargin(position, -10f, 3f), label, textStyle2); } diff --git a/src/EntityTemplate/EntityTemplate.cs b/src/EntityTemplate/EntityTemplate.cs index da1f441..62a5ed4 100644 --- a/src/EntityTemplate/EntityTemplate.cs +++ b/src/EntityTemplate/EntityTemplate.cs @@ -13,5 +13,24 @@ namespace DCFApixels.DragonECS foreach (var item in _components) item.Add(world, entityID); } + + private void OnDrawGizmos() + { + if (_components == null) return; + foreach (var item in _components) + { + if (item is ITemplateComponentGizmos g) + g.OnGizmos(transform, ITemplateComponentGizmos.Mode.Always); + } + } + private void OnDrawGizmosSelected() + { + if (_components == null) return; + foreach (var item in _components) + { + if (item is ITemplateComponentGizmos g) + g.OnGizmos(transform, ITemplateComponentGizmos.Mode.Selected); + } + } } } diff --git a/src/EntityTemplate/ITemplate.cs b/src/EntityTemplate/ITemplate.cs index c5290c8..c331ec0 100644 --- a/src/EntityTemplate/ITemplate.cs +++ b/src/EntityTemplate/ITemplate.cs @@ -17,7 +17,7 @@ namespace DCFApixels.DragonECS { public static int NewEntity(this ITemplate self, EcsWorld world) { - int e = world.NewEntity(); + int e = world.NewEmptyEntity(); self.Apply(world, e); return e; } diff --git a/src/EntityTemplate/TemplateComponent.cs b/src/EntityTemplate/TemplateComponent.cs index 6a2502a..1cbe3b4 100644 --- a/src/EntityTemplate/TemplateComponent.cs +++ b/src/EntityTemplate/TemplateComponent.cs @@ -15,6 +15,15 @@ namespace DCFApixels.DragonECS { public string Name { get; } } + public interface ITemplateComponentGizmos + { + public void OnGizmos(Transform transform, Mode mode); + public enum Mode + { + Always, + Selected + } + } [Serializable] public abstract class TemplateComponentInitializerBase @@ -62,7 +71,7 @@ namespace DCFApixels.DragonECS #endregion } [Serializable] - public abstract class TemplateComponentInitializer : TemplateComponentInitializerBase, ITemplateComponentName + public abstract class TemplateComponentInitializer : TemplateComponentInitializerBase, ITemplateComponentName, ITemplateComponentGizmos { private static string _autoname = GetName(typeof(T)); private static Color _autoColor = GetColor(typeof(T)); @@ -79,6 +88,7 @@ namespace DCFApixels.DragonECS #endregion public abstract void Add(EcsWorld w, int e); + public virtual void OnGizmos(Transform transform, ITemplateComponentGizmos.Mode mode) { } } internal static class ITemplateBrowsableExt diff --git a/src/Extensions/UnityComponents.cs b/src/Extensions/UnityComponents.cs index 2ea1928..5f539ba 100644 --- a/src/Extensions/UnityComponents.cs +++ b/src/Extensions/UnityComponents.cs @@ -69,4 +69,30 @@ namespace DCFApixels.DragonECS } #endregion + #region Joints + [Serializable] + public sealed class UnityComponentJointInitializer : TemplateComponentInitializer> + { + public override string Name => "UnityComponent/Joint/" + nameof(Joint); + public override void Add(EcsWorld w, int e) => w.GetPool>().Add(e) = component; + } + [Serializable] + public sealed class UnityComponentFixedJointInitializer : TemplateComponentInitializer> + { + public override string Name => "UnityComponent/Joint/" + nameof(FixedJoint); + public override void Add(EcsWorld w, int e) => w.GetPool>().Add(e) = component; + } + [Serializable] + public sealed class UnityComponentCharacterJointInitializer : TemplateComponentInitializer> + { + public override string Name => "UnityComponent/Joint/" + nameof(CharacterJoint); + public override void Add(EcsWorld w, int e) => w.GetPool>().Add(e) = component; + } + [Serializable] + public sealed class UnityComponentConfigurableJointInitializer : TemplateComponentInitializer> + { + public override string Name => "UnityComponent/Joint/" + nameof(ConfigurableJoint); + public override void Add(EcsWorld w, int e) => w.GetPool>().Add(e) = component; + } + #endregion } diff --git a/src/Extensions/UnityGameObject.cs b/src/Extensions/UnityGameObject.cs index 5433fce..aaa8025 100644 --- a/src/Extensions/UnityGameObject.cs +++ b/src/Extensions/UnityGameObject.cs @@ -62,7 +62,7 @@ namespace DCFApixels.DragonECS { public static entlong NewEntityWithGameObject(this EcsWorld self, string name = "EcsEntity", GameObjectIcon icon = GameObjectIcon.NONE) { - entlong result = self.GetEntityLong(self.NewEntity()); + entlong result = self.GetEntityLong(self.NewEmptyEntity()); GameObject newGameObject = new GameObject(name); newGameObject.AddComponent().ConnectWith(result); // self.GetPool().Add(result.id) =