hch
2025-07-23 2336d5e71a6ed9c00f9a86c29d7aa33b9a1e38d5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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<Vector2, Vector2, DG.Tweening.Plugins.Options.VectorOptions> 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());
    }
 
}