diff --git a/src/Injections/Injector.cs b/src/Injections/Injector.cs index 0ed7313..a8842e9 100644 --- a/src/Injections/Injector.cs +++ b/src/Injections/Injector.cs @@ -167,6 +167,7 @@ namespace DCFApixels.DragonECS private EcsPipeline.Builder _source; private Injector _instance; private List _initInjections = new List(16); + private EcsWorld _monoWorld; internal Builder(EcsPipeline.Builder source) { _source = source; @@ -179,10 +180,34 @@ namespace DCFApixels.DragonECS } public EcsPipeline.Builder Inject(T obj) { + if(obj is EcsWorld objWorld) + { + if(_monoWorld == null) + { + _monoWorld = objWorld; + } + else + { + Type monoWorldType = _monoWorld.GetType(); + Type objWorldType = objWorld.GetType(); + if (monoWorldType != objWorldType) + { + if(objWorldType == typeof(EcsWorld)) + { // Екземпляр EcsWorld имеет самый больший приоритет. + _monoWorld = objWorld; + } + if(objWorldType == typeof(EcsDefaultWorld) && + monoWorldType != typeof(EcsWorld)) + { // Екземпляр EcsDefaultWorld имеет приоритет больше других типов, но меньше приоритета EcsWorld. + _monoWorld = objWorld; + } + } + } + } _initInjections.Add(new InitInject(obj)); return _source; } - public EcsPipeline.Builder Extract(ref T obj)//TODO проверить + public EcsPipeline.Builder Extract(ref T obj) // TODO проверить { Type type = typeof(T); for (int i = _initInjections.Count - 1; i >= 0; i--) @@ -199,6 +224,12 @@ namespace DCFApixels.DragonECS } public Injector Build(EcsPipeline pipeline) { + var monoWorldProcess = pipeline.GetProcess(); // TODO Проверить IMonoWorldInject + foreach (var monoWorldSystem in monoWorldProcess) + { + monoWorldSystem.World = _monoWorld; + } + _instance.Init(pipeline); foreach (var item in _initInjections) { diff --git a/src/Injections/Utils/Interfaces.cs b/src/Injections/Utils/Interfaces.cs index 8af0ffe..7ecd48f 100644 --- a/src/Injections/Utils/Interfaces.cs +++ b/src/Injections/Utils/Interfaces.cs @@ -9,6 +9,10 @@ { void Inject(T obj); } + public interface IMonoWorldInject : IEcsProcess + { + EcsWorld World { get; set; } + } [MetaName(nameof(OnInitInjectionComplete))] [MetaColor(MetaColor.DragonRose)] [MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.DI_GROUP)]