/// <summary> /// Retrieves the first scene that is considered a valid transition /// </summary> /// <param name="sceneManager">The collection of variables and scenes to be processed</param> /// <returns>The scene model of the first passing transition, or null if none pass</returns> public SceneModel GetFirstPassingTransition(SceneManagerController sceneManager) { foreach (SceneTransition transition in Transitions) { if (transition.IsMuted) { continue; } SceneModel destScene = sceneManager.GetSceneById(transition.DestinationSceneId); if (destScene == null) { Debug.LogError("Scene Index of " + transition.DestinationSceneId + " not found. Skipping transition"); continue; } if (!destScene.IsUnlocked) { continue; } if (transition.CanTransition(sceneManager)) { return(destScene); } } return(null); }
private static void LoadEntrySceneOnPlayMode() { IEnumerable <SceneManagerController> controllers = Common.Editors.AssetDatabaseExtensions.GetAssetsOfType <SceneManagerController>(); playModeController = null; wasEntryOpened = false; SceneManagerController controllerToUse = controllers.FirstOrDefault((x) => x.useOnPlay); if (controllerToUse == null || controllerToUse.EntryScene == null) { return; } playModeController = controllerToUse; playModeController.ignoreEntryCall = true; SceneManager.sceneLoaded -= SceneManager_sceneLoaded; SceneManager.sceneLoaded += SceneManager_sceneLoaded; if (!SceneManagerExtensions.IsSceneLoadedByPath(controllerToUse.EntryScene.SceneAssetPath)) { SceneManager.LoadScene(controllerToUse.EntryScene.SceneName); } }
protected override IEnumerator SwapScenes(SceneManagerController sceneManager, SceneModel current, SceneModel desired) { yield return(new WaitForSeconds(WaitTime)); yield return(base.SwapScenes(sceneManager, current, desired)); }
/// <summary> /// Constructor /// </summary> /// <param name="sceneManager">The controller that directed the transition</param> /// <param name="initialScene">The scene the transition was started on</param> /// <param name="destScene">The scene to be loaded</param> public SceneTransitionEventArgs(SceneManagerController sceneManager, SceneModel initialScene, SceneModel destScene) { SceneManager = sceneManager; InitialScene = initialScene; DestinationScene = destScene; }
protected virtual IEnumerator SwapScenes(SceneManagerController sceneManager, SceneModel current, SceneModel desired) { yield return(SceneManager.LoadSceneAsync(desired.SceneName, LoadSceneMode.Single)); OnTransitionCompleted.SafeInvoke( new SceneTransitionEventArgs(sceneManager, current, desired)); swapperCoroutine = null; }
public override bool Transition(SceneManagerController sceneManager, SceneModel current, SceneModel desired) { if (swapperCoroutine != null) { return(false); } OnTransitionStarted.SafeInvoke(new SceneTransitionEventArgs(sceneManager, current, desired)); swapperCoroutine = StartCoroutine(SwapScenes(sceneManager, current, desired)); return(true); }
private static void PlayModeController_OnTransitionerChanged(object sender, EventArgs e) { if (playModeController == null || string.IsNullOrEmpty(playModeController.goToOnPlay)) { return; } if (playModeController.Transitioner == null) { return; } playModeController.OnTransitionerChanged -= PlayModeController_OnTransitionerChanged; playModeController.TransitionToScene(playModeController.goToOnPlay); playModeController = null; }
private static void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1) { if (playModeController == null) { return; } if (!wasEntryOpened) { if (arg0.path == playModeController.EntryScene.SceneAssetPath) { wasEntryOpened = true; } if (!wasEntryOpened) { return; } } if (string.IsNullOrEmpty(playModeController.goToOnPlay)) { playModeController.ignoreEntryCall = false; playModeController = null; return; } if (arg0.path == playModeController.GetSceneByName(playModeController.goToOnPlay).SceneAssetPath) { playModeController.ignoreEntryCall = false; playModeController = null; } else { if (playModeController.Transitioner == null) { playModeController.OnTransitionerChanged += PlayModeController_OnTransitionerChanged; } else { playModeController.TransitionToScene(playModeController.goToOnPlay); } } SceneManager.sceneLoaded -= SceneManager_sceneLoaded; }
protected virtual IEnumerator SwapScenes(SceneManagerController sceneManager, SceneModel current, SceneModel desired) { float progressModifier = current == null ? 1f : 0.5f; yield return(LoadAdditiveSceneAsync(desired, progressModifier)); if (current != null) { yield return(UnloadSceneAsync(current, 2f)); } OnTransitionCompleted.SafeInvoke( new SceneTransitionEventArgs(sceneManager, current, desired)); swapperCoroutine = null; }
/// <summary> /// Checks if the level is now unlocked /// </summary> /// <param name="manager">The manager to check the variables of</param> /// <returns>True if unlocked, false if not</returns> public bool ReevaluateLockStatus(SceneManagerController manager) { // Unlocked if no conditions bool evaluation = true; foreach (SceneCondition lockCondition in LockConditions) { evaluation = lockCondition.IsMet(manager); if (!evaluation) { break; } } IsUnlocked = evaluation; return(evaluation); }
/// <summary> /// Determines if this condition is met /// </summary> /// <param name="param">The scene manager which contains all the variables /// we may need to evaluate</param> /// <returns>True if met, false if not</returns> public sealed override bool IsMet(SceneManagerController param) { if (string.IsNullOrEmpty(VariableName)) { if (Application.isPlaying) { Debug.LogError("No variable identifier provided, cannot evaluate condition"); } return(false); } System.Object varVal = param.SceneVariables.GetObjectValue(VariableName); if (varVal == null && IgnoreNullValues()) { return(false); } return(IsConditionMet(varVal)); }
/// <summary> /// Determines if the transition to the destination scene is valid /// </summary> /// <param name="manager">The manager containing all of the variables to be evaluated</param> /// <returns>True if a transition can be performed, false if not /// Also returns false if DestinationScene is null</returns> public bool CanTransition(SceneManagerController manager) { SceneModel destinationScene = manager.GetSceneById(destinationSceneId); if (destinationScene == null) { return(false); } bool evaluation = true; foreach (SceneCondition condition in Conditions) { evaluation = condition.IsMet(manager); if (!evaluation) { break; } } return(evaluation); }
public abstract bool Transition(SceneManagerController sceneManager, SceneModel current, SceneModel desired);