mirror of
https://github.com/DCFApixels/DragonECS-AutoInjections.git
synced 2025-09-17 12:24:34 +08:00
Automatic dependency injections for DragonECS
|
||
---|---|---|
src | ||
.gitattributes | ||
.gitignore | ||
DragonECS-AutoInjections.asmdef | ||
DragonECS-AutoInjections.asmdef.meta | ||
LICENSE | ||
LICENSE.meta | ||
package.json | ||
package.json.meta | ||
README-RU.md | ||
README-RU.md.meta | ||
README.md | ||
README.md.meta | ||
src.meta |
Auto Injections for DragonECS
Languages: | Русский | English(WIP) |
---|
The extension is designed to reduce the amount of code by simplifying dependency injection by doing injections automatically.
NOTICE: The project is a work in progress, API may change.
While the English version of the README is incomplete, you can view the Russian version.
Versioning
DragonECS uses this versioning semantics: Open
Code Example
class VelocitySystemDI : IEcsRunProcess
{
class Aspect : EcsAspectAuto
{
[ExcImplicit(typeof(FreezedTag))]
[Inc] public EcsPool<Pose> poses;
[Inc] public EcsPool<Velocity> velocities;
}
[EcsInject] EcsDefaultWorld _world;
[EcsInject] TimeService _time;
public void Run(EcsPipeline pipeline)
{
foreach (var e in _world.Where(out Aspect s))
{
s.poses.Write(e).position += s.velocities.Read(e).value * _time.DeltaTime;
}
}
}
Same code but without AutoInjections
class VelocitySystem : IEcsRunProcess, IEcsInject<EcsDefaultWorld>, IEcsInject<TimeService>
{
class Aspect : EcsAspect
{
public EcsPool<Pose> poses;
public EcsPool<Velocity> velocities;
public Aspect(Builder b)
{
b.Exclude<FreezedTag>();
poses = b.Include<Pose>();
velocities = b.Include<Velocity>();
}
}
EcsDefaultWorld _world;
TimeService _time;
public void Inject(EcsDefaultWorld obj) => _world = obj;
public void Inject(TimeService obj) => _time = obj;
public void Run(EcsPipeline pipeline)
{
foreach (var e in _world.Where(out Aspect s))
{
s.poses.Write(e).position += s.velocities.Read(e).value * _time.DeltaTime;
}
}
}