Ejemplo n.º 1
0
    /// <summary>
    /// Hide this menu screen
    /// </summary>
    public virtual void Hide(float fade, TransitionDirection direction = TransitionDirection.Back, SimpleTween.Callback callback = null)
    {
        // cancel any running tweens in case we are leaving this menu immediately after having opened it.
        SimpleTweener.RemoveTween(alphaTween);
        SimpleTweener.RemoveTween(posTween);

        if (fade == 0.0f)
        {
            canvasGroup.alpha = 0.0f;

            // deactivate this gameobject when the screen is not visible
            gameObject.SetActive(false);

            if (callback != null)
            {
                callback();
            }
        }
        else
        {
            // fade out the canvas group, then disable the gameobject once it's invisible
            alphaTween = SimpleTweener.AddTween(() => CanvasGroup.alpha, x => CanvasGroup.alpha = x, 0.0f, fade).UseRealTime(true).OnCompleted(() => {
                gameObject.SetActive(false);
                if (callback != null)
                {
                    callback();
                }
            });
            posTween = SimpleTweener.AddTween(() => Vector2.zero, x => rectXfm.anchoredPosition = x, new Vector2(0, -30), fade).UseRealTime(true);
        }
    }
Ejemplo n.º 2
0
    private void ShowInfoPopup(float duration, float fadeTime)
    {
        // if we're still showing a previous message, then cancel the previous tweens
        if (isShowing)
        {
            SimpleTweener.RemoveTween(alphaTween);
            SimpleTweener.RemoveTween(positionTween);
        }

        isShowing = true;

        // fade up the alpha, wait for our duration, then fade it out again.
        alphaTween = SimpleTweener.AddTween(() => canvasGroup.alpha, x => canvasGroup.alpha = x, 1.0f, fadeTime).OnCompleted(() => {
            alphaTween = SimpleTweener.AddTween(() => canvasGroup.alpha, x => canvasGroup.alpha = x, 0.0f, fadeTime).Delay(duration).OnCompleted(() => {
                // the popup has now disappeared
                isShowing = false;
            });
        });

        // also animate the x-position in a similar fashion.
        RectTransform rect     = GetComponent <RectTransform>();
        Vector2       startPos = rect.anchoredPosition;

        startPos.x            = 200.0f;
        rect.anchoredPosition = startPos;
        positionTween         = SimpleTweener.AddTween(() => rect.anchoredPosition, x => rect.anchoredPosition = x, new Vector2(30, startPos.y), fadeTime).Ease(Easing.EaseLinear).OnCompleted(() => {
            positionTween = SimpleTweener.AddTween(() => rect.anchoredPosition, x => rect.anchoredPosition = x, new Vector2(-30, startPos.y), duration).Ease(Easing.EaseLinear).OnCompleted(() => {
                positionTween = SimpleTweener.AddTween(() => rect.anchoredPosition, x => rect.anchoredPosition = x, new Vector2(-200, startPos.y), fadeTime).Ease(Easing.EaseLinear);
            });
        });
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Show this menu screen.
    /// </summary>
    /// <param name="fade">Transition time</param>
    /// <param name="direction">Direction - Back if we are returning from a sub-menu, Forward otherwise</param>
    /// <param name="callback">Callback to call once the transition is finished</param>
    public virtual void Show(float fade, TransitionDirection direction = TransitionDirection.Forward, SimpleTween.Callback callback = null)
    {
        gameObject.SetActive(true);

        // cancel any running tweens in case we are returning to this menu immediately after having left it.
        SimpleTweener.RemoveTween(alphaTween);
        SimpleTweener.RemoveTween(posTween);

        if (fade == 0.0f)
        {
            canvasGroup.alpha = 1.0f;
            if (callback != null)
            {
                callback();
            }
        }
        else
        {
            // animate the position and alpha of the screen
            alphaTween = SimpleTweener.AddTween(() => CanvasGroup.alpha, x => CanvasGroup.alpha = x, 1.0f, fade).OnCompleted(callback).UseRealTime(true);
            posTween   = SimpleTweener.AddTween(() => new Vector2(0, -30), x => rectXfm.anchoredPosition = x, Vector2.zero, fade).UseRealTime(true);
        }

        // set our default UI item so it has focus.
        EventSystem.current.SetSelectedGameObject(defaultUIItem);
    }
Ejemplo n.º 4
0
 public override void Cancel()
 {
     // to avoid conficts (if e.g. we collected a slowmotion powerup while this powerup is still running), we have
     // to remove our tween and reset the player's speed if another powerup is collected.
     if (tween != null)
     {
         SimpleTweener.RemoveTween(tween);
         GameManager.Player.SpeedMultiplier = 1.0f;
         tween = null;
     }
 }
Ejemplo n.º 5
0
    /// <summary>
    /// Show a message along with a countdown
    /// </summary>
    /// <param name="message">The message to display</param>
    /// <param name="duration">The duration to display it for (also the duration of the countdown)</param>
    /// <param name="fadeTime">The transition in/out time.</param>
    public void ShowCountdown(string message, float duration, float fadeTime)
    {
        // if we are still showing a previous countdown, then cancel the previous tween
        if (isShowing)
        {
            SimpleTweener.RemoveTween(countdownTween);
        }

        // set the message text
        text.text = message;
        // make the countdown graphic visible
        countdown.alpha = 1.0f;

        // animate the countdown progress by scaling the progress graphic
        countdownTween = SimpleTweener.AddTween(() => Vector3.one, x => countdownProgress.localScale = x, new Vector3(0.0f, 1.0f, 1.0f), duration).Delay(fadeTime).Ease(Easing.EaseLinear);
        // animate the whole info panel
        ShowInfoPopup(duration, fadeTime);
    }