chenxin
2020-11-27 841b66ef416a727a0c798ad2263b098247cb4aa7
Assets/Scripts/TowerDefense/UI/EndlessBossHPManager.cs
@@ -23,6 +23,11 @@
        /// </summary>
        public Image HPImage2;
        /// <summary>
        /// boss形象
        /// </summary>
        public Image BossImage;
        private string path = "UI/Endless/Blood/";
        /// <summary>
@@ -31,26 +36,14 @@
        public Sprite BaseBlood;
        /// <summary>
        /// 当前的进度值
        /// </summary>
        private float current;
        /// <summary>
        /// 目标进度值
        /// </summary>
        private float target;
        /// <summary>
        /// 血条消失速度
        /// </summary>
        public float Speed = 50f;
        /// <summary>
        /// 当前颜色索引
        /// </summary>
        private int index;
        private Tween tween;
        public TextMeshProUGUI WaveNumText;
@@ -64,10 +57,39 @@
        /// </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>
@@ -87,14 +109,15 @@
        }
        /// <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>
@@ -102,7 +125,6 @@
        /// </summary>
        private void ResetProgress()
        {
            current = 1f;
            target = 1f;
            HPImage1.fillAmount = 1;
            HPImage2.fillAmount = 1;
@@ -115,7 +137,6 @@
        /// <param name="end"></param>
        public void SwitchHP(bool end = false)
        {
            tween.Pause();
            HPImage2.fillAmount = 0;
            index = ++index % count;
            ChangeHPImageIndex();
@@ -126,11 +147,21 @@
        /// <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>
@@ -140,6 +171,10 @@
        public void UpdateWave(int wave)
        {
            WaveNumText.text = $"x{wave}";
            if (wave == 0)
            {
                AudioSourceManager.Ins.Play(AudioEnum.BossDie);
            }
        }
        /// <summary>