diff --git a/src/Debug/Systems/DebugModule.cs b/src/Debug/Systems/DebugModule.cs new file mode 100644 index 0000000..1353562 --- /dev/null +++ b/src/Debug/Systems/DebugModule.cs @@ -0,0 +1,22 @@ +namespace DCFApixels.DragonECS +{ + public sealed class DebugModule : IEcsModule + { + public const string DEBUG_SYSTEMS_BLOCK = nameof(DEBUG_SYSTEMS_BLOCK); + public EcsWorld[] _worlds; + public DebugModule(params EcsWorld[] worlds) + { + _worlds = worlds; + } + + void IEcsModule.ImportSystems(EcsPipeline.Builder b) + { + b.InsertSystemsBlock(DEBUG_SYSTEMS_BLOCK, EcsConsts.POST_END_SYSTEMS_BLOCK); + b.Add(new PipelineDebugSystem(), DEBUG_SYSTEMS_BLOCK); + foreach (var world in _worlds) + { + b.Add(new WorldDebugSystem(world), DEBUG_SYSTEMS_BLOCK); + } + } + } +} diff --git a/src/Debug/Systems/DebugModule.cs.meta b/src/Debug/Systems/DebugModule.cs.meta new file mode 100644 index 0000000..8c9f05d --- /dev/null +++ b/src/Debug/Systems/DebugModule.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2e2725559ae99464d9df9336b4fc84e9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Debug/Systems/PipelineDebugSystem.cs b/src/Debug/Systems/PipelineDebugSystem.cs index 6a0e651..77221d7 100644 --- a/src/Debug/Systems/PipelineDebugSystem.cs +++ b/src/Debug/Systems/PipelineDebugSystem.cs @@ -54,8 +54,15 @@ namespace DCFApixels.DragonECS private GUIStyle _interfacesStyle; private Color _interfaceColor = new Color(0.96f, 1f, 0.16f); private PipelineDebugMonitor Target => (PipelineDebugMonitor)target; + + + private GUIStyle systemsListStyle; + public override void OnInspectorGUI() { + systemsListStyle = new GUIStyle(EditorStyles.miniLabel); + systemsListStyle.wordWrap = true; + if (Target.source == null) return; if (_headerStyle == null) @@ -66,6 +73,7 @@ namespace DCFApixels.DragonECS _interfacesStyle.focused.textColor = _interfaceColor; _interfacesStyle.active.textColor = _interfaceColor; _interfacesStyle.normal.textColor = _interfaceColor; + _interfacesStyle.wordWrap = true; _headerStyle.fontSize = 28; } @@ -133,7 +141,7 @@ namespace DCFApixels.DragonECS Color color = (GetAttribute(type) ?? _fakeDebugColorAttribute).GetUnityColor(); GUILayout.BeginVertical(EcsEditor.GetStyle(color, 0.2f)); GUILayout.Label(type.Name, EditorStyles.boldLabel); - GUILayout.Label(string.Join(", ", runner.Targets.Cast().Select(o => o.GetType().Name)), EditorStyles.miniLabel); + GUILayout.Label(string.Join(", ", runner.Targets.Cast().Select(o => o.GetType().Name)), systemsListStyle); GUILayout.EndVertical(); } diff --git a/src/Debug/Systems/WorldDebugSystem.cs b/src/Debug/Systems/WorldDebugSystem.cs index 53667d9..1d50c61 100644 --- a/src/Debug/Systems/WorldDebugSystem.cs +++ b/src/Debug/Systems/WorldDebugSystem.cs @@ -5,6 +5,7 @@ using UnityEngine; namespace DCFApixels.DragonECS { + [DebugHide, DebugColor(DebugColor.Gray)] public class WorldDebugSystem : IEcsRunSystem { private string _monitorName; diff --git a/src/Fetures/UnityWorldProvider.cs b/src/Fetures/UnityWorldProvider.cs index 4d33dcf..db141ad 100644 --- a/src/Fetures/UnityWorldProvider.cs +++ b/src/Fetures/UnityWorldProvider.cs @@ -1,7 +1,6 @@ -using DCFApixels.DragonECS; -using System; +using System; -namespace DCFApixels.Assets.DragonECS_Unity.src.Fetures +namespace DCFApixels.DragonECS { public static class UnityWorldProvider where TWorld : EcsWorld @@ -18,5 +17,13 @@ namespace DCFApixels.Assets.DragonECS_Unity.src.Fetures return _world; } + + public static TWorld Get() + { + if (_world == null) + _world = (TWorld)Activator.CreateInstance(typeof(TWorld)); + return _world; + } } + } diff --git a/src/UnityGameObject.cs b/src/UnityGameObject.cs index 2cce2b8..bba3011 100644 --- a/src/UnityGameObject.cs +++ b/src/UnityGameObject.cs @@ -1,5 +1,7 @@ using System.Runtime.CompilerServices; using UnityEngine; +using System.Linq; +using UnityEditor.ShortcutManagement; #if UNITY_EDITOR using UnityEditor; #endif @@ -64,8 +66,8 @@ namespace DCFApixels.DragonECS { EcsEntity result = self.NewEntity(); GameObject newGameObject = new GameObject(name); - newGameObject.AddComponent()._entity = result; - self.GetPool().Add(result.id) = new UnityGameObject(newGameObject); + newGameObject.AddComponent().ConectWith(result); + // self.GetPool().Add(result.id) = #if UNITY_EDITOR if (icon != GameObjectIcon.NONE) { @@ -89,19 +91,58 @@ namespace DCFApixels.DragonECS } } + public class EcsEntityConnect : MonoBehaviour { - internal EcsEntity _entity; - public EcsEntity entity + private sealed class Query : EcsQuery + { + public readonly EcsPool unityGameObjects; + public Query(Builder b) + { + unityGameObjects = b.Include(); + } + } + + private EcsEntity _entity; + private EcsWorld _world; + + #region Properties + public EcsEntity Entity { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _entity; } + public EcsWorld World + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _world; + } public bool IsAlive { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _entity.IsAlive; } + #endregion + + public void ConectWith(EcsEntity entity) + { + int e = _entity.id; + if (_world != null && _entity.IsNotNull) + { + var q = _world.Select(); + q.unityGameObjects.Del(e); + } + _world = null; + + _entity = entity; + + if (_entity.IsNotNull) + { + _world = _entity.GetWorld(); + var q = _world.Select(); + if (!q.unityGameObjects.Has(e)) q.unityGameObjects.Add(e) = new UnityGameObject(gameObject); + } + } } #if UNITY_EDITOR @@ -115,8 +156,8 @@ namespace DCFApixels.DragonECS private EcsEntityConnect Target => (EcsEntityConnect)target; public override void OnInspectorGUI() { - EditorGUILayout.IntField(Target._entity.id); - GUILayout.Label(Target._entity.ToString()); + EditorGUILayout.IntField(Target.Entity.id); + GUILayout.Label(Target.Entity.ToString()); } } }