private System.Collections.IEnumerator DoLoad() { if(_lastScene != null) { //end last scene var endInstruction = _lastScene.EndScene(); if (endInstruction != null) yield return endInstruction; if(_manager._lastSceneBehaviour == _lastScene) _manager._lastSceneBehaviour = null; } var args = new SceneLoadingEventArgs(_manager, _options); object[] instructions; //signal about to load _options.OnBeforeSceneLoaded(_manager, args); _manager.OnBeforeSceneLoaded(args); if (args.ShouldStall(out instructions)) yield return new WaitForAllComplete(GameLoopEntry.Hook, instructions); //do load var scene = _options.GetScene(_manager); _loadOp = (scene != null) ? scene.LoadAsync() : RadicalYieldInstruction.Null; yield return _loadOp; //get scene behaviour var sceneBehaviour = _options.LoadCustomSceneBehaviour(_manager); if(sceneBehaviour == null) { var go = new GameObject("SceneBehaviour"); go.transform.parent = _manager.transform; go.transform.localPosition = Vector3.zero; sceneBehaviour = go.AddComponent<SceneBehaviour>(); } SceneBehaviour.SceneLoadedInstance = sceneBehaviour; _manager._currentSceneBehaviour = sceneBehaviour; //signal loaded _options.OnSceneLoaded(_manager, args); _manager.OnSceneLoaded(args); if (args.ShouldStall(out instructions)) yield return new WaitForAllComplete(GameLoopEntry.Hook, instructions); else yield return null; //wait one last frame to actually begin the scene //signal scene begun _started = true; var beginInstruction = sceneBehaviour.BeginScene(); _options.OnSceneStarted(_manager, args); _manager.OnSceneStarted(args); if (args.ShouldStall(out instructions)) { var waitAll = new WaitForAllComplete(GameLoopEntry.Hook, instructions); if (beginInstruction != null) waitAll.Add(beginInstruction); beginInstruction = waitAll; } if (beginInstruction != null) yield return beginInstruction; _manager._loadingOp = null; this.SetSignal(); }
private System.Collections.IEnumerator DoLoad() { if (_lastScene != null) { //end last scene var endInstruction = _lastScene.EndScene(); if (endInstruction != null) { yield return(endInstruction); } if (_manager._lastSceneBehaviour == _lastScene) { _manager._lastSceneBehaviour = null; } } var args = new SceneLoadingEventArgs(_manager, _options); object[] instructions; //signal about to load _options.OnBeforeSceneLoaded(_manager, args); _manager.OnBeforeSceneLoaded(args); if (args.ShouldStall(out instructions)) { yield return(new WaitForAllComplete(GameLoopEntry.Hook, instructions)); } //do load var scene = _options.GetScene(_manager); _loadOp = (scene != null) ? scene.LoadAsync() : RadicalYieldInstruction.Null; yield return(_loadOp); //get scene behaviour var sceneBehaviour = _options.LoadCustomSceneBehaviour(_manager); if (sceneBehaviour == null) { var go = new GameObject("SceneBehaviour"); go.transform.parent = _manager.transform; go.transform.localPosition = Vector3.zero; sceneBehaviour = go.AddComponent <SceneBehaviour>(); } SceneBehaviour.SceneLoadedInstance = sceneBehaviour; _manager._currentSceneBehaviour = sceneBehaviour; //signal loaded _options.OnSceneLoaded(_manager, args); _manager.OnSceneLoaded(args); if (args.ShouldStall(out instructions)) { yield return(new WaitForAllComplete(GameLoopEntry.Hook, instructions)); } else { yield return(null); //wait one last frame to actually begin the scene } //signal scene begun _started = true; var beginInstruction = sceneBehaviour.BeginScene(); _options.OnSceneStarted(_manager, args); _manager.OnSceneStarted(args); if (args.ShouldStall(out instructions)) { var waitAll = new WaitForAllComplete(GameLoopEntry.Hook, instructions); if (beginInstruction != null) { waitAll.Add(beginInstruction); } beginInstruction = waitAll; } if (beginInstruction != null) { yield return(beginInstruction); } _manager._loadingOp = null; this.SetSignal(); }