本文整理汇总了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>();
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
}