wangguan
2020-10-22 74daf5509be4fc140fd1bdb6d4df5f1c1002e368
Assets/Scripts/TowerDefense/UI/EndlessBossHPManager.cs
@@ -1,9 +1,8 @@
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Core.Utilities;
using DG.Tweening;
using TMPro;
/**
 * 无尽模式boss血量管理器
@@ -24,16 +23,12 @@
        /// </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"
        };
        private string path = "UI/Endless/Blood/";
        /// <summary>
        /// 血条底图
        /// </summary>
        public Sprite BaseBlood;
        /// <summary>
        /// 当前的进度值
@@ -57,7 +52,17 @@
        private Tween tween;
        public Text WaveNumText;
        public TextMeshProUGUI WaveNumText;
        /// <summary>
        /// 血条7种颜色
        /// </summary>
        private int count = 7;
        /// <summary>
        /// boss信息,名字和等级
        /// </summary>
        public Text BossInfo;
        // Start is called before the first frame update
        private void Start()
@@ -101,7 +106,7 @@
            target = 1f;
            HPImage1.fillAmount = 1;
            HPImage2.fillAmount = 1;
            index = index % colorArr.Length;
            index = index % count;
        }
        /// <summary>
@@ -112,7 +117,7 @@
        {
            tween.Pause();
            HPImage2.fillAmount = 0;
            index = ++index % colorArr.Length;
            index = ++index % count;
            ChangeHPImageIndex();
            ResetProgress();
            SetHPColor(end);
@@ -134,7 +139,16 @@
        /// <param name="wave"></param>
        public void UpdateWave(int wave)
        {
            WaveNumText.text = $"×{wave}";
            WaveNumText.text = $"x{wave}";
        }
        /// <summary>
        /// 设置boss信息
        /// </summary>
        /// <param name="info"></param>
        public void SetBossInfo(string info)
        {
            BossInfo.text = info;
        }
        /// <summary>
@@ -160,14 +174,23 @@
        {
            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;
        }
    }
}