yyl
2025-08-29 dbb4ea01211573e782666e45eb859c96859b2cd6
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
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using DG.Tweening;
 
 
public class BattleHeroInfoBar : MonoBehaviour
{
    protected BattleObject battleObject;
 
    public Slider sliderHp;
 
    public Slider sliderXp; //怒气
 
    protected float timer = 0f;
 
    public float PopUpInterval = 0.2f;
 
 
    // public List<BattleBuffCell> buffCells = new List<BattleBuffCell>();
 
    protected List<string> messages = new List<string>();
 
    public BasicHeroInfoContainer heroInfoContainer;
 
    public BattleTips textTips;
 
    protected Tween hpTween;
 
    protected Tween xpTween;
 
    protected List<BattleTips> tipsList = new List<BattleTips>();
 
    protected List<HB428_tagSCBuffRefresh> buffList = new List<HB428_tagSCBuffRefresh>();
 
    public ScrollerController scroller;
 
    public void SetBattleObject(BattleObject _battleObject)
    {
        battleObject = _battleObject;
        heroInfoContainer.SetHeroInfo(battleObject.teamHero);
        RefreshBuff(buffList);
    }
 
    public void RefreshBuff(List<HB428_tagSCBuffRefresh> datas)
    {
        buffList = datas;
        //  更新buff图标 or 创建新的buff图标
        scroller.Refresh();
        for (int i = 0; i < buffList.Count; i++)
        {
            if (i % 5 == 0)
            {
                scroller.AddCell(ScrollerDataType.Header, i);
            }
        }
        scroller.Restart();
    }
 
    protected void OnEnable()
    {
        scroller.OnRefreshCell += OnRefreshCell;        
    }
 
    protected void OnDisable()
    {
        scroller.OnRefreshCell -= OnRefreshCell;     
        //  TODO YYL 考虑池化
        messages.Clear();
        for (int i = 0; i < tipsList.Count; i++)
        {
            var tip = tipsList[i];
            tip.OnFinish = null;
            GameObject.DestroyImmediate(tip.gameObject);
        }
        tipsList.Clear();
    }
 
    protected void OnRefreshCell(ScrollerDataType type, CellView cell)
    {
        var _cell = cell as BattleBuffLineCell;
        _cell.Display(buffList, cell.index);
    }
 
    public void ShowTips(string message)
    {
        messages.Add(message);
    }
 
    public void SetActive(bool active)
    {
        gameObject.SetActive(active);
    }
 
    public void PopUpTipsDirectly(string message)
    {
        GameObject prefab = textTips.gameObject;
 
        GameObject go = GameObject.Instantiate(prefab, transform);
 
        BattleTips tips = go.GetComponent<BattleTips>();
 
        tips.SetText(message);
 
        tips.OnFinish = () =>
        {
            //  TODO YYL 考虑池化
            tipsList.Remove(tips);
            GameObject.DestroyImmediate(tips.gameObject);
        };
 
        tipsList.Add(tips);
    }
 
 
    public void UpdateHP(long fromHp, long toHp, long maxHp)
    {
        //  做hp增加或者减少的动画
        // sliderHp.value = ((float)fromHp) / ((float)maxHp);
        if (hpTween != null)
        {
            battleObject.battleField.battleTweenMgr.OnKillTween(hpTween);
        }
        hpTween = sliderHp.DOValue((float)toHp / maxHp, 0.3f);
        battleObject.battleField.battleTweenMgr.OnPlayTween(hpTween);
    }
 
    public void UpdateXP(long fromXp, long toXp, long maxXp)
    {
        //  做Xp增加或者减少的动画
        // sliderXp.value = ((float)fromXp) / ((float)maxXp);
        if (xpTween != null)
        {
            battleObject.battleField.battleTweenMgr.OnKillTween(xpTween);
        }
        xpTween = sliderHp.DOValue((float)toXp / maxXp, 0.2f);
        battleObject.battleField.battleTweenMgr.OnPlayTween(xpTween);
    }
 
    public void Run()
    {
        for (int i = tipsList.Count - 1; i >= 0; i--)
        {
            tipsList[i].Run();
        }
 
        timer += Time.deltaTime;
 
        if (messages.Count > 0 && timer >= PopUpInterval)
        {
            // 播放飘字
            string message = messages[0];
            messages.RemoveAt(0);
 
            PopUpTipsDirectly(message);
 
            timer = 0f;
        }
    }
}