This commit is contained in:
Mikhail 2023-04-26 16:54:27 +08:00
parent f67b8e236c
commit dd41a6f2b8
6 changed files with 100 additions and 10 deletions

View File

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

View File

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

View File

@ -54,8 +54,15 @@ namespace DCFApixels.DragonECS
private GUIStyle _interfacesStyle; private GUIStyle _interfacesStyle;
private Color _interfaceColor = new Color(0.96f, 1f, 0.16f); private Color _interfaceColor = new Color(0.96f, 1f, 0.16f);
private PipelineDebugMonitor Target => (PipelineDebugMonitor)target; private PipelineDebugMonitor Target => (PipelineDebugMonitor)target;
private GUIStyle systemsListStyle;
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {
systemsListStyle = new GUIStyle(EditorStyles.miniLabel);
systemsListStyle.wordWrap = true;
if (Target.source == null) if (Target.source == null)
return; return;
if (_headerStyle == null) if (_headerStyle == null)
@ -66,6 +73,7 @@ namespace DCFApixels.DragonECS
_interfacesStyle.focused.textColor = _interfaceColor; _interfacesStyle.focused.textColor = _interfaceColor;
_interfacesStyle.active.textColor = _interfaceColor; _interfacesStyle.active.textColor = _interfaceColor;
_interfacesStyle.normal.textColor = _interfaceColor; _interfacesStyle.normal.textColor = _interfaceColor;
_interfacesStyle.wordWrap = true;
_headerStyle.fontSize = 28; _headerStyle.fontSize = 28;
} }
@ -133,7 +141,7 @@ namespace DCFApixels.DragonECS
Color color = (GetAttribute<DebugColorAttribute>(type) ?? _fakeDebugColorAttribute).GetUnityColor(); Color color = (GetAttribute<DebugColorAttribute>(type) ?? _fakeDebugColorAttribute).GetUnityColor();
GUILayout.BeginVertical(EcsEditor.GetStyle(color, 0.2f)); GUILayout.BeginVertical(EcsEditor.GetStyle(color, 0.2f));
GUILayout.Label(type.Name, EditorStyles.boldLabel); GUILayout.Label(type.Name, EditorStyles.boldLabel);
GUILayout.Label(string.Join(", ", runner.Targets.Cast<object>().Select(o => o.GetType().Name)), EditorStyles.miniLabel); GUILayout.Label(string.Join(", ", runner.Targets.Cast<object>().Select(o => o.GetType().Name)), systemsListStyle);
GUILayout.EndVertical(); GUILayout.EndVertical();
} }

View File

@ -5,6 +5,7 @@ using UnityEngine;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
[DebugHide, DebugColor(DebugColor.Gray)]
public class WorldDebugSystem : IEcsRunSystem public class WorldDebugSystem : IEcsRunSystem
{ {
private string _monitorName; private string _monitorName;

View File

@ -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<TWorld> public static class UnityWorldProvider<TWorld>
where TWorld : EcsWorld<TWorld> where TWorld : EcsWorld<TWorld>
@ -18,5 +17,13 @@ namespace DCFApixels.Assets.DragonECS_Unity.src.Fetures
return _world; return _world;
} }
public static TWorld Get()
{
if (_world == null)
_world = (TWorld)Activator.CreateInstance(typeof(TWorld));
return _world;
}
} }
} }

View File

@ -1,5 +1,7 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using UnityEngine; using UnityEngine;
using System.Linq;
using UnityEditor.ShortcutManagement;
#if UNITY_EDITOR #if UNITY_EDITOR
using UnityEditor; using UnityEditor;
#endif #endif
@ -64,8 +66,8 @@ namespace DCFApixels.DragonECS
{ {
EcsEntity result = self.NewEntity(); EcsEntity result = self.NewEntity();
GameObject newGameObject = new GameObject(name); GameObject newGameObject = new GameObject(name);
newGameObject.AddComponent<EcsEntityConnect>()._entity = result; newGameObject.AddComponent<EcsEntityConnect>().ConectWith(result);
self.GetPool<UnityGameObject>().Add(result.id) = new UnityGameObject(newGameObject); // self.GetPool<UnityGameObject>().Add(result.id) =
#if UNITY_EDITOR #if UNITY_EDITOR
if (icon != GameObjectIcon.NONE) if (icon != GameObjectIcon.NONE)
{ {
@ -89,19 +91,58 @@ namespace DCFApixels.DragonECS
} }
} }
public class EcsEntityConnect : MonoBehaviour public class EcsEntityConnect : MonoBehaviour
{ {
internal EcsEntity _entity; private sealed class Query : EcsQuery
public EcsEntity entity {
public readonly EcsPool<UnityGameObject> unityGameObjects;
public Query(Builder b)
{
unityGameObjects = b.Include<UnityGameObject>();
}
}
private EcsEntity _entity;
private EcsWorld _world;
#region Properties
public EcsEntity Entity
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _entity; get => _entity;
} }
public EcsWorld World
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _world;
}
public bool IsAlive public bool IsAlive
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _entity.IsAlive; get => _entity.IsAlive;
} }
#endregion
public void ConectWith(EcsEntity entity)
{
int e = _entity.id;
if (_world != null && _entity.IsNotNull)
{
var q = _world.Select<Query>();
q.unityGameObjects.Del(e);
}
_world = null;
_entity = entity;
if (_entity.IsNotNull)
{
_world = _entity.GetWorld();
var q = _world.Select<Query>();
if (!q.unityGameObjects.Has(e)) q.unityGameObjects.Add(e) = new UnityGameObject(gameObject);
}
}
} }
#if UNITY_EDITOR #if UNITY_EDITOR
@ -115,8 +156,8 @@ namespace DCFApixels.DragonECS
private EcsEntityConnect Target => (EcsEntityConnect)target; private EcsEntityConnect Target => (EcsEntityConnect)target;
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {
EditorGUILayout.IntField(Target._entity.id); EditorGUILayout.IntField(Target.Entity.id);
GUILayout.Label(Target._entity.ToString()); GUILayout.Label(Target.Entity.ToString());
} }
} }
} }