using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using DG.Tweening; using DG.Tweening.Core; public static class BattleUtility { // 其他通用的战斗工具方法可以放在这里 public static TweenerCore MoveToTarget(RectTransform transform, RectTransform target, Vector2 offset, float duration, Action onComplete = null) { Vector3 targetWorldPos = target.TransformPoint(target.anchoredPosition + offset); RectTransform parentRect = transform.parent as RectTransform; Vector2 targetAnchoredPos; RectTransformUtility.ScreenPointToLocalPointInRectangle( parentRect, RectTransformUtility.WorldToScreenPoint(null, targetWorldPos), null, out targetAnchoredPos); // 3. DOTween 移动 return transform.DOAnchorPos(targetAnchoredPos, duration) .SetEase(Ease.Linear) .OnComplete(() => onComplete?.Invoke()); } }