| | |
| | | using UnityEngine.UI; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using Core.Utilities; |
| | | using DG.Tweening; |
| | | using TMPro; |
| | | |
| | | /** |
| | | * 无尽模式boss血量管理器 |
| | |
| | | /// </summary> |
| | | public Image HPImage2; |
| | | |
| | | private Color[] colorArr = |
| | | { |
| | | new Color(1, 0, 0), // "#FF0000" |
| | | new Color(1, 165 / 255f, 0), // "#FFA500" |
| | | new Color(1, 1, 0), // "#FFFF00" |
| | | new Color(0, 1, 0), // "#00FF00" |
| | | new Color(0, 1, 1), // "#00FFFF" |
| | | new Color(0, 0, 1), // "#0000FF" |
| | | new Color(128 / 255f, 0, 128 / 255f) // "#800080" |
| | | }; |
| | | /// <summary> |
| | | /// boss形象 |
| | | /// </summary> |
| | | public Image BossImage; |
| | | |
| | | private string path = "UI/Endless/Blood/"; |
| | | |
| | | /// <summary> |
| | | /// 当前的进度值 |
| | | /// 血条底图 |
| | | /// </summary> |
| | | private float current; |
| | | public Sprite BaseBlood; |
| | | |
| | | /// <summary> |
| | | /// 目标进度值 |
| | |
| | | private float target; |
| | | |
| | | /// <summary> |
| | | /// 血条消失速度 |
| | | /// </summary> |
| | | public float Speed = 50f; |
| | | |
| | | /// <summary> |
| | | /// 当前颜色索引 |
| | | /// </summary> |
| | | private int index; |
| | | |
| | | private Tween tween; |
| | | public TextMeshProUGUI WaveNumText; |
| | | |
| | | public Text WaveNumText; |
| | | /// <summary> |
| | | /// 血条7种颜色 |
| | | /// </summary> |
| | | private int count = 7; |
| | | |
| | | /// <summary> |
| | | /// boss信息,名字和等级 |
| | | /// </summary> |
| | | public Text BossInfo; |
| | | |
| | | private Sequence progressSequence; |
| | | |
| | | public Text HPInfoText; |
| | | |
| | | private float totalHP; |
| | | |
| | | /// <summary> |
| | | /// boss总血量 |
| | | /// </summary> |
| | | /// <value></value> |
| | | private float TotalHP { get; set; } |
| | | |
| | | private float hp; |
| | | |
| | | /// <summary> |
| | | /// 当前血量 |
| | | /// </summary> |
| | | /// <value></value> |
| | | public float CurrentHP |
| | | { |
| | | get { return hp; } |
| | | private set |
| | | { |
| | | hp = value; |
| | | |
| | | if (hp < 0.00001f) hp = 0; |
| | | } |
| | | } |
| | | |
| | | // Start is called before the first frame update |
| | | private void Start() |
| | | { |
| | | InitHP(); |
| | | Init(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置当前进度百分比 |
| | | /// 设置boss的当前血量 |
| | | /// </summary> |
| | | /// <param name="progress"></param> |
| | | public void SetCurrentProgress(float progress) |
| | | /// <param name="hp"></param> |
| | | public void SetCurrentHP(float hp) |
| | | { |
| | | target = progress; |
| | | tween = DOTween.To(() => HPImage2.fillAmount, (v) => HPImage2.fillAmount = v, target, 0.3f); |
| | | tween.Play(); |
| | | CurrentHP = hp; |
| | | target = CurrentHP / TotalHP; |
| | | HPInfoText.text = $"HP:{Mathf.Floor(CurrentHP)}/{Mathf.Floor(TotalHP)}"; |
| | | DOTween.To(() => HPImage2.fillAmount, (float v) => HPImage2.fillAmount = v, target, 0.2f); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | private void ResetProgress() |
| | | { |
| | | current = 1f; |
| | | target = 1f; |
| | | HPImage1.fillAmount = 1; |
| | | HPImage2.fillAmount = 1; |
| | | index = index % colorArr.Length; |
| | | index = index % count; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <param name="end"></param> |
| | | public void SwitchHP(bool end = false) |
| | | { |
| | | tween.Pause(); |
| | | HPImage2.fillAmount = 0; |
| | | index = ++index % colorArr.Length; |
| | | index = ++index % count; |
| | | ChangeHPImageIndex(); |
| | | ResetProgress(); |
| | | SetHPColor(end); |
| | |
| | | /// <summary> |
| | | /// 初始化血条 |
| | | /// </summary> |
| | | public void InitHP() |
| | | public void Init() |
| | | { |
| | | index = 0; |
| | | ResetProgress(); |
| | | SetHPColor(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 初始化血量数据 |
| | | /// </summary> |
| | | /// <param name="totalHP"></param> |
| | | public void InitHP(float totalHP) |
| | | { |
| | | CurrentHP = TotalHP = totalHP; |
| | | HPInfoText.text = $"HP:{Mathf.Floor(CurrentHP)}/{Mathf.Floor(TotalHP)}"; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <param name="wave"></param> |
| | | public void UpdateWave(int wave) |
| | | { |
| | | WaveNumText.text = $"×{wave}"; |
| | | WaveNumText.text = $"x{wave}"; |
| | | if (wave == 0) |
| | | { |
| | | AudioSourceManager.Ins.Play(AudioEnum.BossDie); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置boss信息 |
| | | /// </summary> |
| | | /// <param name="info"></param> |
| | | public void SetBossInfo(string info) |
| | | { |
| | | BossInfo.text = info; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | if (end) |
| | | { |
| | | HPImage2.color = colorArr[index]; |
| | | HPImage1.color = Color.white; |
| | | HPImage2.sprite = GetSprite(index); |
| | | HPImage1.sprite = Resources.Load($"{path}di", typeof(Sprite)) as Sprite; |
| | | } |
| | | else |
| | | { |
| | | HPImage2.color = colorArr[index]; |
| | | HPImage1.color = colorArr[(index + 1) % colorArr.Length]; |
| | | HPImage2.sprite = GetSprite(index); |
| | | HPImage1.sprite = GetSprite((index + 1) % count); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据索引获得sprite |
| | | /// </summary> |
| | | /// <param name="index"></param> |
| | | private Sprite GetSprite(int index) |
| | | { |
| | | return Resources.Load($"{path}{index}", typeof(Sprite)) as Sprite; |
| | | } |
| | | } |
| | | } |