public bool InputEnabled(VOGStateBase state)
 {
     return (_InputEnabled >= 0) && (state == StateStack.Peek());
 }
    private IEnumerator RunTransition(VOGStateBase from, VOGStateBase to, TransitionDirection direction, object data)
    {
        if (Listener == null)
        {
            var cam = Camera.main;
            if (cam == null)
            {
                cam = (Camera)GameObject.FindObjectOfType(typeof(Camera));
            }
            Listener = cam.GetComponent<AudioListener>();
            if (Listener == null)
            {
                Listener = cam.gameObject.AddComponent<AudioListener>();
            }
        }
        if (Listener != null)
        {
            var source = Listener.audio;
            if (source == null)
            {
                source = Listener.gameObject.AddComponent<AudioSource>();
            }
            source.PlayOneShot(TransitionAudioClip, TransitionAudioVolume);
        }

        //Debug.Log("From " + from + " to " + to);
        VisibleState visibleFrom = CreateVisibleState(from);
        VisibleState visibleTo = CreateVisibleState(to);

        //enable to-state
        if (to != null)
        {
            try
            {
                if (data != null)
                {
                    to.OnDataChanged(data);
                }
                to.OnStateEnable(this);
            }
            catch (System.Exception ex)
            {
                Debug.LogError("Error while disabling state, " + ex.ToString());
            }
        }

        System.Action<float> updatePosition = (prog) =>
        {
            visibleFrom.TransitionProgress = visibleTo.TransitionProgress = prog;

            if (direction == TransitionDirection.Forward)
            {
                visibleFrom.Position = Matrix4x4.TRS(new Vector3(-Screen.width * prog, 0), Quaternion.identity, Vector3.one);
                visibleTo.Position = Matrix4x4.TRS(new Vector3(Screen.width * (1 - prog), 0), Quaternion.identity, Vector3.one);
            }
            else if (direction == TransitionDirection.Backward)
            {
                visibleFrom.Position = Matrix4x4.TRS(new Vector3(Screen.width * prog, 0), Quaternion.identity, Vector3.one);
                visibleTo.Position = Matrix4x4.TRS(new Vector3(-Screen.width * (1 - prog), 0), Quaternion.identity, Vector3.one);
            }
            else if (direction == TransitionDirection.Over)
            {
                visibleFrom.Position = Matrix4x4.TRS(new Vector3(0, Screen.width * prog, 0), Quaternion.identity, Vector3.one);
                visibleTo.Position = Matrix4x4.TRS(new Vector3(0, -Screen.width * (1 - prog), 0), Quaternion.identity, Vector3.one);
            }
        };

        //Run Transition
        _IsTransition = true;
        DisableInput();

        float startTime = Time.realtimeSinceStartup;
        float progress = 0;
        while (Time.realtimeSinceStartup - startTime < TransitionDuration)
        {
            progress = (Time.realtimeSinceStartup - startTime) / TransitionDuration;
            updatePosition(progress);

            yield return null;
        }

        //Force last frame with progress = 1
        updatePosition(1);
        yield return null;

        EnableInput();
        _IsTransition = false;

        //Disable from state
        if (from != null)
        {
            try
            {
                from.OnStateDisable(this);
            }
            catch (System.Exception ex)
            {
                Debug.LogError("Error while disabling state, " + ex.ToString());
            }
            VisibleStates.Remove(visibleFrom);
        }
    }
 private VisibleState FindVisibleState(VOGStateBase state)
 {
     return VisibleStates.Find(s => s.State == state);
 }
 private VisibleState CreateVisibleState(VOGStateBase state)
 {
     VisibleState visibleState = VisibleStates.Find(s => s.State == state);
     if (visibleState == null)
     {
         visibleState = new VisibleState()
         {
             State = state,
         };
         if (state != null)
         {
             VisibleStates.Add(visibleState);
         }
     }
     return visibleState;
 }
 public void StartTransition(VOGStateBase to, object data = null)
 {
     VOGStateBase from = null;
     from = StateStack.Count > 0 ? StateStack.Peek() : null;
     StateStack.Push(to);
     StartCoroutine(RunTransition(from, to, TransitionDirection.Forward, data));
 }
 public void StartOverTransition(VOGStateBase to, object data = null)
 {
     StateStack.Push(to);
     StartCoroutine(RunTransition(null, to, TransitionDirection.Over, data));
 }