mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 01:54:35 +08:00
udpate AutoDelFixed
This commit is contained in:
parent
45cbf45d13
commit
0080246ca8
@ -1,55 +1,41 @@
|
||||
namespace DCFApixels.DragonECS
|
||||
using DCFApixels.DragonECS.Internal;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
[DebugHide, DebugColor(DebugColor.Grey)]
|
||||
public class DeleteOneFrameComponentFixedSystem<TWorld, TComponent> : IEcsFixedRunProcess, IEcsInject<TWorld>
|
||||
where TWorld : EcsWorld<TWorld>
|
||||
where TComponent : struct, IEcsComponent
|
||||
public class DeleteOneFrameComponentFixedSystem<TComponent> : IEcsFixedRunProcess, IEcsInject<EcsWorld>
|
||||
where TComponent : struct, IEcsComponent
|
||||
{
|
||||
private TWorld _world;
|
||||
public void Inject(TWorld obj) => _world = obj;
|
||||
|
||||
private sealed class Subject : EcsSubject
|
||||
{
|
||||
public EcsPool<TComponent> pool;
|
||||
public Subject(Builder b)
|
||||
{
|
||||
pool = b.Include<TComponent>();
|
||||
}
|
||||
public Subject(Builder b) => pool = b.Include<TComponent>();
|
||||
}
|
||||
List<EcsWorld> _worlds = new List<EcsWorld>();
|
||||
public void Inject(EcsWorld obj) => _worlds.Add(obj);
|
||||
public void FixedRun(EcsPipeline pipeline)
|
||||
{
|
||||
foreach (var e in _world.Where(out Subject s))
|
||||
for (int i = 0, iMax = _worlds.Count; i < iMax; i++)
|
||||
{
|
||||
//try
|
||||
//{
|
||||
s.pool.Del(e);
|
||||
//}
|
||||
//catch (System.Exception)
|
||||
//{
|
||||
//
|
||||
// throw;
|
||||
//}
|
||||
EcsWorld world = _worlds[i];
|
||||
if (world.IsComponentTypeDeclared<TComponent>())
|
||||
{
|
||||
foreach (var e in world.Where(out Subject s))
|
||||
s.pool.Del(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class DeleteOneFrameComponentFixedSystemExt
|
||||
public static class DeleteOneFrameComponentFixedSystemExtensions
|
||||
{
|
||||
private const string AUTO_DEL_FIXED_LAYER = nameof(AUTO_DEL_FIXED_LAYER);
|
||||
public static EcsPipeline.Builder AutoDelFixed<TWorld, TComponent>(this EcsPipeline.Builder b)
|
||||
where TWorld : EcsWorld<TWorld>
|
||||
private const string AUTO_DEL_LAYER = nameof(AUTO_DEL_LAYER);
|
||||
public static EcsPipeline.Builder AutoDelFixed<TComponent>(this EcsPipeline.Builder b, string layerName = AUTO_DEL_LAYER)
|
||||
where TComponent : struct, IEcsComponent
|
||||
{
|
||||
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_FIXED_LAYER);
|
||||
b.AddUnique(new DeleteOneFrameComponentFixedSystem<TWorld, TComponent>(), AUTO_DEL_FIXED_LAYER);
|
||||
return b;
|
||||
}
|
||||
/// <summary> for EcsDefaultWorld </summary>
|
||||
public static EcsPipeline.Builder AutoDelFixed<TComponent>(this EcsPipeline.Builder b)
|
||||
where TComponent : struct, IEcsComponent
|
||||
{
|
||||
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_FIXED_LAYER);
|
||||
b.AddUnique(new DeleteOneFrameComponentFixedSystem<EcsDefaultWorld, TComponent>(), AUTO_DEL_FIXED_LAYER);
|
||||
if (AUTO_DEL_LAYER == layerName)
|
||||
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER);
|
||||
b.AddUnique(new DeleteOneFrameComponentSystem<TComponent>(), layerName);
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user