mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-11-14 18:15:55 +08:00
update injections
This commit is contained in:
parent
d7494648c9
commit
11d9b45ecd
@ -1,5 +1,6 @@
|
||||
using DCFApixels.DragonECS.Internal;
|
||||
using DCFApixels.DragonECS.RunnersCore;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
@ -54,17 +55,38 @@ namespace DCFApixels.DragonECS
|
||||
[DebugHide, DebugColor(DebugColor.Gray)]
|
||||
public sealed class EcsInjectRunner<T> : EcsRunner<IEcsInject<T>>, IEcsInject<T>
|
||||
{
|
||||
private IEcsPreInject _preInjectchache;
|
||||
private EcsBaseTypeInjectRunner _baseTypeInjectRunner;
|
||||
void IEcsInject<T>.Inject(T obj)
|
||||
{
|
||||
_preInjectchache.PreInject(obj);
|
||||
_baseTypeInjectRunner.Inject(obj);
|
||||
foreach (var item in targets) item.Inject(obj);
|
||||
}
|
||||
protected override void OnSetup()
|
||||
{
|
||||
_preInjectchache = Source.GetRunner<IEcsPreInject>();
|
||||
Type baseType = typeof(T).BaseType;
|
||||
if (baseType != typeof(object) && baseType != typeof(ValueType) && baseType != null)
|
||||
_baseTypeInjectRunner = (EcsBaseTypeInjectRunner)Activator.CreateInstance(typeof(EcsBaseTypeInjectRunner<>).MakeGenericType(baseType), Source);
|
||||
else
|
||||
_baseTypeInjectRunner = new EcsObjectTypePreInjectRunner(Source);
|
||||
}
|
||||
}
|
||||
internal abstract class EcsBaseTypeInjectRunner
|
||||
{
|
||||
public abstract void Inject(object obj);
|
||||
}
|
||||
internal class EcsBaseTypeInjectRunner<T> : EcsBaseTypeInjectRunner
|
||||
{
|
||||
private IEcsInject<T> _runner;
|
||||
public EcsBaseTypeInjectRunner(EcsPipeline pipeline) => _runner = pipeline.GetRunner<IEcsInject<T>>();
|
||||
public override void Inject(object obj) => _runner.Inject((T)obj);
|
||||
}
|
||||
internal class EcsObjectTypePreInjectRunner : EcsBaseTypeInjectRunner
|
||||
{
|
||||
private IEcsPreInject _runner;
|
||||
public EcsObjectTypePreInjectRunner(EcsPipeline pipeline) => _runner = pipeline.GetRunner<IEcsPreInject>();
|
||||
public override void Inject(object obj) => _runner.PreInject(obj);
|
||||
}
|
||||
|
||||
[DebugHide, DebugColor(DebugColor.Gray)]
|
||||
public sealed class EcsPreInitInjectProcessRunner : EcsRunner<IEcsPreInitInjectProcess>, IEcsPreInitInjectProcess
|
||||
{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using DCFApixels.DragonECS.Internal;
|
||||
using DCFApixels.DragonECS.Internal;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
@ -12,14 +12,10 @@ namespace DCFApixels.DragonECS
|
||||
public SystemsLayerMarkerSystem(string name) => this.name = name;
|
||||
}
|
||||
[DebugHide, DebugColor(DebugColor.Grey)]
|
||||
public class DeleteEmptyEntitesSystem : IEcsRunProcess, IEcsPreInject
|
||||
public class DeleteEmptyEntitesSystem : IEcsRunProcess, IEcsInject<EcsWorld>
|
||||
{
|
||||
private List<EcsWorld> _worlds = new List<EcsWorld>();
|
||||
public void PreInject(object obj)
|
||||
{
|
||||
if (obj is EcsWorld world)
|
||||
_worlds.Add(world);
|
||||
}
|
||||
public void Inject(EcsWorld obj) => _worlds.Add(obj);
|
||||
public void Run(EcsPipeline pipeline)
|
||||
{
|
||||
foreach (var world in _worlds)
|
||||
@ -27,7 +23,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
}
|
||||
[DebugHide, DebugColor(DebugColor.Grey)]
|
||||
public class DeleteOneFrameComponentSystem<TComponent> : IEcsRunProcess, IEcsPreInject
|
||||
public class DeleteOneFrameComponentSystem<TComponent> : IEcsRunProcess, IEcsInject<EcsWorld>
|
||||
where TComponent : struct, IEcsComponent
|
||||
{
|
||||
private sealed class Subject : EcsSubject
|
||||
@ -36,11 +32,7 @@ namespace DCFApixels.DragonECS
|
||||
public Subject(Builder b) => pool = b.Include<TComponent>();
|
||||
}
|
||||
List<EcsWorld> _worlds = new List<EcsWorld>();
|
||||
public void PreInject(object obj)
|
||||
{
|
||||
if (obj is EcsWorld world)
|
||||
_worlds.Add(world);
|
||||
}
|
||||
public void Inject(EcsWorld obj) => _worlds.Add(obj);
|
||||
public void Run(EcsPipeline pipeline)
|
||||
{
|
||||
for (int i = 0, iMax = _worlds.Count; i < iMax; i++)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user