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());
        }
        IEnumerator EndCoroutine()
        {
            // Check if this scene is already ended.
            if (!playing)
            {
                yield break;
            }
            playing = false;

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

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

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

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

            // Wait a frame.
            yield return(null);

            // Load a new scene or restart the current scene
            if (CanLoadUnityScene)
            {
                SceneManager.LoadScene(UnitySceneIndex);
            }
            else
            {
                Start();
            }
        }
Beispiel #3
0
 public SceneBehaviour SceneBehaviour()
 {
     if (!_sceneBehaviour)
     {
         var temp = GameObject.FindGameObjectWithTag("SceneBehaviour");
         if (temp)
         {
             _sceneBehaviour = temp.GetComponent <SceneBehaviour>();
         }
         else
         {
             _sceneBehaviour = Instantiate(sceneBehaviourPrefab, Vector3.zero, Quaternion.identity);
         }
     }
     return(_sceneBehaviour);
 }
Beispiel #4
0
    // Use this for initialization
    private void Start()
    {
        scenePolygon      = new GameObject();
        scenePolygon.name = this.name + " polygon";
        sceneBehaviour    = FindObjectOfType <SceneBehaviour> ();
        Polygon pol = new Polygon(this, userTops);

        bool hasKernel = pol.HaveKernel();

        SetKernelText(hasKernel);

        if (hasKernel)
        {
            pol.calculateCircuit();
        }
        else
        {
            SetCircuitText(-1);
            SetTopsText(-1);
        }
    }
 /// <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 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);
                    }
                }
            }
        }
        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());
        }
Beispiel #10
0
 void Awake()
 {
     instance = this;
 }
 void End()
 {
     SceneBehaviour.StartCoroutine(EndCoroutine());
 }
Beispiel #12
0
 private void Start()
 {
     sceneBehaviour = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <SceneBehaviour>();
 }
Beispiel #13
0
 private void Start()
 {
     sceneBehaviour = camera.gameObject.GetComponent <SceneBehaviour>();
     maxSpeed       = speed;
 }