using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using DG.Tweening; public class Tools : MonoBehaviour { // Start is called before the first frame update void Start() { } public static IEnumerator AnimateText(float startValue, float endValue, float time, Text SetText) { float elapsedTime = 0f; // 已经过去的时间 while (elapsedTime < time) { elapsedTime += Time.deltaTime; float t = elapsedTime / time; // 计算当前值,使用 Mathf.Lerp 进行线性插值 int currentValue = Mathf.RoundToInt(Mathf.Lerp(startValue, endValue, t)); // 更新文本显示 SetText.text = currentValue.ToString(); yield return null; // 等待一帧 } SetText.text = endValue.ToString(); } //public static void MoveUpOrDwon(RectTransform obj,float add)//向上或下移动 //{ // float targetY = obj.anchoredPosition.y + add; // 计算目标位置 // obj.DOAnchorPosY(targetY, 1f).SetEase(Ease.Linear); //} public static void MoveUpOrDwon(RectTransform obj, float add, System.Action onComplete = null) { float targetY = obj.anchoredPosition.y + add; // 计算目标位置 obj.DOAnchorPosY(targetY, 1f).SetEase(Ease.Linear).OnComplete(() => { if (onComplete != null) { onComplete.Invoke(); } }); } }