mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 10:04:36 +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)]
|
[DebugHide, DebugColor(DebugColor.Grey)]
|
||||||
public class DeleteOneFrameComponentFixedSystem<TWorld, TComponent> : IEcsFixedRunProcess, IEcsInject<TWorld>
|
public class DeleteOneFrameComponentFixedSystem<TComponent> : IEcsFixedRunProcess, IEcsInject<EcsWorld>
|
||||||
where TWorld : EcsWorld<TWorld>
|
|
||||||
where TComponent : struct, IEcsComponent
|
where TComponent : struct, IEcsComponent
|
||||||
{
|
{
|
||||||
private TWorld _world;
|
|
||||||
public void Inject(TWorld obj) => _world = obj;
|
|
||||||
|
|
||||||
private sealed class Subject : EcsSubject
|
private sealed class Subject : EcsSubject
|
||||||
{
|
{
|
||||||
public EcsPool<TComponent> pool;
|
public EcsPool<TComponent> pool;
|
||||||
public Subject(Builder b)
|
public Subject(Builder b) => pool = b.Include<TComponent>();
|
||||||
{
|
|
||||||
pool = b.Include<TComponent>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
List<EcsWorld> _worlds = new List<EcsWorld>();
|
||||||
|
public void Inject(EcsWorld obj) => _worlds.Add(obj);
|
||||||
public void FixedRun(EcsPipeline pipeline)
|
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
|
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);
|
||||||
//}
|
|
||||||
//catch (System.Exception)
|
|
||||||
//{
|
|
||||||
//
|
|
||||||
// throw;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public static class DeleteOneFrameComponentFixedSystemExt
|
public static class DeleteOneFrameComponentFixedSystemExtensions
|
||||||
{
|
{
|
||||||
private const string AUTO_DEL_FIXED_LAYER = nameof(AUTO_DEL_FIXED_LAYER);
|
private const string AUTO_DEL_LAYER = nameof(AUTO_DEL_LAYER);
|
||||||
public static EcsPipeline.Builder AutoDelFixed<TWorld, TComponent>(this EcsPipeline.Builder b)
|
public static EcsPipeline.Builder AutoDelFixed<TComponent>(this EcsPipeline.Builder b, string layerName = AUTO_DEL_LAYER)
|
||||||
where TWorld : EcsWorld<TWorld>
|
|
||||||
where TComponent : struct, IEcsComponent
|
where TComponent : struct, IEcsComponent
|
||||||
{
|
{
|
||||||
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_FIXED_LAYER);
|
if (AUTO_DEL_LAYER == layerName)
|
||||||
b.AddUnique(new DeleteOneFrameComponentFixedSystem<TWorld, TComponent>(), AUTO_DEL_FIXED_LAYER);
|
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER);
|
||||||
return b;
|
b.AddUnique(new DeleteOneFrameComponentSystem<TComponent>(), layerName);
|
||||||
}
|
|
||||||
/// <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);
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user