Automatic dependency injections for DragonECS
Go to file
2023-06-22 15:45:11 +08:00
src refactoring 2023-06-22 14:39:35 +08:00
.gitattributes Initial commit 2023-03-29 04:50:13 +08:00
.gitignore change git ignore 2023-06-12 23:00:50 +08:00
DragonECS-AutoInjections.asmdef Init 2023-03-29 16:43:06 +08:00
DragonECS-AutoInjections.asmdef.meta Init 2023-03-29 16:43:06 +08:00
LICENSE Initial commit 2023-03-29 04:50:13 +08:00
LICENSE.meta change git ignore 2023-06-12 23:00:50 +08:00
package.json Update package.json 2023-06-22 15:45:11 +08:00
package.json.meta change git ignore 2023-06-12 23:00:50 +08:00
README-RU.md Update README-RU.md 2023-06-22 15:40:35 +08:00
README-RU.md.meta change git ignore 2023-06-12 23:00:50 +08:00
README.md Update README.md 2023-06-12 15:08:11 +08:00
README.md.meta change git ignore 2023-06-12 23:00:50 +08:00
src.meta change git ignore 2023-06-12 23:00:50 +08:00

Version License

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 Subject : EcsSubjectDI
    {
        [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 Subject 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 Subject : EcsSubject
    {
        public EcsPool<Pose> poses;
        public EcsPool<Velocity> velocities;
        public Subject(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 Subject s))
        {
            s.poses.Write(e).position += s.velocities.Read(e).value * _time.DeltaTime;
        }
    }
}