/// <summary> /// The scene where we actually add/remove gameplay related entities. /// <br /> /// <b>Warning:</b> Do not hold a direct reference to the returned gameplay scene because it can potentially change. /// </summary> public Scene GetGameplayScene() { if (_gameplayScene != null) { return(_gameplayScene); } // Entities are added to the InGameScreen scene rather than the root scene _previousRootScene = _sceneSystem.SceneInstance.RootScene; var sceneManager = GameServicesExt.GetSceneManagerFromRootScene(_previousRootScene); Debug.Assert(sceneManager != null, $"SceneManager entity must contain {nameof(SceneManager)} component."); Debug.Assert(sceneManager.ActiveMainSceneHandler is InGameSceneHandler, "Must be in-game."); _gameplayScene = sceneManager.ActiveMainSceneHandler.Scene; sceneManager.MainSceneChanged += OnMainSceneChanged; return(_gameplayScene); }
private void UnregisterMainSceneChangedEventHandler(Scene rootScene) { var sceneManager = GameServicesExt.GetSceneManagerFromRootScene(rootScene); sceneManager.MainSceneChanged -= OnMainSceneChanged; }