IEnumerator FadeOutAndLoad(string sceneName, float animationTime, float waitTime, Action callback = null) { fadeCanvasGroup.alpha = 0; if (loadingText != null) { loadingText.gameObject.SetActive(true); } yield return(this.DoUnscaledTween01(t => { if (music != null) { music.volume = PennerAnimation.CubicEaseOut(t, 0, 1, 1); } fadeCanvasGroup.alpha = PennerAnimation.QuadEaseInOut(t, 0, 1, 1); }, animationTime, () => { callback?.Invoke(); })); fadeCanvasGroup.alpha = 1.0f; if (music != null) { music.volume = 0; } if (waitTime > 0) { yield return(new WaitForSeconds(waitTime)); } SceneManager.LoadScene(sceneName); }
public static IEnumerator EaseOutShake(Transform target, float animationTime, float strength) { Vector3 pivotPosition = target.localPosition; float elapsedTime = 0; while (elapsedTime < animationTime) { Vector3 p = pivotPosition + Random.insideUnitSphere * PennerAnimation.CubicEaseOut( elapsedTime, 0, strength, animationTime); target.localPosition = p; elapsedTime += Time.deltaTime; yield return(0); } target.localPosition = pivotPosition; }
public static IEnumerator CubicSlideInY(RectTransform rt, float targetPosition, float animationTime) { float elapsedTime = 0; float startPosition = rt.anchoredPosition.y; while (elapsedTime < animationTime) { rt.anchoredPosition = new Vector2( rt.anchoredPosition.x, PennerAnimation.CubicEaseOut(elapsedTime, startPosition, targetPosition - startPosition, animationTime) ); elapsedTime += Time.deltaTime; yield return(0); } rt.anchoredPosition = new Vector2( rt.anchoredPosition.x, targetPosition ); }
override public IEnumerator Click() { float elapsedTime = 0; float initScale = 1 + scaleFactor; float tweenTime = animationTime * 3.0f; clickTrigered = false; while (/*currentState == state.Click &&*/ elapsedTime < tweenTime) { float s = PennerAnimation.CubicEaseOut(elapsedTime, initScale, -scaleFactor, tweenTime); transform.localScale = pivotScale * s; elapsedTime += Time.unscaledDeltaTime; //elastic out is a bit slow to finish, we force click here. if (elapsedTime > tweenTime * 0.35f) { TrigerClick(); } yield return(0); } transform.localScale = pivotScale; ChangeState(state.Idle); }