using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using static Zenject.ZenAutoInjecter; using Zenject; using ModestTree; public static class Injector { static DiContainer LookupContainer(GameObject go, ContainerSources container) { if (container == ContainerSources.ProjectContext) { return ProjectContext.Instance.Container; } if (container == ContainerSources.SceneContext) { return GetContainerForCurrentScene(go); } Assert.IsEqual(container, ContainerSources.SearchHierarchy); var parentContext = go.transform.GetComponentInParent(); if (parentContext != null) { return parentContext.Container; } return GetContainerForCurrentScene(go); } static DiContainer GetContainerForCurrentScene(GameObject go) { return ProjectContext.Instance.Container .Resolve() .GetContainerForScene(go.scene); } public static void Inject(this GameObject go, ContainerSources container = ContainerSources.SceneContext) { LookupContainer(go, container).InjectGameObject(go); } }