yyl
2026-02-11 3f2cd27c5dfb3b450245bf1a37fc1b3414031c7c
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using System.Collections;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using DG.Tweening;
using UnityEngine.UI;
using UnityEngine;
 
public class SkillTips : MonoBehaviour
{
    public const float tweenDuration = 0.5f;
 
    public const float delayDuration = 1.1f;
 
    public const float beginingX = 400f;
 
    [SerializeField]public Image imgIcon;
 
    [SerializeField]public Image imgSkillName;
 
    [SerializeField] public Image imageBg;
 
    private Tween tween1;
    private Tween tween2;
    private Tween tween3;
 
    public void PlayMotion(BattleField battleField, bool isRed, TeamHero teamHero, SkillConfig skillConfig)
    {
        if (teamHero == null || skillConfig == null)
        {
            return;
        }
 
        if (skillConfig.FuncType != 2)
            return;
 
        KillAllTweens();
 
        imgIcon.sprite = UILoader.LoadSprite("HeroHead", teamHero.skinConfig.SquareIcon);
        imgSkillName.sprite = UILoader.LoadSprite("SkillNameIcon", skillConfig.SkillTipsName);
        imgSkillName.SetNativeSize();
        // 保证开始时所有图片为可见(alpha=1)
        if (imageBg != null) { var c = imageBg.color; c.a = 1f; imageBg.color = c; }
        if (imgIcon != null) { var c = imgIcon.color; c.a = 1f; imgIcon.color = c; }
        if (imgSkillName != null) { var c = imgSkillName.color; c.a = 1f; imgSkillName.color = c; }
 
        gameObject.SetActive(true);
        float posY = transform.localPosition.y;
        transform.localPosition = isRed ? new Vector3(-beginingX, posY, 0f) : new Vector3(beginingX, posY, 0f);
        tween1 = transform.DOLocalMoveX(0, tweenDuration / battleField.speedRatio, false).SetEase(Ease.Linear).OnComplete(() =>
        {
            tween1 = null;
            tween3 = DOVirtual.DelayedCall(delayDuration / battleField.speedRatio, () =>
            {
                tween3 = null;
 
                // tween2 改为做减淡(对 imageBg、imgIcon、imgSkillName 同步淡出)
                float fadeDuration = tweenDuration / battleField.speedRatio;
                Sequence seq = DOTween.Sequence();
                if (imageBg != null)
                    seq.Join(imageBg.DOFade(0f, fadeDuration).SetEase(Ease.InQuad));
                if (imgIcon != null)
                    seq.Join(imgIcon.DOFade(0f, fadeDuration).SetEase(Ease.InQuad));
                if (imgSkillName != null)
                    seq.Join(imgSkillName.DOFade(0f, fadeDuration).SetEase(Ease.InQuad));
 
                seq.OnComplete(() =>
                {
                    tween2 = null;
                    // 恢复图片 alpha,保证下次显示时可见
                    if (imageBg != null) { var cc = imageBg.color; cc.a = 1f; imageBg.color = cc; }
                    if (imgIcon != null) { var cc = imgIcon.color; cc.a = 1f; imgIcon.color = cc; }
                    if (imgSkillName != null) { var cc = imgSkillName.color; cc.a = 1f; imgSkillName.color = cc; }
 
                    transform.localPosition = isRed ? new Vector3(-beginingX, posY, 0f) : new Vector3(beginingX, posY, 0f);
                    gameObject.SetActive(false);
                });
 
                tween2 = seq;
                battleField.battleTweenMgr.OnPlayTween(tween2);
            });
            battleField.battleTweenMgr.OnPlayTween(tween3);
        });
        battleField.battleTweenMgr.OnPlayTween(tween1);
    }
 
    public async UniTask PlayMotionAsync(BattleField battleField, bool isRed, TeamHero teamHero, SkillConfig skillConfig)
    {
        if (teamHero == null || skillConfig == null)
        {
            return;
        }
 
        if (skillConfig.FuncType != 2)
            return;
 
        KillAllTweens();
 
        imgIcon.sprite = await UILoader.LoadSpriteAsync("HeroHead", teamHero.skinConfig.SquareIcon);
        if (this == null) return;
        imgSkillName.sprite = await UILoader.LoadSpriteAsync("SkillNameIcon", skillConfig.SkillTipsName);
        if (this == null) return;
        imgSkillName.SetNativeSize();
        // 保证开始时所有图片为可见(alpha=1)
        if (imageBg != null) { var c = imageBg.color; c.a = 1f; imageBg.color = c; }
        if (imgIcon != null) { var c = imgIcon.color; c.a = 1f; imgIcon.color = c; }
        if (imgSkillName != null) { var c = imgSkillName.color; c.a = 1f; imgSkillName.color = c; }
 
        gameObject.SetActive(true);
        float posY = transform.localPosition.y;
        transform.localPosition = isRed ? new Vector3(-beginingX, posY, 0f) : new Vector3(beginingX, posY, 0f);
        tween1 = transform.DOLocalMoveX(0, tweenDuration / battleField.speedRatio, false).SetEase(Ease.Linear).OnComplete(() =>
        {
            tween1 = null;
            tween3 = DOVirtual.DelayedCall(delayDuration / battleField.speedRatio, () =>
            {
                tween3 = null;
 
                // tween2 改为做减淡(对 imageBg、imgIcon、imgSkillName 同步淡出)
                float fadeDuration = tweenDuration / battleField.speedRatio;
                Sequence seq = DOTween.Sequence();
                if (imageBg != null)
                    seq.Join(imageBg.DOFade(0f, fadeDuration).SetEase(Ease.InQuad));
                if (imgIcon != null)
                    seq.Join(imgIcon.DOFade(0f, fadeDuration).SetEase(Ease.InQuad));
                if (imgSkillName != null)
                    seq.Join(imgSkillName.DOFade(0f, fadeDuration).SetEase(Ease.InQuad));
 
                seq.OnComplete(() =>
                {
                    tween2 = null;
                    // 恢复图片 alpha,保证下次显示时可见
                    if (imageBg != null) { var cc = imageBg.color; cc.a = 1f; imageBg.color = cc; }
                    if (imgIcon != null) { var cc = imgIcon.color; cc.a = 1f; imgIcon.color = cc; }
                    if (imgSkillName != null) { var cc = imgSkillName.color; cc.a = 1f; imgSkillName.color = cc; }
 
                    transform.localPosition = isRed ? new Vector3(-beginingX, posY, 0f) : new Vector3(beginingX, posY, 0f);
                    gameObject.SetActive(false);
                });
 
                tween2 = seq;
                battleField.battleTweenMgr.OnPlayTween(tween2);
            });
            battleField.battleTweenMgr.OnPlayTween(tween3);
        });
        battleField.battleTweenMgr.OnPlayTween(tween1);
    }
    
    public void KillAllTweens()
    {
        if (tween1 != null)
        {
            tween1.Kill();
            tween1 = null;
        }
        if (tween2 != null)
        {
            tween2.Kill();
            tween2 = null;
        }
        if (tween3 != null)
        {
            tween3.Kill();
            tween3 = null;
        }
 
        // 被强制停止时也需要恢复 alpha
        if (imageBg != null) { var cc = imageBg.color; cc.a = 1f; imageBg.color = cc; }
        if (imgIcon != null) { var cc = imgIcon.color; cc.a = 1f; imgIcon.color = cc; }
        if (imgSkillName != null) { var cc = imgSkillName.color; cc.a = 1f; imgSkillName.color = cc; }
    }
 
}