Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. public static IEnumerator LoadSceneAdditiveWithContainer(string levelName, DiContainer parentContainer)
  2.     {
  3.         var rootObjectsBeforeLoad = GameObject.FindObjectsOfType<Transform>().Where(x => x.parent == null).ToList();
  4.  
  5.         Application.LoadLevelAdditive(levelName);
  6.  
  7.         // Wait one frame for objects to be added to the scene heirarchy
  8.         yield return null;
  9.  
  10.         var rootObjectsAfterLoad = GameObject.FindObjectsOfType<Transform>().Where(x => x.parent == null).ToList();
  11.  
  12.         foreach (var newObject in rootObjectsAfterLoad.Except(rootObjectsBeforeLoad).Select(x => x.gameObject))
  13.         {
  14.             Assert.That(newObject.GetComponent<CompositionRoot>() == null,
  15.                 "LoadSceneAdditiveWithContainer does not expect a container to exist in the loaded scene");
  16.  
  17.             InjectionHelper.InjectChildGameObjects(parentContainer, newObject);
  18.         }
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement