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;
|
}
|
}
|
}
|