예제 #1
0
 private void ScreenFaderFadeIn(float time, SimpleTween.Callback onCompletedCB)
 {
     // fade the screen to white
     screenFade.gameObject.SetActive(true);
     screenFade.alpha = 0.0f;
     SimpleTweener.AddTween(() => screenFade.alpha, x => screenFade.alpha = x, 1.0f, time).OnCompleted(onCompletedCB);
 }
예제 #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);
            });
        });
    }
예제 #3
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);
        }
    }
예제 #4
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);
    }
예제 #5
0
    public void Hide()
    {
        // slide off
        RectTransform rect = canvasGroup.GetComponent <RectTransform>();

        SimpleTweener.AddTween(() => Vector2.zero, x => rect.anchoredPosition  = x, new Vector2(-80, 0), 0.5f).Ease(Easing.EaseIn);
        SimpleTweener.AddTween(() => canvasGroup.alpha, x => canvasGroup.alpha = x, 0.0f, 0.5f).Ease(Easing.EaseIn);
    }
예제 #6
0
    public void Show()
    {
        // slide on
        RectTransform rect = canvasGroup.GetComponent <RectTransform>();

        SimpleTweener.AddTween(() => new Vector2(-80, 0), x => rect.anchoredPosition = x, Vector2.zero, 0.5f);
        SimpleTweener.AddTween(() => canvasGroup.alpha, x => canvasGroup.alpha       = x, 1.0f, 0.5f);
    }
예제 #7
0
 private void ScreenFaderFadeOut(float time)
 {
     // fade out the white overlay
     if (screenFade.gameObject.activeSelf)
     {
         SimpleTweener.AddTween(() => screenFade.alpha, x => screenFade.alpha = x, 0.0f, time).OnCompleted(() => screenFade.gameObject.SetActive(false));
     }
 }
예제 #8
0
    public void OnNewRecord()
    {
        // give a little visual kick to the distance labels
        RectTransform distRect   = distanceText.GetComponent <RectTransform>();
        RectTransform recordRect = recordText.GetComponent <RectTransform>();

        SimpleTweener.AddTween(() => distRect.localScale, x => distRect.localScale     = x, 1.5f * Vector3.one, 0.5f).Ease(Easing.EaseKick);
        SimpleTweener.AddTween(() => recordRect.localScale, x => recordRect.localScale = x, 1.5f * Vector3.one, 0.5f).Delay(0.1f).Ease(Easing.EaseKick);
    }
예제 #9
0
 private IEnumerator BlinkToggle()
 {
     while (true)
     {
         SimpleTweener.AddTween(() => transform.localScale, x => transform.localScale = x, 1.1f * Vector3.one, 0.3f).Ease(Easing.EaseKick).OnCompleted(() => {
             transform.localScale = Vector3.one;
         });
         yield return(new WaitForSecondsRealtime(1f));
     }
 }
예제 #10
0
    public override void Show(float fade, TransitionDirection direction, SimpleTween.Callback callback)
    {
        // don't animate the elements if we're returning to this screen from a submenu.
        if (direction == TransitionDirection.Forward)
        {
            // get the distance and credits values.
            float distance    = GameManager.LevelManager.TotalDistance;
            float record      = GameManager.RecordDistance;
            int   creditScore = GameManager.CreditsThisRace;

            if (distance == record)
            {
                // this is a new record, so show the newRecordScreen elements
                normalScreen.alpha    = 0.0f;
                newRecordScreen.alpha = 1.0f;

                // animate the distance text up from 0, then kick the scale at the end for effect.
                SimpleTweener.AddTween(() => 0, x => newRecordText.text = Mathf.CeilToInt(x).ToString() + "m", record, 0.5f).Delay(0.2f).OnCompleted(() => {
                    KickItem(newRecordText.transform, 1.5f, 0.5f);
                });
                SimpleTweener.AddTween(() => 0, x => creditScoreText.text = "+" + x, creditScore, 0.5f).Delay(0.7f).OnCompleted(() => {
                    KickItem(creditScoreText.transform, 1.5f, 0.3f);
                });
            }
            else
            {
                // no new record, so show the normalScreen elements
                normalScreen.alpha    = 1.0f;
                newRecordScreen.alpha = 0.0f;

                // animate the text up from 0, then kick the scale at the end for effect.
                SimpleTweener.AddTween(() => 0, x => distanceText.text = Mathf.CeilToInt(x).ToString() + "m", distance, 0.5f).Delay(0.2f).OnCompleted(() => {
                    KickItem(distanceText.transform, 1.5f, 0.3f);
                });
                SimpleTweener.AddTween(() => 0, x => oldRecordText.text = Mathf.CeilToInt(x).ToString() + "m", record, 0.5f).Delay(0.5f).OnCompleted(() => {
                    KickItem(oldRecordText.transform, 1.5f, 0.3f);
                });
                SimpleTweener.AddTween(() => 0, x => creditScoreText.text = "+" + x, creditScore, 0.5f).Delay(1.0f).OnCompleted(() => {
                    KickItem(creditScoreText.transform, 1.5f, 0.3f);
                });
            }
        }

        base.Show(fade, direction, callback);
    }
예제 #11
0
    public override void ApplyPowerup()
    {
        // display a powerup message on screen
        string msg = infoText + " +" + creditBonus;

        GameManager.ShowCountdown(msg, boostTime, fadeInTime);
        // award the player some credits
        GameManager.AwardCredits(creditBonus);

        // animate up the speed of the player, wait for our duration, then animate it back down again.
        PlayerControl player = GameManager.Player;

        tween = SimpleTweener.AddTween(() => player.SpeedMultiplier, x => player.SpeedMultiplier = x, boostAmount, fadeInTime).OnCompleted(() => {
            tween = SimpleTweener.AddTween(() => player.SpeedMultiplier, x => player.SpeedMultiplier = x, 1.0f, fadeOutTime).Delay(boostTime).OnCompleted(() => {
                PowerupManager.OnPowerupCompleted(this);
            });
        });
    }
예제 #12
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);
    }
예제 #13
0
 private void KickItem(Transform item, float amount, float time)
 {
     // animate the scale of an item to give it a little 'kick'
     SimpleTweener.AddTween(() => item.localScale, x => item.localScale = x, amount * item.localScale, time).Ease(Easing.EaseKick);
 }