This commit is contained in:
Mikhail 2023-04-24 16:48:26 +08:00
parent 21e5b61cbc
commit f67b8e236c
7 changed files with 191 additions and 148 deletions

View File

@ -40,6 +40,7 @@ namespace DCFApixels.DragonECS
#if UNITY_EDITOR #if UNITY_EDITOR
namespace Editors namespace Editors
{ {
using DCFApixels.DragonECS.RunnersCore;
using System; using System;
using System.Linq; using System.Linq;
using UnityEditor; using UnityEditor;

View File

@ -8,9 +8,9 @@ namespace DCFApixels.DragonECS
public class WorldDebugSystem : IEcsRunSystem public class WorldDebugSystem : IEcsRunSystem
{ {
private string _monitorName; 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; _monitorName = monitorName;
_ecsWorld = ecsWorld; _ecsWorld = ecsWorld;
@ -24,7 +24,7 @@ namespace DCFApixels.DragonECS
poolsmonitor.source = this; poolsmonitor.source = this;
poolsmonitor.world = _ecsWorld; poolsmonitor.world = _ecsWorld;
poolsmonitor.monitorName = "Pools"; poolsmonitor.monitorName = "pools";
} }
public void Run(EcsPipeline pipeline) public void Run(EcsPipeline pipeline)
@ -35,7 +35,7 @@ namespace DCFApixels.DragonECS
public class WorldDebugMonitor : DebugMonitorBase public class WorldDebugMonitor : DebugMonitorBase
{ {
internal WorldDebugSystem source; internal WorldDebugSystem source;
internal IEcsWorld world; internal EcsWorld world;
} }
#if UNITY_EDITOR #if UNITY_EDITOR
@ -60,7 +60,7 @@ namespace DCFApixels.DragonECS
public class WorldPoolsMonitor : DebugMonitorBase public class WorldPoolsMonitor : DebugMonitorBase
{ {
internal WorldDebugSystem source; internal WorldDebugSystem source;
internal IEcsWorld world; internal EcsWorld world;
} }
#if UNITY_EDITOR #if UNITY_EDITOR
@ -82,75 +82,75 @@ namespace DCFApixels.DragonECS
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {
_scroll = GUILayout.BeginScrollView(_scroll, GUILayout.Height(800f)); // _scroll = GUILayout.BeginScrollView(_scroll, GUILayout.Height(800f));
var pools = Target.world.GetAllPools().ToArray().Where(o => !(o is EcsNullPool)); // var pools = Target.world.GetAllPools().ToArray().Where(o => !(o is EcsNullPool)).OfType<IEcsPool>();
//
GUILayout.Label("", GUILayout.ExpandWidth(true)); // GUILayout.Label("", GUILayout.ExpandWidth(true));
//
float width = GUILayoutUtility.GetLastRect().width; // float width = GUILayoutUtility.GetLastRect().width;
//
Vector3 newPoolBlockSize = _poolBlockMinSize; // Vector3 newPoolBlockSize = _poolBlockMinSize;
int widthCount = Mathf.Max(1, Mathf.Min((Mathf.FloorToInt(width / _poolBlockMinSize.x)), pools.Count())); // int widthCount = Mathf.Max(1, Mathf.Min((Mathf.FloorToInt(width / _poolBlockMinSize.x)), pools.Count()));
newPoolBlockSize.x = width / widthCount; // newPoolBlockSize.x = width / widthCount;
//
int x = -1, y = 0; // int x = -1, y = 0;
foreach (var pool in pools) // foreach (var pool in pools)
{ // {
if(++x >= widthCount) // if(++x >= widthCount)
{ // {
x = 0; // x = 0;
y++; // y++;
} // }
//
DrawPoolBlock(pool, new Rect(newPoolBlockSize.x * x, newPoolBlockSize.y * y, newPoolBlockSize.x, newPoolBlockSize.y)); // DrawPoolBlock(pool, new Rect(newPoolBlockSize.x * x, newPoolBlockSize.y * y, newPoolBlockSize.x, newPoolBlockSize.y));
} // }
GUILayout.EndScrollView(); // GUILayout.EndScrollView();
} }
private void DrawPoolBlock(IEcsPool pool, Rect position) // private void DrawPoolBlock(IEcsPool pool, Rect position)
{ // {
Color defaultContentColor = GUI.contentColor; // Color defaultContentColor = GUI.contentColor;
GUI.contentColor = Color.black * 0.925f; // GUI.contentColor = Color.black * 0.925f;
//
position = AddMargin(position, 1f, 1f); // position = AddMargin(position, 1f, 1f);
//
EditorGUI.DrawRect(position, Color.black* 0.16f); // EditorGUI.DrawRect(position, Color.black* 0.16f);
//
Rect progressBar = new Rect(Vector2.zero, _poolProgressBasrSize); // Rect progressBar = new Rect(Vector2.zero, _poolProgressBasrSize);
progressBar.width = position.width; // progressBar.width = position.width;
progressBar.center = position.center - Vector2.up * _poolBlockMinSize.y * 0.09f; // progressBar.center = position.center - Vector2.up * _poolBlockMinSize.y * 0.09f;
//
//
Color mainColor = new Color(0.3f, 1f, 0f, 1f); // Color mainColor = new Color(0.3f, 1f, 0f, 1f);
var debugColor = pool.ComponentType.GetCustomAttribute<DebugColorAttribute>(); // var debugColor = pool.ComponentType.GetCustomAttribute<DebugColorAttribute>();
if (debugColor != null) // if (debugColor != null)
{ // {
mainColor = debugColor.GetUnityColor(); // mainColor = debugColor.GetUnityColor();
} // }
Color backgroundColor = mainColor * 0.3f + Color.white * 0.2f; // Color backgroundColor = mainColor * 0.3f + Color.white * 0.2f;
//
EditorGUI.DrawRect(progressBar, backgroundColor); // EditorGUI.DrawRect(progressBar, backgroundColor);
//
progressBar.yMin = progressBar.yMax - ((float)pool.Count / pool.Capacity) * progressBar.height; // progressBar.yMin = progressBar.yMax - ((float)pool.Count / pool.Capacity) * progressBar.height;
//
GUIStyle textStyle0 = EditorStyles.miniBoldLabel; // GUIStyle textStyle0 = EditorStyles.miniBoldLabel;
textStyle0.alignment = TextAnchor.MiddleCenter; // textStyle0.alignment = TextAnchor.MiddleCenter;
//
Color foregroundColor = mainColor; // Color foregroundColor = mainColor;
EditorGUI.DrawRect(progressBar, foregroundColor); // EditorGUI.DrawRect(progressBar, foregroundColor);
GUI.Label(progressBar, pool.Count.ToString(), textStyle0); // GUI.Label(progressBar, pool.Count.ToString(), textStyle0);
//
GUIStyle textStyle1 = EditorStyles.miniBoldLabel; // GUIStyle textStyle1 = EditorStyles.miniBoldLabel;
textStyle1.alignment = TextAnchor.UpperCenter; // textStyle1.alignment = TextAnchor.UpperCenter;
GUI.Label(AddMargin(position, 3f, 3f), "Total\r\n"+ pool.Capacity, textStyle1); // GUI.Label(AddMargin(position, 3f, 3f), "Total\r\n"+ pool.Capacity, textStyle1);
//
GUI.contentColor = defaultContentColor; // GUI.contentColor = defaultContentColor;
GUIStyle textStyle2 = EditorStyles.miniBoldLabel; // GUIStyle textStyle2 = EditorStyles.miniBoldLabel;
textStyle2.alignment = TextAnchor.LowerCenter; // textStyle2.alignment = TextAnchor.LowerCenter;
GUI.Label(AddMargin(position, -10f, 3f), pool.ComponentType.Name, textStyle2); // GUI.Label(AddMargin(position, -10f, 3f), pool.ComponentType.Name, textStyle2);
//
} // }
private Rect AddMargin(Rect rect, Vector2 value) private Rect AddMargin(Rect rect, Vector2 value)
{ {

8
src/Fetures.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a20b387d9272da846b2a1206bfb6d53a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,22 @@
using DCFApixels.DragonECS;
using System;
namespace DCFApixels.Assets.DragonECS_Unity.src.Fetures
{
public static class UnityWorldProvider<TWorld>
where TWorld : EcsWorld<TWorld>
{
private static TWorld _world;
public static TWorld Get(Func<TWorld> builder)
{
if (builder == null)
throw new ArgumentNullException();
if (_world == null)
_world = builder();
return _world;
}
}
}

View File

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

View File

@ -1,84 +1,22 @@
namespace DCFApixels.DragonECS using DCFApixels.DragonECS.RunnersCore;
namespace DCFApixels.DragonECS
{ {
public interface IEcsLateRunSystem : IEcsSystem public interface IEcsLateRunSystem : IEcsSystem
{ {
public void LateRun(EcsPipeline pipeline); public void LateRun(EcsPipeline pipeline);
} }
public class EcsLateRunSystemRunner : EcsRunner<IEcsLateRunSystem>, 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 class IEcsLateRunSystemExtensions
{ {
public static void LateRun(this EcsPipeline systems) public static void LateRun(this EcsPipeline systems)
{ {
systems.GetRunner<IEcsLateRunSystem>().LateRun(systems); systems.GetRunner<IEcsLateRunSystem>().LateRun(systems);
} }
} }
public interface IEcsFixedRunSystem : IEcsSystem public interface IEcsFixedRunSystem : IEcsSystem
{ {
public void FixedRun(EcsPipeline pipeline); public void FixedRun(EcsPipeline pipeline);
} }
public class EcsFixedRunSystemRunner : EcsRunner<IEcsFixedRunSystem>, 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 class IEcsFixedRunSystemExtensions
{ {
public static void FixedRun(this EcsPipeline pipeline) public static void FixedRun(this EcsPipeline pipeline)
@ -86,4 +24,68 @@
pipeline.GetRunner<IEcsFixedRunSystem>().FixedRun(pipeline); pipeline.GetRunner<IEcsFixedRunSystem>().FixedRun(pipeline);
} }
} }
namespace Internal
{
[DebugColor(DebugColor.Orange)]
public class EcsLateRunSystemRunner : EcsRunner<IEcsLateRunSystem>, 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>, 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
}
}
} }

