当前位置: 首页>>代码示例>>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;未经允许,请勿转载。