Skip to content

Dependency injection for LeoECS Lite

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
Notifications You must be signed in to change notification settings

EffortStar/ecslite-di

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Leopotam ECSLite DI (games.effortstar.ecslite-di)

Dependency injection for LeoECS Lite.

Install

  1. Open Unity Package Manager,
  2. click "+" and select "Add package from git URL...", and
  3. use the following URL
    https://github.com/EffortStar/ecslite-di.git
    

Usage

using Leopotam.EcsLite;
using EffortStar.EcsLite.Di;

class MyGame {
  EcsWorld _world;
  EcsSystems _systems;

  public MyGame(PlayerConfig playerConfig, EnemyConfig enemyConfig) {
    _world = new EcsWorld();
    _systems = new EcsSystems(_world);
    _systems
      .Add(new PlayerSystem())
      .Add(new WeaponSystem())
      .Add(new EnemySystem())
      .Inject(playerConfig, enemyConfig)
      .Init();
  }
}
using Leopotam.EcsLite;
using EffortStar.EcsLite.Di;

class EnemySystem : IEcsRunSystem {
  [Di] EcsWorld _world;
  [Di] EcsFilter<Inc<SpawnEnemy>> _spawnFilter;
  [Di] EcsFilter<Inc<Enemy>, Exc<IsDead>> _enemyFilter;
  [Di] EcsPool<SpawnEnemy> _spawnPool;
  [Di] EcsPool<Enemy> _enemyPool;
  [Di] EnemyConfig _config;

  public void Run(IEcsSystems systems) {
    foreach (var entity in _spawnFilter) {
      ref var spawn = ref _spawnPool.Get(entity);
      SpawnEnemy(spawn.Position);
      _world.DelEntity(entity);
    }

    foreach (var entity in _enemyFilter) {
      ref var enemy = ref _enemyPool.Get(entity);
      enemy.Position += enemy.Direction * _config.MoveSpeed;
    }
  }

  void SpawnEnemy() { /* ... */ }
}

Contributing

Contributions and issues welcome.

License

See license in LICENSE.

About

Dependency injection for LeoECS Lite

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Packages

No packages published

Languages