Automatic dependency injections for DragonECS
Go to file
2025-03-15 15:10:16 +08:00
src defines refactoring 2025-03-15 15:10:16 +08:00
.gitattributes Initial commit 2023-03-29 04:50:13 +08:00
.gitignore Update .gitignore 2025-01-06 10:50:46 +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.md add .md extension for LICENSE 2025-03-14 14:24:58 +08:00
LICENSE.md.meta add .md extension for LICENSE 2025-03-14 14:24:58 +08:00
package.json up version to 0.9.16 2024-12-31 23:22:01 +08:00
package.json.meta change git ignore 2023-06-12 23:00:50 +08:00
README-RU.md update readme 2024-11-12 13:30:34 +08:00
README-RU.md.meta change git ignore 2023-06-12 23:00:50 +08:00
README.md update readme 2024-11-12 13:30:34 +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 Discord QQ

Auto Injections for DragonECS

Readme Languages:

Русский

English(WIP)

The extension is designed to reduce the amount of code by simplifying dependency injection by doing injections automatically.

Warning

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.


Installation

Versioning semantics - Open

Environment

Requirements:

  • Dependency: DragonECS
  • Minimum version of C# 7.3;

Optional:

  • Game engines with C#: Unity, Godot, MonoGame, etc.

Tested with:

  • Unity: Minimum version 2020.1.0;

Unity Installation

  • Unity Package

The package can be installed as a Unity package by adding the Git URL in the PackageManager or manually adding it to Packages/manifest.json:

https://github.com/DCFApixels/DragonECS-AutoInjections.git
  • Source Code

The package can also be added to the project as source code.


Code Example

class VelocitySystemDI : IEcsRun
{
    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()
    {
        foreach (var e in _world.Where(out Aspect a))
        {
            a.poses.Get(e).position += a.velocities.Read(e).value * _time.DeltaTime;
        }
    }
}
Same code but without AutoInjections
class VelocitySystem : IEcsRun, 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()
    {
        foreach (var e in _world.Where(out Aspect a))
        {
            a.poses.Get(e).position += a.velocities.Read(e).value * _time.DeltaTime;
        }
    }
}