2023-04-26 16:45:37 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace DCFApixels.DragonECS
|
2023-03-27 20:31:45 +08:00
|
|
|
|
{
|
2023-05-07 00:50:02 +08:00
|
|
|
|
[DebugHide, DebugColor(DebugColor.Black)]
|
2023-03-27 20:31:45 +08:00
|
|
|
|
public class SystemsBlockMarkerSystem : IEcsSystem
|
|
|
|
|
{
|
|
|
|
|
public readonly string name;
|
2023-05-23 02:11:00 +08:00
|
|
|
|
public SystemsBlockMarkerSystem(string name) { this.name = name; }
|
2023-03-27 20:31:45 +08:00
|
|
|
|
}
|
2023-05-23 02:11:00 +08:00
|
|
|
|
|
2023-04-26 16:45:37 +08:00
|
|
|
|
[DebugHide, DebugColor(DebugColor.Grey)]
|
2023-05-07 00:50:02 +08:00
|
|
|
|
public class DeleteEmptyEntitesSystem : IEcsRunProcess, IEcsPreInject
|
2023-04-26 16:45:37 +08:00
|
|
|
|
{
|
|
|
|
|
private List<EcsWorld> _worlds = new List<EcsWorld>();
|
|
|
|
|
public void PreInject(object obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj is EcsWorld world)
|
|
|
|
|
_worlds.Add(world);
|
|
|
|
|
}
|
|
|
|
|
public void Run(EcsPipeline pipeline)
|
|
|
|
|
{
|
|
|
|
|
foreach (var world in _worlds)
|
|
|
|
|
world.DeleteEmptyEntites();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-26 16:54:18 +08:00
|
|
|
|
[DebugHide, DebugColor(DebugColor.Grey)]
|
2023-05-07 00:50:02 +08:00
|
|
|
|
public class DeleteOneFrameComponentSystem<TWorld, TComponent> : IEcsRunProcess, IEcsInject<TWorld>
|
2023-04-26 16:45:37 +08:00
|
|
|
|
where TWorld : EcsWorld<TWorld>
|
|
|
|
|
where TComponent : struct, IEcsComponent
|
|
|
|
|
{
|
|
|
|
|
private TWorld _world;
|
|
|
|
|
public void Inject(TWorld obj) => _world = obj;
|
2023-05-07 00:50:02 +08:00
|
|
|
|
private sealed class Subject : EcsSubject
|
2023-04-26 16:45:37 +08:00
|
|
|
|
{
|
|
|
|
|
public EcsPool<TComponent> pool;
|
2023-05-07 00:50:02 +08:00
|
|
|
|
public Subject(Builder b)
|
2023-04-26 16:45:37 +08:00
|
|
|
|
{
|
|
|
|
|
pool = b.Include<TComponent>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void Run(EcsPipeline pipeline)
|
|
|
|
|
{
|
2023-05-07 00:50:02 +08:00
|
|
|
|
foreach (var e in _world.Where(out Subject s))
|
|
|
|
|
s.pool.Del(e);
|
2023-04-26 16:45:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class DeleteOneFrameComponentSystemExt
|
|
|
|
|
{
|
2023-05-07 00:50:02 +08:00
|
|
|
|
private const string AUTO_DEL_LAYER = nameof(AUTO_DEL_LAYER);
|
2023-04-26 16:45:37 +08:00
|
|
|
|
public static EcsPipeline.Builder AutoDel<TWorld, TComponent>(this EcsPipeline.Builder b)
|
|
|
|
|
where TWorld : EcsWorld<TWorld>
|
|
|
|
|
where TComponent : struct, IEcsComponent
|
|
|
|
|
{
|
2023-05-07 00:50:02 +08:00
|
|
|
|
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER);
|
|
|
|
|
b.AddUnique(new DeleteOneFrameComponentSystem<TWorld, TComponent>(), AUTO_DEL_LAYER);
|
2023-04-26 16:45:37 +08:00
|
|
|
|
return b;
|
|
|
|
|
}
|
2023-05-23 02:11:00 +08:00
|
|
|
|
/// <summary>for EcsDefaultWorld</summary>
|
2023-04-26 16:45:37 +08:00
|
|
|
|
public static EcsPipeline.Builder AutoDel<TComponent>(this EcsPipeline.Builder b)
|
|
|
|
|
where TComponent : struct, IEcsComponent
|
|
|
|
|
{
|
2023-05-07 00:50:02 +08:00
|
|
|
|
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER);
|
|
|
|
|
b.AddUnique(new DeleteOneFrameComponentSystem<EcsDefaultWorld, TComponent>(), AUTO_DEL_LAYER);
|
2023-04-26 16:45:37 +08:00
|
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-27 20:31:45 +08:00
|
|
|
|
}
|