Beispiel #1
0
 public void open(TransitionCallBack endCallback = null, float time = -1)
 {
     if (!isClosed || currentTarget == 0)
     {
         return;
     }
     if (time < 0)
     {
         time = this.time;
     }
     if (currentCoroutine != null)
     {
         StopCoroutine(currentCoroutine);
     }
     transitionEndCallback = endCallback;
     StartCoroutine(FadeCanvasGroup(canvasElement, canvasElement.alpha, 0, time));
 }
Beispiel #2
0
    // Use this for initialization
    public IEnumerator FadeCanvasGroup(CanvasGroup cg, float start, float end, float time = 0.5f)
    {
        float velocity = 0.05f;

        transform.hideFlags = HideFlags.None;
        cg.alpha            = start;
        currentTarget       = end;
        while (true)
        {
            time -= Time.smoothDeltaTime;
            if (time <= 0)
            {
                cg.alpha = end;
                break;
            }

            cg.alpha = Mathf.SmoothDamp(cg.alpha, end, ref velocity, time, Mathf.Infinity, Time.smoothDeltaTime);

            yield return(new WaitForEndOfFrame());
        }
        if (cg.alpha <= 0)
        {
            transform.hideFlags = HideFlags.HideInHierarchy;
            isClosed            = false;
        }
        else
        {
            isClosed = true;
        }
        currentCoroutine = null;
        currentTarget    = -1;
        if (transitionEndCallback != null)
        {
            transitionEndCallback();
        }
        transitionEndCallback = null;
    }
Beispiel #3
0
 /**
  * @param cback : a callback function that determines if can transition</param>
  * @param dest : a destination state for next transition</param>
  */
 public StateTransition(TransitionCallBack cback, GameState dest)
 {
     callback         = cback;
     destinationState = dest;
 }