void Start()
        {
            // Check if this scene is already started.
            if (playing)
            {
                return;
            }

            // Initialize
            playing           = true;
            startTime         = Time.time;
            unscaledStartTime = Time.unscaledTime;
            IsCleared         = false;

            // Time
            ToryTime.Instance.ForcedStayTimerTimedOut       += ForcedStayTimerTimedOut;
            ToryTime.Instance.InteractionCheckTimerTimedOut += InteractionCheckTimerTimedOut;
            ToryTime.Instance.TransitionTimerTimedOut       += TransitionTimerTimedOut;

            // Input
            ToryInput.Instance.Interacted += Interacted;
            ToryInput.Instance.PlayerLeft += PlayerLeft;

            // Start
            if (FrameworkBehaviour.CanShowLog)
            {
                Debug.Log("[ToryScene] A new tory scene loaded.");
            }
            Loaded();

            // Start
            if (FrameworkBehaviour.CanShowLog)
            {
                Debug.Log("[ToryScene] A new tory scene started.");
            }
            Started();

            // Start the first tory scene.
            System.Type type   = First.GetType();
            MethodInfo  method = type.GetMethod("Start", (BindingFlags.NonPublic |
                                                          BindingFlags.Instance));

            if (method != null)
            {
                method.Invoke(First, null);
            }

            // Start update coroutines.
            updateCrt      = SceneBehaviour.StartCoroutine(Update());
            fixedUpdateCrt = SceneBehaviour.StartCoroutine(FixedUpdate());
        }
 /// <summary>
 /// Loads a new tory scene after the <c>delay</c> in seconds.
 /// You can determine when to end the current tory scene via the <c>endNow</c> parameter.
 /// </summary>
 /// <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 load a new tory scene. If set to <c>false</c>, wait the <c>delay</c> in seconds before loading a new tory scene.</param>
 public void LoadToryScene(float delay, bool endNow)
 {
     forcedEnd = true;
     SceneBehaviour.StartCoroutine(End(null, delay, endNow));
 }
 /// <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>
 /// Proceed to the next 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>
 /// <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 Proceed(float delay, bool endNow)
 {
     SceneBehaviour.StartCoroutine(End(null, delay, endNow));
 }
        protected void Start()
        {
            // Check if this scene is already started.
            if (IsPlaying)
            {
                return;
            }

            // Initialzie
            IsPlaying                       = true;
            forcedEnd                       = false;
            startTime                       = Time.time;
            unscaledStartTime               = Time.unscaledTime;
            IsForcedStayTimerTimedOut       = (ForcedStayTimeSinceStarted > 0f) ? false : true;
            IsInteractionCheckTimerTimedOut = false;
            IsTransitionTimerTimedOut       = false;
            IsPlayerLeft                    = false;

            // Set the current tory scene.
            System.Type  type = ToryScene.Instance.GetType();
            PropertyInfo prop = type.GetProperty("Current", (BindingFlags.NonPublic |
                                                             BindingFlags.Public |
                                                             BindingFlags.Instance));

            if (prop != null)
            {
                prop.SetValue(ToryScene.Instance, this, null);
            }

            // Time - reset and add listener to the ForcedStayTimerTimedOut event.
            type = ToryTime.Instance.GetType();
            MethodInfo method = type.GetMethod("ResetForcedStayTimer", (BindingFlags.NonPublic |
                                                                        BindingFlags.Public |
                                                                        BindingFlags.Instance));

            if (method != null)
            {
                method.Invoke(ToryTime.Instance, null);
            }
            ToryTime.Instance.ForcedStayTimerTimedOut += OnForcedStayTimerTimedOut;

            // Time - reset and add listener to the InteractionCheckTimerTimedOut event.
            method = type.GetMethod("ResetInteractionCheckTimer", (BindingFlags.NonPublic |
                                                                   BindingFlags.Public |
                                                                   BindingFlags.Instance));
            if (method != null)
            {
                method.Invoke(ToryTime.Instance, null);
            }
            ToryTime.Instance.InteractionCheckTimerTimedOut += OnInteractionCheckTimerTimedOut;

            // Time - reset and add listener to the TransitionTimerTimedOut event.
            method = type.GetMethod("ResetTransitionTimer", (BindingFlags.NonPublic |
                                                             BindingFlags.Public |
                                                             BindingFlags.Instance));
            if (method != null)
            {
                method.Invoke(ToryTime.Instance, null);
            }
            ToryTime.Instance.TransitionTimerTimedOut += OnTransitionTimerTimedOut;

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

            // Time - Start the timer methods.
            MethodInfo StartForcedStayTimer = type.GetMethod("StartForcedStayTimer", (BindingFlags.NonPublic |
                                                                                      BindingFlags.Public |
                                                                                      BindingFlags.Instance));
            MethodInfo InteractionCheckTimer = type.GetMethod("StartInteractionCheckTimer", (BindingFlags.NonPublic |
                                                                                             BindingFlags.Public |
                                                                                             BindingFlags.Instance));
            MethodInfo TransitionTimer = type.GetMethod("StartTransitionTimer", (BindingFlags.NonPublic |
                                                                                 BindingFlags.Public |
                                                                                 BindingFlags.Instance));

            if (StartForcedStayTimer != null)
            {
                StartForcedStayTimer.Invoke(ToryTime.Instance, null);
            }
            if (InteractionCheckTimer != null)
            {
                InteractionCheckTimer.Invoke(ToryTime.Instance, null);
            }
            if (TransitionTimer != null)
            {
                TransitionTimer.Invoke(ToryTime.Instance, null);
            }

            // Start
            if (FrameworkBehaviour.CanShowLog)
            {
                Debug.Log("[ToryScene] A new tory scene state (" + smb.Name + ") started.");
            }
            Started();

            // Start update coroutines.
            updateCrt      = SceneBehaviour.StartCoroutine(Update());
            fixedUpdateCrt = SceneBehaviour.StartCoroutine(FixedUpdate());
        }
 void End()
 {
     SceneBehaviour.StartCoroutine(EndCoroutine());
 }