Dependency injection for LeoECS Lite.
Tested on unity 2020.3 (not dependent on it) and contains assembly definition for compiling to separate assembly file for performance reason.
Important! Don't forget to use
DEBUG
builds for development andRELEASE
builds in production: all internal error checks / exception throwing works only inDEBUG
builds and eleminated for performance reasons inRELEASE
.
This repository can be installed as unity module directly from git url. In this way new line should be added to Packages/manifest.json
:
"com.goodcat.ecslite.shared": "https://github.com/GoodCatGames/ecslite-multiple-shared.git"
If you can't / don't want to use unity modules, code can be downloaded as sources archive from Releases
page.
var battleLog = new BattleLog();
IBattleLogView battleLogView = null;
#if DEBUG
battleLogView = new BattleLogViewText(battleLog);
#else
battleLogView = new BattleLogViewHtml(battleLog);
#endif
// If you use InjectShared() you cannot create systems with SharedCustom:
// var systems = new EcsSystems (new EcsWorld(), new SharedCustom());
// You will get an exception.
var systems = new EcsSystems(new EcsWorld());
systems
.Add (new System1())
.Add (new System2())
.Add (new BattleLogShowSystem())
// ...
// InjectShared() methods should be placed after
// all systems/worlds registration
.InjectShared(battleLog)
.InjectShared<IBattleLogView>(battleLogView)
// InitShared() method should be placed after
// all InjectShared() methods
.InitShared()
.Init();
public class BattleLogShowSystem : IEcsRunSystem
{
[EcsInject] private readonly BattleLogViewBase _battleLogView;
public void Run(EcsSystems systems)
{
_battleLogView.Show();
}
}
// Getting Shared directly from systems
var shared = systems.GetShared<shared.Shared>();
var battleLogView = shared.Get<IBattleLogView>();
battleLogView.Show();
The software is released under the terms of the MIT license.
No personal support or any guarantees.