public static Tweener DoFillAmount(this Image image, float fillAmount, float duration, float?overrideStartFillAmout = null) { if (image == null) { throw new ArgumentNullException(nameof(image)); } if (fillAmount < 0f) { throw new ArgumentException(nameof(fillAmount)); } else if (fillAmount > 1f) { fillAmount = 1f; } if (duration < 0f) { throw new ArgumentException(nameof(duration)); } TimeTweener tweener = new TimeTweener() { DurationTime = duration, TimeType = TweenerTimeType.ScaleTime, }; tweener.Enumerator = DoFillAmount_Internal(tweener, image, fillAmount, overrideStartFillAmout); return(tweener); }
internal static IEnumerator <Tweener> DoFillAmount_Internal(TimeTweener tweener, Image image, float fillAmount, float?overrideStartFillAmout) { if (!image) { yield return(null); yield break; } float deltaTime = Time.deltaTime; float startFillAmount = overrideStartFillAmout ?? image.fillAmount; tweener.CumulativeTime += deltaTime; image.fillAmount = tweener.Normalized * (fillAmount - startFillAmount) + startFillAmount; while (tweener.Normalized < 1f) { yield return(tweener); if (!image) { yield return(null); yield break; } deltaTime = Time.deltaTime; tweener.CumulativeTime += deltaTime; image.fillAmount = tweener.Normalized * (fillAmount - startFillAmount) + startFillAmount; } }
internal static IEnumerator <Tweener> DoColor_Internal(TimeTweener tweener, Graphic graphic, Color targetColor, Color?overrideStartColor) { if (!graphic) { yield return(null); yield break; } float deltaTime = Time.deltaTime; Color startColor = overrideStartColor ?? graphic.color; tweener.CumulativeTime += deltaTime; graphic.color = tweener.Normalized * (targetColor - startColor) + startColor; while (tweener.Normalized < 1f) { yield return(tweener); if (!graphic) { yield return(null); yield break; } deltaTime = Time.deltaTime; tweener.CumulativeTime += deltaTime; graphic.color = tweener.Normalized * (targetColor - startColor) + startColor; } }
internal static IEnumerator <Tweener> DoAnchoredPosition_Internal(TimeTweener tweener, RectTransform rectTransform, Vector2 targetPosition, Vector2?overrideStartAnchoredPosition) { if (!rectTransform) { yield return(null); yield break; } float deltaTime = Time.deltaTime; Vector2 startPosition = overrideStartAnchoredPosition ?? rectTransform.anchoredPosition; tweener.CumulativeTime += deltaTime; rectTransform.anchoredPosition = tweener.Normalized * (targetPosition - startPosition) + startPosition; while (tweener.Normalized < 1f) { yield return(tweener); if (!rectTransform) { yield return(null); yield break; } deltaTime = Time.deltaTime; tweener.CumulativeTime += deltaTime; rectTransform.anchoredPosition = tweener.Normalized * (targetPosition - startPosition) + startPosition; } }
internal static IEnumerator <Tweener> DoPosition_Internal(TimeTweener tweener, Transform transform, Vector3 targetPosition, Vector3?overrideStartPosition) { if (!transform) { yield return(null); yield break; } float deltaTime = Time.deltaTime; Vector3 startPosition = overrideStartPosition ?? transform.position; tweener.CumulativeTime += deltaTime; transform.position = tweener.Normalized * (targetPosition - startPosition) + startPosition; while (tweener.Normalized < 1f) { yield return(tweener); if (!transform) { yield return(null); yield break; } deltaTime = Time.deltaTime; tweener.CumulativeTime += deltaTime; transform.position = tweener.Normalized * (targetPosition - startPosition) + startPosition; } }
internal static IEnumerator <Tweener> DoLocalEuler_Internal(TimeTweener tweener, Transform transform, Vector3 targetEuler, Vector3 startEuler) { if (!transform) { yield return(null); yield break; } float deltaTime = Time.deltaTime; tweener.CumulativeTime += deltaTime; transform.localEulerAngles = tweener.Normalized * (targetEuler - startEuler) + startEuler; while (tweener.Normalized < 1f) { yield return(tweener); if (!transform) { yield return(null); yield break; } deltaTime = Time.deltaTime; tweener.CumulativeTime += deltaTime; transform.localEulerAngles = tweener.Normalized * (targetEuler - startEuler) + startEuler; } }
internal static IEnumerator <Tweener> DoLocalScale_Internal(TimeTweener tweener, Transform transform, Vector3 targetLocalScale, Vector3?overrideStartLocalScale) { if (!transform) { yield return(null); yield break; } float deltaTime = Time.deltaTime; Vector3 startLocalScale = overrideStartLocalScale ?? transform.localScale; tweener.CumulativeTime += deltaTime; transform.localScale = tweener.Normalized * (targetLocalScale - startLocalScale) + startLocalScale; while (tweener.Normalized < 1f) { yield return(tweener); if (!transform) { yield return(null); yield break; } deltaTime = Time.deltaTime; tweener.CumulativeTime += deltaTime; transform.localScale = tweener.Normalized * (targetLocalScale - startLocalScale) + startLocalScale; } }
internal static IEnumerator <Tweener> DoTime_Internal(TimeTweener tweener) { tweener.CumulativeTime += Time.deltaTime; while (tweener.Normalized < 1f) { yield return(tweener); tweener.CumulativeTime += Time.deltaTime; } }
public static Tweener DoUnscaleTime(float duration) { if (duration < 0f) { throw new ArgumentException(nameof(duration)); } TimeTweener tweener = new TimeTweener() { DurationTime = duration, TimeType = TweenerTimeType.UnscaleTime, }; tweener.Enumerator = DoUnscaleTime_Internal(tweener); return(tweener); }
public static Tweener DoColor(this Graphic graphic, Color targetColor, float duration, Color?overrideStartColor = null) { if (graphic == null) { throw new ArgumentNullException(nameof(graphic)); } if (duration < 0f) { throw new ArgumentException(nameof(duration)); } TimeTweener tweener = new TimeTweener() { DurationTime = duration, TimeType = TweenerTimeType.ScaleTime, }; tweener.Enumerator = DoColor_Internal(tweener, graphic, targetColor, overrideStartColor); return(tweener); }
public static Tweener DoAnchoredPosition(this RectTransform rectTransform, Vector3 targetPosition, float duration, Vector2?overrideStartAnchoredPosition = null) { if (rectTransform == null) { throw new ArgumentNullException(nameof(rectTransform)); } if (duration < 0f) { throw new ArgumentException(nameof(duration)); } TimeTweener tweener = new TimeTweener() { DurationTime = duration, TimeType = TweenerTimeType.ScaleTime, }; tweener.Enumerator = DoAnchoredPosition_Internal(tweener, rectTransform, targetPosition, overrideStartAnchoredPosition); return(tweener); }
/// <summary> /// 对一个 Transform 对象创建补间动画实例 /// </summary> /// <param name="transform">执行补间动画的实例</param> /// <param name="targetEuler">结束时欧拉角度</param> /// <param name="duration">旋转持续时间</param> /// <param name="startEuler">因为存在优角劣角问题,不能自行获取起始欧拉角度</param> /// <returns>Tweener 实例</returns> public static Tweener DoLocalEuler(this Transform transform, Vector3 targetEuler, float duration, Vector3 startEuler) { if (transform == null) { throw new ArgumentNullException(nameof(transform)); } if (duration < 0f) { throw new ArgumentException(nameof(duration)); } TimeTweener tweener = new TimeTweener() { DurationTime = duration, TimeType = TweenerTimeType.ScaleTime, }; tweener.Enumerator = DoLocalEuler_Internal(tweener, transform, targetEuler, startEuler); return(tweener); }