yyl
2025-08-07 f4bb83fc7902cf87ba43b918c87c1d96ee5dbc14
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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());
    }
 
    public static string DisplayDamageNum(long num, int attackType)
    {
        var basePowerStr = UIHelper.ReplaceLargeArtNum(num);
        var result = string.Empty;
        for (int i = 0; i < basePowerStr.Length; i++)
        {
            var numChar = (char)GetDamageNumKey((DamageType)attackType, basePowerStr[i]);
            if (numChar > 0)
            {
                result += numChar;
            }
        }
        return result;
    }
 
    public static int GetDamageNumKey(DamageType damageType, int _num)
    {
        var config = DamageNumConfig.Get(damageType.ToString());
        //.的ASCII码是46
        if (_num == 46)
        {
            return config.nums[10];
        }
        //k的ASCII码是107
        else if (_num == 107)
        {
            return config.nums[11];
        }
        //m的ASCII码是109
        else if (_num == 109)
        {
            return config.nums[12];
        }
        //b的ASCII码是98
        else if (_num == 98)
        {
            return config.nums[13];
        }
        //t的ASCII码是116
        else if (_num == 116)
        {
            return config.nums[14];
        }
        return config.nums[_num - 48];
    }
 
}