View File

@ -7,7 +7,7 @@ using UnityEditor;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
[DebugColor(DebugColor.Cyan)] [DebugColor(DebugColor.Cyan)]
public struct UnityGameObject public struct UnityGameObject : IEcsComponent
{ {
public GameObject gameObject; public GameObject gameObject;
public Transform transform; public Transform transform;
@ -60,13 +60,12 @@ namespace DCFApixels.DragonECS
public static class GameObjectRefExt 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); GameObject newGameObject = new GameObject(name);
newGameObject.AddComponent<EcsEntity>()._entity = result; newGameObject.AddComponent<EcsEntityConnect>()._entity = result;
result.Write<UnityGameObject>() = new UnityGameObject(newGameObject); self.GetPool<UnityGameObject>().Add(result.id) = new UnityGameObject(newGameObject);
#if UNITY_EDITOR #if UNITY_EDITOR
if (icon != GameObjectIcon.NONE) if (icon != GameObjectIcon.NONE)
{ {
@ -90,10 +89,10 @@ namespace DCFApixels.DragonECS
} }
} }
public class EcsEntity : MonoBehaviour public class EcsEntityConnect : MonoBehaviour
{ {
internal ent _entity; internal EcsEntity _entity;
public ent entity public EcsEntity entity
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _entity; get => _entity;
@ -101,7 +100,7 @@ namespace DCFApixels.DragonECS
public bool IsAlive public bool IsAlive
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _entity.IsAlive(); get => _entity.IsAlive;
} }
} }
@ -110,10 +109,10 @@ namespace DCFApixels.DragonECS
namespace Editors namespace Editors
{ {
using UnityEditor; using UnityEditor;
[CustomEditor(typeof(EcsEntity))] [CustomEditor(typeof(EcsEntityConnect))]
public class EcsEntityEditor : Editor public class EcsEntityEditor : Editor
{ {
private EcsEntity Target => (EcsEntity)target; private EcsEntityConnect Target => (EcsEntityConnect)target;
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {
EditorGUILayout.IntField(Target._entity.id); EditorGUILayout.IntField(Target._entity.id);