IEnumerator ChangeNumberAnimation(int targetNumber, float numberDuration, string extraTextInFront = "", string extraTextInEnd = "", float delay = 0) { if (delay != 0) { yield return(new WaitForSeconds(delay)); } int startNumber; if (!int.TryParse(textComponent.text, out startNumber)) { startNumber = 0; } float progress = 0; float v = 1f / numberDuration; int lastNumber = startNumber; while (progress <= 1) { progress += v * Time.deltaTime; float easedValue = EaseUtility.EasedLerp(startNumber, targetNumber, progress, numberEaseType); int tmp = Mathf.FloorToInt(easedValue); if (lastNumber != tmp) { lastNumber = tmp; SetTextAnimation(extraTextInFront + lastNumber.ToString() + extraTextInEnd); } yield return(null); } SetTextAnimation(extraTextInFront + targetNumber.ToString() + extraTextInEnd); }
public static float Lerp(float from, float to, float time, float duration, EaseUtility.Ease easeType) { float t = EaseUtility.EaseConstant(easeType, time, duration); t = Mathf.Clamp01(t); return(from + (to - from) * t); }
void SetTextLerpView(float param) { float ease = EaseUtility.EasedLerp(0, 1, param, animationEaseType); if (scaleTarget == ScaleTarget.Self) { textComponent.transform.localScale = Vector3.LerpUnclamped(startScale, Vector3.one, ease); } else { textComponent.transform.parent.localScale = Vector3.LerpUnclamped(startScale, Vector3.one, ease); } Color c = initShadowColor; if (isChangeOpacity) { textComponent.color = new Color(textComponent.color.r, textComponent.color.g, textComponent.color.b, ease); if (isHasShadow) { shadow.effectColor = new Color(c.r, c.g, c.b, Mathf.Lerp(0, c.a, param)); } } else { textComponent.color = new Color(textComponent.color.r, textComponent.color.g, textComponent.color.b, 1); if (isHasShadow) { shadow.effectColor = new Color(c.r, c.g, c.b, Mathf.Lerp(0, c.a, 1)); } } }
IEnumerator Shaking(Transform _transform, Vector3 magnetude, float duration, float motion, bool isSexy = false, bool isIgnoreTimeScale = false, EaseStyle easeStyle = EaseStyle.QuadEaseOut) { float lifeTime = duration; float age = lifeTime; Vector3 offset = Vector3.zero; Vector2 seedX = Vector2Extension.RandomInSqaure * 10f; Vector2 seedY = Vector2Extension.RandomInSqaure * 10f; Vector2 seedZ = Vector2Extension.RandomInSqaure * 10f; Vector2 motionVectX = Vector2Extension.RandomOnCircle * motion; Vector2 motionVectY = Vector2Extension.RandomOnCircle * motion; Vector2 motionVectZ = Vector2Extension.RandomOnCircle * motion; while (_transform != null & age > 0) { _transform.position -= offset; float deltaTime = (isIgnoreTimeScale) ? Time.unscaledDeltaTime : Time.deltaTime; age -= deltaTime; float power = (age / lifeTime); power *= EaseUtility.EasedLerp(0f, 1f, power, easeStyle); seedX += ((isSexy) ? motionVectX * power : motionVectX) * deltaTime; seedY += ((isSexy) ? motionVectY * power : motionVectY) * deltaTime; seedZ += ((isSexy) ? motionVectZ * power : motionVectZ) * deltaTime; offset = new Vector3( Mathf.PerlinNoise(seedX.x, seedX.y), Mathf.PerlinNoise(seedY.x, seedY.y), Mathf.PerlinNoise(seedZ.x, seedZ.y)); //***** Center the noise signal ***** offset -= Vector3.one * 0.5f; offset *= 2f; offset *= power; offset = new Vector3( offset.x * magnetude.x, offset.y * magnetude.y, offset.z * magnetude.z); //***** Center the noise signal ***** _transform.position += offset; yield return(null); } if (_transform != null) { _transform.position -= offset; } yield break; }
private void Execute(PalCommand command, double oldDeltaTime, double newDeltaTime, double loop) { bool doesLoop = loop < 10000.0; // arbitrary number if (doesLoop && newDeltaTime > command.End) { oldDeltaTime = ((oldDeltaTime - loop) % (command.End - loop)) + loop; newDeltaTime = ((newDeltaTime - loop) % (command.End - loop)) + loop; } if (command.Start <= newDeltaTime || (command.End < newDeltaTime && command.End >= oldDeltaTime)) { double t; bool hasFinished = command.End < newDeltaTime; if (hasFinished == false) { t = (newDeltaTime - command.Start) * 1.0 / (command.End - command.Start); t = EaseUtility.Calculate(command.Ease, t); } else { t = 1.0; } if (command.InvertedTimer) { t = 1.0 - t; } var parameters = command.Parameters.ToArray(); entries[command.Command].Execute(this, command, t, parameters); if (doesLoop == false && hasFinished == true) { var toBurn = entries[command.Command].Burn(parameters); if (toBurn != null) { for (int i = 0; i < toBurn.Length; i++) { backbuffer[i] = palette[i]; } } } } }
/// <summary> /// 回傳一個可被 yield return 的協程,做一個由 0 至 1 的 tween 並每個 update 去執行 action,float 則是 progress /// </summary> /// <param name="duration"></param> /// <param name="progressAction"></param> /// <param name="easeType"></param> /// <returns></returns> public static YieldInstruction ProgressionTask(float duration, System.Action <float> progressAction, EaseStyle easeType = EaseStyle.Linear) { return(CoroutineManager.instance.StartCoroutine(EaseUtility.To(0, 1, duration, easeType, progressAction, null))); }
public double Get(double x) { return(EaseUtility.Calculate(Ease, x * Speed + FixStep) * Multiplier + Sum); }
public IEnumerator OnLeaveRunner(bool NeedPool = true, bool ignoreTransition = false) { //ViewSystemLog.LogError("OnLeave " + name); if (transition == TransitionType.Animator && hasLoopBool) { animator.SetBool(ButtonAnimationBoolKey, false); } needPool = NeedPool; OnLeaveWorking = true; if (lifeCyclesObjects != null) { foreach (var item in lifeCyclesObjects.ToArray()) { try { item.OnBeforeLeave(); } catch (Exception ex) { ViewSystemLog.LogError(ex.Message, this); } } } if (selfViewElementGroup != null) { selfViewElementGroup.OnLeaveChild(ignoreTransition); } //在試圖 leave 時 如果已經是 disable 的 那就直接把他送回池子 //如果 ignoreTransition 也直接把他送回池子 if (gameObject.activeSelf == false || ignoreTransition) { goto END; } if (transition == TransitionType.Animator) { try { if (animatorTransitionType == AnimatorTransitionType.Direct) { if (animator.HasState(0, Animator.StringToHash(AnimationStateName_Out))) { animator.Play(AnimationStateName_Out); } else { animator.Play("Disable"); } } else { animator.ResetTrigger(AnimationStateName_Out); animator.SetTrigger(AnimationStateName_Out); } } catch { goto END; } } else if (transition == TransitionType.CanvasGroupAlpha) { if (canvasGroup == null) { ViewSystemLog.LogError("No Canvas Group Found on this Object", this); } if (canvasGroupCoroutine != null) { viewController.StopMicroCoroutine(canvasGroupCoroutine); } // canvasGroupCoroutine = viewController.StartMicroCoroutine(EaseMethods.EaseValue( // canvasGroup.alpha, // 0, // canvasOutTime, // EaseMethods.GetEase(canvasOutEase), // (v) => // { // canvasGroup.alpha = v; // }, // () => // { // canvasGroupCoroutine = null; // } // )); canvasGroupCoroutine = viewController.StartMicroCoroutine( EaseUtility.To( canvasGroup.alpha, 0, canvasOutTime, canvasOutEase, (v) => { canvasGroup.alpha = v; }, () => { canvasGroupCoroutine = null; } ) ); goto END; } else if (transition == TransitionType.Custom) { OnLeaveHandle.Invoke(OnLeaveAnimationFinish); } else { goto END; } END: if (!ignoreTransition && !isSkipOutAnimation) { float time = 0; var outDuration = GetOutDuration(); while (time < outDuration) { time += GlobalTimer.deltaTime; yield return(null); } } if (lifeCyclesObjects != null) { foreach (var item in lifeCyclesObjects.ToArray()) { try { item.OnStartLeave(); } catch (Exception ex) { ViewSystemLog.LogError(ex.Message, this); } } } leaveCoroutine = null; OnLeaveAnimationFinish(); // }); }
public IEnumerator OnShowRunner(bool manual) { IsShowed = true; if (lifeCyclesObjects != null) { foreach (var item in lifeCyclesObjects.ToArray()) { try { item.OnBeforeShow(); } catch (Exception ex) { ViewSystemLog.LogError(ex.ToString(), this); } } } SetActive(true); if (selfViewElementGroup != null) { if (selfViewElementGroup.OnlyManualMode && manual == false) { if (gameObject.activeSelf) { SetActive(false); } goto END; } selfViewElementGroup.OnShowChild(); } if (transition == TransitionType.Animator) { animator.Play(AnimationStateName_In); if (transition == TransitionType.Animator && hasLoopBool) { animator.SetBool(ButtonAnimationBoolKey, true); } } else if (transition == TransitionType.CanvasGroupAlpha) { canvasGroup.alpha = 0; if (canvasGroupCoroutine != null) { viewController.StopMicroCoroutine(canvasGroupCoroutine); } // canvasGroupCoroutine = viewController.StartMicroCoroutine(EaseMethods.EaseValue( // canvasGroup.alpha, // 1, // canvasInTime, // EaseMethods.GetEase(canvasInEase), // (v) => // { // canvasGroup.alpha = v; // }, // () => // { // canvasGroupCoroutine = null; // } // )); canvasGroupCoroutine = viewController.StartMicroCoroutine( EaseUtility.To( canvasGroup.alpha, 1, canvasInTime, canvasInEase, (v) => { canvasGroup.alpha = v; }, () => { canvasGroupCoroutine = null; } ) ); } else if (transition == TransitionType.Custom) { OnShowHandle.Invoke(null); } END: if (lifeCyclesObjects != null) { foreach (var item in lifeCyclesObjects.ToArray()) { try { item.OnStartShow(); } catch (Exception ex) { ViewSystemLog.LogError(ex.ToString(), this); } } } if (_allGraphics != null) { for (int i = 0; i < _allGraphics.Length; i++) { if (_allGraphics[i].raycastTarget == false) { GraphicRegistry.UnregisterGraphicForCanvas(_allGraphics[i].canvas, _allGraphics[i]); } } } showCoroutine = null; yield break; }
public IEnumerator OnChangePageRunner(bool show, Transform parent, ViewElementTransform rectTransformData, float TweenTime, float delayIn, bool ignoreTransition, bool reshowIfSamePage) { if (lifeCyclesObjects != null) { foreach (var item in lifeCyclesObjects.ToArray()) { try { item.OnChangePage(show); } catch (Exception ex) { ViewSystemLog.LogError(ex.ToString(), this); } } } if (show) { if (parent == null) { ViewSystemLog.LogError($"{gameObject.name} does not set the parent for next viewpage.", this); goto END; //throw new NullReferenceException(gameObject.name + " does not set the parent for next viewpage."); } //停掉正在播放的 Leave 動畫 if (leaveCoroutine != null) { // viewController.StopCoroutine(OnLeaveCoroutine); } //還在池子裡,應該先 OnShow //或是正在離開,都要重播 OnShow if (IsShowed == false || OnLeaveWorking) { rectTransform.SetParent(parent, true); if (rectTransformData == null || !string.IsNullOrEmpty(rectTransformData.parentPath)) { rectTransform.anchoredPosition3D = Vector3.zero; rectTransform.localScale = Vector3.one; } else { ApplyRectTransform(rectTransformData); } float time = 0; while (time < delayIn) { time += GlobalTimer.deltaTime; yield return(null); } OnShow(); goto END; } //已經在場上的 else { //如果目前的 parent 跟目標的 parent 是同一個人 那就什麼事都不錯 if ((rectTransformData == null || !string.IsNullOrEmpty(rectTransformData.parentPath)) && parent.GetInstanceID() == rectTransform.parent.GetInstanceID()) { //ViewSystemLog.LogWarning("Due to already set the same parent with target parent, ignore " + name); if (reshowIfSamePage) { OnShow(); } goto END; } //其他的情況下用 Tween 過去 if (TweenTime >= 0) { rectTransform.SetParent(parent, true); if (rectTransformData == null || !string.IsNullOrEmpty(rectTransformData.parentPath)) { var marginFixer = GetComponent <ViewMarginFixer>(); viewController.StartMicroCoroutine(EaseUtility.To( rectTransform.anchoredPosition3D, Vector3.zero, TweenTime, EaseStyle.QuadEaseOut, (v) => { rectTransform.anchoredPosition3D = v; }, () => { if (marginFixer) { marginFixer.ApplyModifyValue(); } } )); viewController.StartMicroCoroutine(EaseUtility.To( rectTransform.localScale, Vector3.one, TweenTime, EaseStyle.QuadEaseOut, (v) => { rectTransform.localScale = v; } )); } else { rectTransform.SetParent(parent, true); var flag = rectTransformData.rectTransformFlag; FlagsHelper.Unset(ref flag, RectTransformFlag.AnchoredPosition); FlagsHelper.Unset(ref flag, RectTransformFlag.LocalScale); ApplyRectTransform(rectTransformData, flag); viewController.StartMicroCoroutine(EaseUtility.To( rectTransform.anchoredPosition3D, rectTransformData.rectTransformData.anchoredPosition, TweenTime, EaseStyle.QuadEaseOut, (v) => { rectTransform.anchoredPosition3D = v; }, () => { } )); viewController.StartMicroCoroutine(EaseUtility.To( rectTransform.localScale, rectTransformData.rectTransformData.localScale, TweenTime, EaseStyle.QuadEaseOut, (v) => { rectTransform.localScale = v; }, () => { } )); } goto END; } //TweenTime 設定為 <0 的情況下,代表要完整 OnLeave 在 OnShow else { float time = 0; while (time < delayIn) { time += GlobalTimer.deltaTime; yield return(null); } OnLeave(ignoreTransition: ignoreTransition); while (OnLeaveWorking == true) { yield return(null); } ViewSystemLog.LogWarning("Try to ReShow ", this); rectTransform.SetParent(parent, true); if (rectTransformData == null || !string.IsNullOrEmpty(rectTransformData.parentPath)) { rectTransform.anchoredPosition3D = Vector3.zero; rectTransform.localScale = Vector3.one; } else { ApplyRectTransform(rectTransformData); } time = 0; while (time < delayIn) { time += GlobalTimer.deltaTime; yield return(null); } OnShow(); goto END; } } } else { OnLeave(ignoreTransition: ignoreTransition); goto END; } END: changePageCoroutine = null; yield break; }