mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 09:54:35 +08:00
update DeleteOneFrameComponentSystem
This commit is contained in:
parent
bf8f6518df
commit
d7494648c9
@ -27,8 +27,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
[DebugHide, DebugColor(DebugColor.Grey)]
|
[DebugHide, DebugColor(DebugColor.Grey)]
|
||||||
public class DeleteOneFrameComponentSystem<TWorld, TComponent> : IEcsRunProcess, IEcsInject<TWorld>
|
public class DeleteOneFrameComponentSystem<TComponent> : IEcsRunProcess, IEcsPreInject
|
||||||
where TWorld : EcsWorld<TWorld>
|
|
||||||
where TComponent : struct, IEcsComponent
|
where TComponent : struct, IEcsComponent
|
||||||
{
|
{
|
||||||
private sealed class Subject : EcsSubject
|
private sealed class Subject : EcsSubject
|
||||||
@ -36,32 +35,35 @@ namespace DCFApixels.DragonECS
|
|||||||
public EcsPool<TComponent> pool;
|
public EcsPool<TComponent> pool;
|
||||||
public Subject(Builder b) => pool = b.Include<TComponent>();
|
public Subject(Builder b) => pool = b.Include<TComponent>();
|
||||||
}
|
}
|
||||||
private TWorld _world;
|
List<EcsWorld> _worlds = new List<EcsWorld>();
|
||||||
public void Inject(TWorld obj) => _world = obj;
|
public void PreInject(object obj)
|
||||||
|
{
|
||||||
|
if (obj is EcsWorld world)
|
||||||
|
_worlds.Add(world);
|
||||||
|
}
|
||||||
public void Run(EcsPipeline pipeline)
|
public void Run(EcsPipeline pipeline)
|
||||||
{
|
{
|
||||||
foreach (var e in _world.Where(out Subject s))
|
for (int i = 0, iMax = _worlds.Count; i < iMax; i++)
|
||||||
|
{
|
||||||
|
EcsWorld world = _worlds[i];
|
||||||
|
if (world.IsComponentTypeDeclared<TComponent>())
|
||||||
|
{
|
||||||
|
foreach (var e in world.Where(out Subject s))
|
||||||
s.pool.Del(e);
|
s.pool.Del(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
public static class DeleteOneFrameComponentSystemExtensions
|
public static class DeleteOneFrameComponentSystemExtensions
|
||||||
{
|
{
|
||||||
private const string AUTO_DEL_LAYER = nameof(AUTO_DEL_LAYER);
|
private const string AUTO_DEL_LAYER = nameof(AUTO_DEL_LAYER);
|
||||||
public static EcsPipeline.Builder AutoDel<TWorld, TComponent>(this EcsPipeline.Builder b)
|
public static EcsPipeline.Builder AutoDel<TComponent>(this EcsPipeline.Builder b, string layerName = AUTO_DEL_LAYER)
|
||||||
where TWorld : EcsWorld<TWorld>
|
|
||||||
where TComponent : struct, IEcsComponent
|
where TComponent : struct, IEcsComponent
|
||||||
{
|
{
|
||||||
|
if(AUTO_DEL_LAYER == layerName)
|
||||||
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER);
|
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER);
|
||||||
b.AddUnique(new DeleteOneFrameComponentSystem<TWorld, TComponent>(), AUTO_DEL_LAYER);
|
b.AddUnique(new DeleteOneFrameComponentSystem<TComponent>(), layerName);
|
||||||
return b;
|
|
||||||
}
|
|
||||||
/// <summary>for EcsDefaultWorld</summary>
|
|
||||||
public static EcsPipeline.Builder AutoDel<TComponent>(this EcsPipeline.Builder b)
|
|
||||||
where TComponent : struct, IEcsComponent
|
|
||||||
{
|
|
||||||
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER);
|
|
||||||
b.AddUnique(new DeleteOneFrameComponentSystem<EcsDefaultWorld, TComponent>(), AUTO_DEL_LAYER);
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user