コード例 #1
0
 private IEnumerator DisableAfterAnimation()
 {
     if (animator != null)
     {
         const float maxWaitDuration = 10;
         float       timeout         = Time.realtimeSinceStartup + maxWaitDuration;
         var         oldHashId       = UITools.GetAnimatorNameHash(animator.GetCurrentAnimatorStateInfo(0));
         while ((UITools.GetAnimatorNameHash(animator.GetCurrentAnimatorStateInfo(0)) == oldHashId) && (Time.realtimeSinceStartup < timeout))
         {
             yield return(null);
         }
         yield return(new WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length));
     }
     base.SetActive(false);
     if (panel != null)
     {
         Tools.SetGameObjectActive(panel, false);
     }
 }
コード例 #2
0
 private IEnumerator DisableAfterAnimation(UnityEngine.UI.Graphic panel)
 {
     isHiding = true;
     if (animator != null)
     {
         const float maxWaitDuration = 10;
         float       timeout         = Time.realtimeSinceStartup + maxWaitDuration;
         var         oldHashId       = UITools.GetAnimatorNameHash(animator.GetCurrentAnimatorStateInfo(0));
         while ((UITools.GetAnimatorNameHash(animator.GetCurrentAnimatorStateInfo(0)) == oldHashId) && (Time.realtimeSinceStartup < timeout))
         {
             yield return(null);
         }
         yield return(DialogueManager.Instance.StartCoroutine(DialogueTime.WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length)));
     }
     isHiding = false;
     if (panel != null)
     {
         Tools.SetGameObjectActive(panel, false);
     }
 }
コード例 #3
0
 private IEnumerator DisableAfterAnimation(UnityEngine.UI.Graphic panel)
 {
     if (animator != null)
     {
         const float maxWaitDuration = 10;
         float       timeout         = Time.realtimeSinceStartup + maxWaitDuration;
         var         oldHashId       = UITools.GetAnimatorNameHash(animator.GetCurrentAnimatorStateInfo(0));
         while ((UITools.GetAnimatorNameHash(animator.GetCurrentAnimatorStateInfo(0)) == oldHashId) && (Time.realtimeSinceStartup < timeout))
         {
             yield return(null);
         }
         yield return(new WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length));
     }
                 #if !UNITY_WEBPLAYER
     base.SetActive(false);             // Can't call base virtual methods in webplayer.
                 #endif
     if (panel != null)
     {
         Tools.SetGameObjectActive(panel, false);
     }
 }
コード例 #4
0
 private IEnumerator CloseAfterAnimation(Action closedWindowHandler)
 {
     if (animator != null)
     {
         if (pauseWhileOpen)
         {
             Time.timeScale = 1;
         }
         animator.SetTrigger(animationTransitions.hideTrigger);
         const float maxWaitDuration = 10;
         float       timeout         = Time.realtimeSinceStartup + maxWaitDuration;
         var         oldHashId       = UITools.GetAnimatorNameHash(animator.GetCurrentAnimatorStateInfo(0));
         while ((UITools.GetAnimatorNameHash(animator.GetCurrentAnimatorStateInfo(0)) == oldHashId) && (Time.realtimeSinceStartup < timeout))
         {
             yield return(null);
         }
         yield return(new WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length));
     }
     Tools.SetGameObjectActive(mainPanel, false);
     closedWindowHandler();
 }
コード例 #5
0
        private IEnumerator WaitForAnimation(string triggerName, float newTimeScale, bool panelActive, bool wait, System.Action callback)
        {
            if (panelActive)
            {
                Tools.SetGameObjectActive(panel, true);
            }
            if (CanTriggerAnimation(triggerName))
            {
                CheckAnimatorModeAndTimescale(triggerName); //---Was: Time.timeScale = 1; // Can't guarantee animator is set to Unscaled, so unpause to play.
                animator.SetTrigger(triggerName);
                const float maxWaitDuration = 10;
                float       timeout         = Time.realtimeSinceStartup + maxWaitDuration;
                var         goalHashID      = Animator.StringToHash(triggerName);
                var         oldHashId       = UITools.GetAnimatorNameHash(animator.GetCurrentAnimatorStateInfo(0));
                var         currentHashID   = oldHashId;
                if (wait && !Mathf.Approximately(0, Time.timeScale))
                {
                    while ((currentHashID != goalHashID) && (currentHashID == oldHashId) && (Time.realtimeSinceStartup < timeout))
                    {
                        yield return(null);

                        currentHashID = UITools.GetAnimatorNameHash(animator.GetCurrentAnimatorStateInfo(0));
                    }
                    yield return(new WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length));
                }
            }
            if (!panelActive)
            {
                Tools.SetGameObjectActive(panel, false);
            }
            Time.timeScale = newTimeScale;
            animCoroutine  = null;
            if (callback != null)
            {
                callback.Invoke();
            }
        }
コード例 #6
0
        private IEnumerator WaitForAnimationTrigger(string triggerName, bool pauseAfterAnimation, bool panelActive, bool wait, System.Action callback)
        {
            if (panelActive)
            {
                if (panel != null && !panel.gameObject.activeSelf)
                {
                    panel.gameObject.SetActive(true);
                    yield return(null);
                }
            }
            if (CanTriggerAnimation(triggerName) && animator.gameObject.activeSelf)
            {
                CheckAnimatorModeAndTimescale(triggerName);
                float timeout       = Time.realtimeSinceStartup + maxWaitDuration;
                var   goalHashID    = Animator.StringToHash(triggerName);
                var   oldHashId     = UITools.GetAnimatorNameHash(animator.GetCurrentAnimatorStateInfo(0));
                var   currentHashID = oldHashId;
                animator.SetTrigger(triggerName);
                if (wait)
                {
                    // Wait while we're not at the goal state and we're in the original state and we haven't timed out:
                    while ((currentHashID != goalHashID) && (currentHashID == oldHashId) && (Time.realtimeSinceStartup < timeout))
                    {
                        yield return(null);

                        var isAnimatorValid = animator != null && animator.isActiveAndEnabled && animator.runtimeAnimatorController != null && animator.layerCount > 0;
                        currentHashID = isAnimatorValid ? UITools.GetAnimatorNameHash(animator.GetCurrentAnimatorStateInfo(0)) : currentHashID;
                    }
                    // If we're in the goal state and we haven't timed out, wait for the duration of the goal state:
                    if (currentHashID == goalHashID && Time.realtimeSinceStartup < timeout)
                    {
                        var clipLength = animator.GetCurrentAnimatorStateInfo(0).length;
                        if (Mathf.Approximately(0, Time.timeScale))
                        {
                            timeout = Time.realtimeSinceStartup + clipLength;
                            while (Time.realtimeSinceStartup < timeout)
                            {
                                yield return(null);
                            }
                        }
                        else
                        {
                            yield return(new WaitForSeconds(clipLength));
                        }
                    }
                }
            }
            if (!panelActive)
            {
                Tools.SetGameObjectActive(panel, false);
            }
            if (pauseAfterAnimation)
            {
                Time.timeScale = 0;
            }
            animCoroutine = null;
            if (callback != null)
            {
                callback.Invoke();
            }
        }