當前位置: 首頁>>代碼示例>>C#>>正文


C# DiContainer.InjectGameObject方法代碼示例

本文整理匯總了C#中Zenject.DiContainer.InjectGameObject方法的典型用法代碼示例。如果您正苦於以下問題:C# DiContainer.InjectGameObject方法的具體用法?C# DiContainer.InjectGameObject怎麽用?C# DiContainer.InjectGameObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zenject.DiContainer的用法示例。


在下文中一共展示了DiContainer.InjectGameObject方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Awake

        public void Awake()
        {
            _container = CreateContainer(
                false, GlobalCompositionRoot.Instance.Container, _staticInstallers);
            _staticInstallers.Clear();

            if (InjectFullScene)
            {
                var rootGameObjects = GameObject.FindObjectsOfType<Transform>()
                    .Where(x => x.parent == null && x.GetComponent<GlobalCompositionRoot>() == null && (x.GetComponent<CompositionRoot>() == null || x == this.transform))
                    .Select(x => x.gameObject).ToList();

                foreach (var rootObj in rootGameObjects)
                {
                    _container.InjectGameObject(rootObj, true, !OnlyInjectWhenActive);
                }
            }
            else
            {
                _container.InjectGameObject(gameObject, true, !OnlyInjectWhenActive);
            }

            _dependencyRoot = _container.Resolve<IDependencyRoot>();
        }
開發者ID:zeljkokalezic,項目名稱:Reactive-Space-Shooter,代碼行數:24,代碼來源:CompositionRoot.cs

示例2: LoadSceneAdditiveWithContainer

        // This method can be used to load the given scene and perform injection on its contents
        // Note that the scene we're loading can have [Inject] flags however it should not have
        // its own composition root
        public static IEnumerator LoadSceneAdditiveWithContainer(
            string levelName, DiContainer parentContainer)
        {
            var rootObjectsBeforeLoad = GameObject.FindObjectsOfType<Transform>().Where(x => x.parent == null).ToList();

            Application.LoadLevelAdditive(levelName);

            // Wait one frame for objects to be added to the scene heirarchy
            yield return null;

            var rootObjectsAfterLoad = GameObject.FindObjectsOfType<Transform>().Where(x => x.parent == null).ToList();

            foreach (var newObject in rootObjectsAfterLoad.Except(rootObjectsBeforeLoad).Select(x => x.gameObject))
            {
                Assert.That(newObject.GetComponent<CompositionRoot>() == null,
                    "LoadSceneAdditiveWithContainer does not expect a container to exist in the loaded scene");

                parentContainer.InjectGameObject(newObject);
            }
        }
開發者ID:IllusiveS,項目名稱:Asteroids,代碼行數:23,代碼來源:ZenUtil.cs

示例3: LoadSceneAdditiveWithContainer

        // This method can be used to load the given scene and perform injection on its contents
        // Note that the scene we're loading can have [Inject] flags however it should not have
        // its own composition root
        public static IEnumerator LoadSceneAdditiveWithContainer(
            string levelName, DiContainer parentContainer)
        {
            var rootObjectsBeforeLoad = UnityUtil.GetRootGameObjects();

            #if UNITY_5_3
            SceneManager.LoadScene(levelName, true);
            #else
            Application.LoadLevelAdditive(levelName);
            #endif

            // Wait one frame for objects to be added to the scene heirarchy
            yield return null;

            var rootObjectsAfterLoad = UnityUtil.GetRootGameObjects();

            foreach (var newObject in rootObjectsAfterLoad.Except(rootObjectsBeforeLoad))
            {
                Assert.That(newObject.GetComponent<SceneCompositionRoot>() == null,
                    "LoadSceneAdditiveWithContainer does not expect a container to exist in the loaded scene");

                parentContainer.InjectGameObject(newObject);
            }
        }
開發者ID:yunspace,項目名稱:UMATutorial,代碼行數:27,代碼來源:ZenUtil.cs

示例4: LoadSceneAdditiveWithContainerAsync

        // This method can be used to load the given scene and perform injection on its contents
        // Note that the scene we're loading can have [Inject] flags however it should not have
        // its own composition root.
        // This Method uses LoadSceneAsync and works in unity from 5.3 and upward.
        // After the loading finishes and the callback parameter is set the callback gets called.
        public static IEnumerator LoadSceneAdditiveWithContainerAsync(string levelName, DiContainer parentContainer,
            Action<Scene> callback)
        {
            var asyncOp = SceneManager.LoadSceneAsync(levelName, LoadSceneMode.Additive);

            yield return asyncOp;

            var scene = SceneManager.GetSceneByName(levelName);

            if (scene.IsValid())
            {
                foreach (var go in scene.GetRootGameObjects())
                {
                    parentContainer.InjectGameObject(go);
                }

                if (callback != null)
                {
                    callback(scene);
                }
            }
        }
開發者ID:Aszan,項目名稱:Zenject,代碼行數:27,代碼來源:ZenUtil.cs


注:本文中的Zenject.DiContainer.InjectGameObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。