void Awake() { Stopwatch stopwatch = CreateAndStartStopwatch(); sceneInjector = UniInjectUtils.CreateInjector(); UniInjectUtils.SceneInjector = sceneInjector; // Bind the scene injector itself. // This way it can be injected at the scene start // and be used to inject newly created scripts at runtime. sceneInjector.AddBindingForInstance(sceneInjector); // (1) Iterate over scene hierarchy, thereby // (a) find IBinder instances. // (b) find scripts that need injection and how their members should be injected. AnalyzeScene(); // (2) Store bindings in the sceneInjector CreateBindings(); // (3) Inject the bindings from the sceneInjector into the objects that need injection. InjectScriptsThatNeedInjection(); StopAndLogTime(stopwatch, $"SceneInjectionManager - Analyzing, binding and injecting scene took {stopwatch.ElapsedMilliseconds} ms"); // (4) Notify listeners that scene injection has finished foreach (ISceneInjectionFinishedListener listener in sceneInjectionFinishedListeners) { listener.OnSceneInjectionFinished(); } }
public void DoInjection() { Stopwatch stopwatch = CreateAndStartStopwatch(); sceneInjector = UniInjectUtils.CreateInjector(); UniInjectUtils.SceneInjector = sceneInjector; // Try to find a UIDocument GameObject uiDocumentGameObject = GameObject.FindGameObjectWithTag("UIDocument"); if (uiDocumentGameObject != null) { UIDocument uiDocument = uiDocumentGameObject.GetComponent <UIDocument>(); if (uiDocument != null) { sceneInjector.RootVisualElement = uiDocument.rootVisualElement; } } // Bind the scene injector itself. // This way it can be injected at the scene start // and be used to inject newly created scripts at runtime. sceneInjector.AddBindingForInstance(sceneInjector); // (1) Iterate over scene hierarchy, thereby // (a) find IBinder instances. // (b) find scripts that need injection and how their members should be injected. AnalyzeScene(); // (2) Store bindings in the sceneInjector CreateBindings(); // (3) Inject the bindings from the sceneInjector into the objects that need injection. InjectScriptsThatNeedInjection(); StopAndLogTime(stopwatch, $"SceneInjectionManager - Analyzing, binding and injecting scene took {stopwatch.ElapsedMilliseconds} ms"); // (4) Notify listeners that scene injection has finished foreach (ISceneInjectionFinishedListener listener in sceneInjectionFinishedListeners) { listener.OnSceneInjectionFinished(); } }