From f67b8e236cc86ac64f0bac9dbcee5b0c76763602 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Mon, 24 Apr 2023 16:48:26 +0800 Subject: [PATCH] update --- src/Debug/Systems/PipelineDebugSystem.cs | 1 + src/Debug/Systems/WorldDebugSystem.cs | 142 +++++++++++------------ src/Fetures.meta | 8 ++ src/Fetures/UnityWorldProvider.cs | 22 ++++ src/Fetures/UnityWorldProvider.cs.meta | 11 ++ src/Runners/Runners.cs | 132 ++++++++++----------- src/UnityGameObject.cs | 23 ++-- 7 files changed, 191 insertions(+), 148 deletions(-) create mode 100644 src/Fetures.meta create mode 100644 src/Fetures/UnityWorldProvider.cs create mode 100644 src/Fetures/UnityWorldProvider.cs.meta diff --git a/src/Debug/Systems/PipelineDebugSystem.cs b/src/Debug/Systems/PipelineDebugSystem.cs index ee53d44..6a0e651 100644 --- a/src/Debug/Systems/PipelineDebugSystem.cs +++ b/src/Debug/Systems/PipelineDebugSystem.cs @@ -40,6 +40,7 @@ namespace DCFApixels.DragonECS #if UNITY_EDITOR namespace Editors { + using DCFApixels.DragonECS.RunnersCore; using System; using System.Linq; using UnityEditor; diff --git a/src/Debug/Systems/WorldDebugSystem.cs b/src/Debug/Systems/WorldDebugSystem.cs index 71672bb..53667d9 100644 --- a/src/Debug/Systems/WorldDebugSystem.cs +++ b/src/Debug/Systems/WorldDebugSystem.cs @@ -8,9 +8,9 @@ namespace DCFApixels.DragonECS public class WorldDebugSystem : IEcsRunSystem { private string _monitorName; - private IEcsWorld _ecsWorld; + private EcsWorld _ecsWorld; - public WorldDebugSystem(IEcsWorld ecsWorld, string monitorName = "World") + public WorldDebugSystem(EcsWorld ecsWorld, string monitorName = "World") { _monitorName = monitorName; _ecsWorld = ecsWorld; @@ -24,7 +24,7 @@ namespace DCFApixels.DragonECS poolsmonitor.source = this; poolsmonitor.world = _ecsWorld; - poolsmonitor.monitorName = "Pools"; + poolsmonitor.monitorName = "pools"; } public void Run(EcsPipeline pipeline) @@ -35,7 +35,7 @@ namespace DCFApixels.DragonECS public class WorldDebugMonitor : DebugMonitorBase { internal WorldDebugSystem source; - internal IEcsWorld world; + internal EcsWorld world; } #if UNITY_EDITOR @@ -60,7 +60,7 @@ namespace DCFApixels.DragonECS public class WorldPoolsMonitor : DebugMonitorBase { internal WorldDebugSystem source; - internal IEcsWorld world; + internal EcsWorld world; } #if UNITY_EDITOR @@ -82,75 +82,75 @@ namespace DCFApixels.DragonECS public override void OnInspectorGUI() { - _scroll = GUILayout.BeginScrollView(_scroll, GUILayout.Height(800f)); - var pools = Target.world.GetAllPools().ToArray().Where(o => !(o is EcsNullPool)); - - GUILayout.Label("", GUILayout.ExpandWidth(true)); - - float width = GUILayoutUtility.GetLastRect().width; - - Vector3 newPoolBlockSize = _poolBlockMinSize; - int widthCount = Mathf.Max(1, Mathf.Min((Mathf.FloorToInt(width / _poolBlockMinSize.x)), pools.Count())); - newPoolBlockSize.x = width / widthCount; - - int x = -1, y = 0; - foreach (var pool in pools) - { - if(++x >= widthCount) - { - x = 0; - y++; - } - - DrawPoolBlock(pool, new Rect(newPoolBlockSize.x * x, newPoolBlockSize.y * y, newPoolBlockSize.x, newPoolBlockSize.y)); - } - GUILayout.EndScrollView(); + // _scroll = GUILayout.BeginScrollView(_scroll, GUILayout.Height(800f)); + // var pools = Target.world.GetAllPools().ToArray().Where(o => !(o is EcsNullPool)).OfType(); + // + // GUILayout.Label("", GUILayout.ExpandWidth(true)); + // + // float width = GUILayoutUtility.GetLastRect().width; + // + // Vector3 newPoolBlockSize = _poolBlockMinSize; + // int widthCount = Mathf.Max(1, Mathf.Min((Mathf.FloorToInt(width / _poolBlockMinSize.x)), pools.Count())); + // newPoolBlockSize.x = width / widthCount; + // + // int x = -1, y = 0; + // foreach (var pool in pools) + // { + // if(++x >= widthCount) + // { + // x = 0; + // y++; + // } + // + // DrawPoolBlock(pool, new Rect(newPoolBlockSize.x * x, newPoolBlockSize.y * y, newPoolBlockSize.x, newPoolBlockSize.y)); + // } + // GUILayout.EndScrollView(); } - private void DrawPoolBlock(IEcsPool pool, Rect position) - { - Color defaultContentColor = GUI.contentColor; - GUI.contentColor = Color.black * 0.925f; - - position = AddMargin(position, 1f, 1f); - - EditorGUI.DrawRect(position, Color.black* 0.16f); - - Rect progressBar = new Rect(Vector2.zero, _poolProgressBasrSize); - progressBar.width = position.width; - progressBar.center = position.center - Vector2.up * _poolBlockMinSize.y * 0.09f; - - - Color mainColor = new Color(0.3f, 1f, 0f, 1f); - var debugColor = pool.ComponentType.GetCustomAttribute(); - if (debugColor != null) - { - mainColor = debugColor.GetUnityColor(); - } - Color backgroundColor = mainColor * 0.3f + Color.white * 0.2f; - - EditorGUI.DrawRect(progressBar, backgroundColor); - - progressBar.yMin = progressBar.yMax - ((float)pool.Count / pool.Capacity) * progressBar.height; - - GUIStyle textStyle0 = EditorStyles.miniBoldLabel; - textStyle0.alignment = TextAnchor.MiddleCenter; - - Color foregroundColor = mainColor; - EditorGUI.DrawRect(progressBar, foregroundColor); - GUI.Label(progressBar, pool.Count.ToString(), textStyle0); - - GUIStyle textStyle1 = EditorStyles.miniBoldLabel; - textStyle1.alignment = TextAnchor.UpperCenter; - GUI.Label(AddMargin(position, 3f, 3f), "Total\r\n"+ pool.Capacity, textStyle1); - - GUI.contentColor = defaultContentColor; - GUIStyle textStyle2 = EditorStyles.miniBoldLabel; - textStyle2.alignment = TextAnchor.LowerCenter; - GUI.Label(AddMargin(position, -10f, 3f), pool.ComponentType.Name, textStyle2); - - } + // private void DrawPoolBlock(IEcsPool pool, Rect position) + // { + // Color defaultContentColor = GUI.contentColor; + // GUI.contentColor = Color.black * 0.925f; + // + // position = AddMargin(position, 1f, 1f); + // + // EditorGUI.DrawRect(position, Color.black* 0.16f); + // + // Rect progressBar = new Rect(Vector2.zero, _poolProgressBasrSize); + // progressBar.width = position.width; + // progressBar.center = position.center - Vector2.up * _poolBlockMinSize.y * 0.09f; + // + // + // Color mainColor = new Color(0.3f, 1f, 0f, 1f); + // var debugColor = pool.ComponentType.GetCustomAttribute(); + // if (debugColor != null) + // { + // mainColor = debugColor.GetUnityColor(); + // } + // Color backgroundColor = mainColor * 0.3f + Color.white * 0.2f; + // + // EditorGUI.DrawRect(progressBar, backgroundColor); + // + // progressBar.yMin = progressBar.yMax - ((float)pool.Count / pool.Capacity) * progressBar.height; + // + // GUIStyle textStyle0 = EditorStyles.miniBoldLabel; + // textStyle0.alignment = TextAnchor.MiddleCenter; + // + // Color foregroundColor = mainColor; + // EditorGUI.DrawRect(progressBar, foregroundColor); + // GUI.Label(progressBar, pool.Count.ToString(), textStyle0); + // + // GUIStyle textStyle1 = EditorStyles.miniBoldLabel; + // textStyle1.alignment = TextAnchor.UpperCenter; + // GUI.Label(AddMargin(position, 3f, 3f), "Total\r\n"+ pool.Capacity, textStyle1); + // + // GUI.contentColor = defaultContentColor; + // GUIStyle textStyle2 = EditorStyles.miniBoldLabel; + // textStyle2.alignment = TextAnchor.LowerCenter; + // GUI.Label(AddMargin(position, -10f, 3f), pool.ComponentType.Name, textStyle2); + // + // } private Rect AddMargin(Rect rect, Vector2 value) { diff --git a/src/Fetures.meta b/src/Fetures.meta new file mode 100644 index 0000000..c6ada3a --- /dev/null +++ b/src/Fetures.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a20b387d9272da846b2a1206bfb6d53a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Fetures/UnityWorldProvider.cs b/src/Fetures/UnityWorldProvider.cs new file mode 100644 index 0000000..4d33dcf --- /dev/null +++ b/src/Fetures/UnityWorldProvider.cs @@ -0,0 +1,22 @@ +using DCFApixels.DragonECS; +using System; + +namespace DCFApixels.Assets.DragonECS_Unity.src.Fetures +{ + public static class UnityWorldProvider + where TWorld : EcsWorld + { + private static TWorld _world; + + public static TWorld Get(Func builder) + { + if (builder == null) + throw new ArgumentNullException(); + + if (_world == null) + _world = builder(); + + return _world; + } + } +} diff --git a/src/Fetures/UnityWorldProvider.cs.meta b/src/Fetures/UnityWorldProvider.cs.meta new file mode 100644 index 0000000..107dcbc --- /dev/null +++ b/src/Fetures/UnityWorldProvider.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d0af8ddc3edb89242a26c1d308a18c87 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Runners/Runners.cs b/src/Runners/Runners.cs index 69cec0e..12f3a6e 100644 --- a/src/Runners/Runners.cs +++ b/src/Runners/Runners.cs @@ -1,84 +1,22 @@ -namespace DCFApixels.DragonECS +using DCFApixels.DragonECS.RunnersCore; + +namespace DCFApixels.DragonECS { public interface IEcsLateRunSystem : IEcsSystem { public void LateRun(EcsPipeline pipeline); } - - public class EcsLateRunSystemRunner : EcsRunner, IEcsLateRunSystem - { -#if DEBUG && !DISABLE_DEBUG - private EcsProfilerMarker[] _markers; -#endif - public void LateRun(EcsPipeline pipeline) - { -#if DEBUG && !DISABLE_DEBUG - for (int i = 0; i < targets.Length; i++) - { - using (_markers[i].Auto()) - targets[i].LateRun(pipeline); - } -#else - foreach (var item in targets) item.LateRun(pipeline); -#endif - } - -#if DEBUG && !DISABLE_DEBUG - protected override void OnSetup() - { - _markers = new EcsProfilerMarker[targets.Length]; - for (int i = 0; i < targets.Length; i++) - { - _markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(LateRun)}")); - } - } -#endif - } public static class IEcsLateRunSystemExtensions { public static void LateRun(this EcsPipeline systems) { systems.GetRunner().LateRun(systems); } - } - - - - public interface IEcsFixedRunSystem : IEcsSystem { public void FixedRun(EcsPipeline pipeline); } - public class EcsFixedRunSystemRunner : EcsRunner, IEcsFixedRunSystem - { -#if DEBUG && !DISABLE_DEBUG - private EcsProfilerMarker[] _markers; -#endif - public void FixedRun(EcsPipeline pipeline) - { -#if DEBUG && !DISABLE_DEBUG - for (int i = 0; i < targets.Length; i++) - { - using (_markers[i].Auto()) - targets[i].FixedRun(pipeline); - } -#else - foreach (var item in targets) item.FixedRun(pipeline); -#endif - } - -#if DEBUG && !DISABLE_DEBUG - protected override void OnSetup() - { - _markers = new EcsProfilerMarker[targets.Length]; - for (int i = 0; i < targets.Length; i++) - { - _markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(FixedRun)}")); - } - } -#endif - } public static class IEcsFixedRunSystemExtensions { public static void FixedRun(this EcsPipeline pipeline) @@ -86,4 +24,68 @@ pipeline.GetRunner().FixedRun(pipeline); } } + + namespace Internal + { + [DebugColor(DebugColor.Orange)] + public class EcsLateRunSystemRunner : EcsRunner, IEcsLateRunSystem + { +#if DEBUG && !DISABLE_DEBUG + private EcsProfilerMarker[] _markers; +#endif + public void LateRun(EcsPipeline pipeline) + { +#if DEBUG && !DISABLE_DEBUG + for (int i = 0; i < targets.Length; i++) + { + using (_markers[i].Auto()) + targets[i].LateRun(pipeline); + } +#else + foreach (var item in targets) item.LateRun(pipeline); +#endif + } + +#if DEBUG && !DISABLE_DEBUG + protected override void OnSetup() + { + _markers = new EcsProfilerMarker[targets.Length]; + for (int i = 0; i < targets.Length; i++) + { + _markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(LateRun)}")); + } + } +#endif + } + [DebugColor(DebugColor.Orange)] + public class EcsFixedRunSystemRunner : EcsRunner, IEcsFixedRunSystem + { +#if DEBUG && !DISABLE_DEBUG + private EcsProfilerMarker[] _markers; +#endif + public void FixedRun(EcsPipeline pipeline) + { +#if DEBUG && !DISABLE_DEBUG + for (int i = 0; i < targets.Length; i++) + { + using (_markers[i].Auto()) + targets[i].FixedRun(pipeline); + } +#else + foreach (var item in targets) item.FixedRun(pipeline); +#endif + } + +#if DEBUG && !DISABLE_DEBUG + protected override void OnSetup() + { + _markers = new EcsProfilerMarker[targets.Length]; + for (int i = 0; i < targets.Length; i++) + { + _markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(FixedRun)}")); + } + } +#endif + } + } } diff --git a/src/UnityGameObject.cs b/src/UnityGameObject.cs index 9cf71bb..2cce2b8 100644 --- a/src/UnityGameObject.cs +++ b/src/UnityGameObject.cs @@ -7,7 +7,7 @@ using UnityEditor; namespace DCFApixels.DragonECS { [DebugColor(DebugColor.Cyan)] - public struct UnityGameObject + public struct UnityGameObject : IEcsComponent { public GameObject gameObject; public Transform transform; @@ -60,13 +60,12 @@ namespace DCFApixels.DragonECS public static class GameObjectRefExt { - public static ent NewEntityWithGameObject(this IEcsWorld self, string name = "Entity", GameObjectIcon icon = GameObjectIcon.NONE) + public static EcsEntity NewEntityWithGameObject(this EcsWorld self, string name = "EcsEntity", GameObjectIcon icon = GameObjectIcon.NONE) { - ent result = self.NewEntity(); + EcsEntity result = self.NewEntity(); GameObject newGameObject = new GameObject(name); - newGameObject.AddComponent()._entity = result; - result.Write() = new UnityGameObject(newGameObject); - + newGameObject.AddComponent()._entity = result; + self.GetPool().Add(result.id) = new UnityGameObject(newGameObject); #if UNITY_EDITOR if (icon != GameObjectIcon.NONE) { @@ -90,10 +89,10 @@ namespace DCFApixels.DragonECS } } - public class EcsEntity : MonoBehaviour + public class EcsEntityConnect : MonoBehaviour { - internal ent _entity; - public ent entity + internal EcsEntity _entity; + public EcsEntity entity { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _entity; @@ -101,7 +100,7 @@ namespace DCFApixels.DragonECS public bool IsAlive { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _entity.IsAlive(); + get => _entity.IsAlive; } } @@ -110,10 +109,10 @@ namespace DCFApixels.DragonECS namespace Editors { using UnityEditor; - [CustomEditor(typeof(EcsEntity))] + [CustomEditor(typeof(EcsEntityConnect))] public class EcsEntityEditor : Editor { - private EcsEntity Target => (EcsEntity)target; + private EcsEntityConnect Target => (EcsEntityConnect)target; public override void OnInspectorGUI() { EditorGUILayout.IntField(Target._entity.id);