/// <summary>
 /// Start the specified tory scene state after the <c>delay</c> in seconds.
 /// </summary>
 /// <returns>The tory scene state to start.</returns>
 /// <param name="scene">Scene.</param>
 /// <param name="delay">Delay in seconds.</param>
 public void Start(IToryScene scene, float delay)
 {
     Start(scene, delay, false);
 }
 /// <summary>
 /// Start the specified tory scene state after the <c>delay</c> in seconds.
 /// You can determine when to end the current tory scene via the <c>endNow</c> parameter.
 /// </summary>
 /// <returns>The start.</returns>
 /// <param name="scene">The tory scene state to start.</param>
 /// <param name="delay">Delay in seconds.</param>
 /// <param name="endNow">If set to <c>true</c>, end the current tory scene immediately, and then wait the <c>delay</c> in seconds to start the next tory scene. If set to <c>false</c>, wait the <c>delay</c> in seconds before ending the current tory scene.</param>
 public void Start(IToryScene scene, float delay, bool endNow)
 {
     SceneBehaviour.StartCoroutine(End(scene, delay, endNow));
 }
 /// <summary>
 /// Start the specified tory scene state.
 /// </summary>
 /// <param name="scene">The tory scene state to start.</param>
 public void Start(IToryScene scene)
 {
     Start(scene, 0f);
 }
        protected IEnumerator End(IToryScene toScene = null, float delay = 0f, bool endNow = false)
        {
            // Check if this scene is under forced stay or not.
            if (!IsForcedStayTimerTimedOut)
            {
                if (FrameworkBehaviour.CanShowLog)
                {
                    Debug.Log("[ToryScene] The tory scene (" + smb.Name + ") lasts for "
                              + (ToryTime.Instance.ForcedStayTimer).ToString("F1")
                              + " seconds.");
                }
                yield break;
            }

            // Check if this scene is already ended.
            if (!IsPlaying)
            {
                yield break;
            }
            IsPlaying = false;

            // Delay.
            if (!endNow && delay > 0f)
            {
                yield return(new WaitForSeconds(delay));
            }

            // End the updates
            if (updateCrt != null)
            {
                SceneBehaviour.StopCoroutine(updateCrt);
            }
            if (fixedUpdateCrt != null)
            {
                SceneBehaviour.StopCoroutine(fixedUpdateCrt);
            }

            // Time - end the timer methods.
            System.Type type = ToryTime.Instance.GetType();
            MethodInfo  StopForcedStayTimer = type.GetMethod("StopForcedStayTimer", (BindingFlags.NonPublic |
                                                                                     BindingFlags.Public |
                                                                                     BindingFlags.Instance));
            MethodInfo StopInteractionCheckTimer = type.GetMethod("StopInteractionCheckTimer", (BindingFlags.NonPublic |
                                                                                                BindingFlags.Public |
                                                                                                BindingFlags.Instance));
            MethodInfo StopTransitionTimer = type.GetMethod("StopTransitionTimer", (BindingFlags.NonPublic |
                                                                                    BindingFlags.Public |
                                                                                    BindingFlags.Instance));

            if (StopForcedStayTimer != null)
            {
                StopForcedStayTimer.Invoke(ToryTime.Instance, null);
            }
            if (StopInteractionCheckTimer != null)
            {
                StopInteractionCheckTimer.Invoke(ToryTime.Instance, null);
            }
            if (StopTransitionTimer != null)
            {
                StopTransitionTimer.Invoke(ToryTime.Instance, null);
            }

            // Time - remove listeners.
            ToryTime.Instance.ForcedStayTimerTimedOut       -= OnForcedStayTimerTimedOut;
            ToryTime.Instance.InteractionCheckTimerTimedOut -= OnInteractionCheckTimerTimedOut;
            ToryTime.Instance.TransitionTimerTimedOut       -= OnTransitionTimerTimedOut;

            // Input
            ToryInput.Instance.Interacted -= Interacted;
            ToryInput.Instance.PlayerLeft -= OnPlayerLeft;

            // End
            if (FrameworkBehaviour.CanShowLog)
            {
                Debug.Log("[ToryScene] The current tory scene state (" + smb.Name + ") ended.");
            }
            Ended();

            // Reset fields
            IsForcedStayTimerTimedOut       = false;
            IsInteractionCheckTimerTimedOut = false;
            IsTransitionTimerTimedOut       = false;
            IsPlayerLeft = false;

            // Delay.
            if (endNow && delay > 0f)
            {
                yield return(new WaitForSeconds(delay));
            }

            // If set to the forced end, end the ToryScene.
            if (forcedEnd)
            {
                // Go to Scene.End.
                type = ToryScene.Instance.GetType();
                MethodInfo method = type.GetMethod("End", (BindingFlags.NonPublic |
                                                           BindingFlags.Public |
                                                           BindingFlags.Instance));
                if (method != null)
                {
                    method.Invoke(ToryScene.Instance, null);
                }
            }
            else if (toScene != null)
            {
                // Go to the specified scene.
                type = toScene.GetType();
                MethodInfo method = type.GetMethod("Start", (BindingFlags.NonPublic |
                                                             BindingFlags.Instance));
                if (method != null)
                {
                    method.Invoke(toScene, null);
                }
            }
            else
            {
                // Go to the Next.Start.
                if (Next != null)
                {
                    type = Next.GetType();
                    MethodInfo method = type.GetMethod("Start", (BindingFlags.NonPublic |
                                                                 BindingFlags.Instance));
                    if (method != null)
                    {
                        method.Invoke(Next, null);
                    }
                }
                else
                {
                    // Go to the Scene.End.
                    type = ToryScene.Instance.GetType();
                    MethodInfo method = type.GetMethod("End", (BindingFlags.NonPublic |
                                                               BindingFlags.Public |
                                                               BindingFlags.Instance));
                    if (method != null)
                    {
                        method.Invoke(ToryScene.Instance, null);
                    }
                }
            }
        }
 /// <summary>
 /// Start the specified tory scene state after the <c>delay</c> in seconds.
 /// You can determine when to end the current tory scene via the <c>endNow</c> parameter.
 /// </summary>
 /// <returns>The start.</returns>
 /// <param name="scene">The tory scene state to start.</param>
 /// <param name="delay">Delay in seconds.</param>
 /// <param name="endNow">If set to <c>true</c>, end the current tory scene immediately, and then wait the <c>delay</c> in seconds to start the next tory scene. If set to <c>false</c>, wait the <c>delay</c> in seconds before ending the current tory scene.</param>
 public void Start(IToryScene scene, float delay, bool endNow)
 {
     Current.Start(scene, delay, endNow);
 }
 /// <summary>
 /// Start the specified tory scene state after the <c>delay</c> in seconds.
 /// </summary>
 /// <returns>The tory scene state to start.</returns>
 /// <param name="scene">Scene.</param>
 /// <param name="delay">Delay in seconds.</param>
 public void Start(IToryScene scene, float delay)
 {
     Current.Start(scene, delay);
 }
 /// <summary>
 /// Start the specified tory scene state.
 /// </summary>
 /// <param name="scene">The tory scene state to start.</param>
 public void Start(IToryScene scene)
 {
     Current.Start(scene);
 }