From f2f4e1e45981bb294a5221ade7b4646cc3e29d35 Mon Sep 17 00:00:00 2001
From: chenxin <chenxin6991@163.com>
Date: Wed, 11 Nov 2020 18:56:44 +0800
Subject: [PATCH] 无尽模式分数

---
 Assets/Scripts/TowerDefense/UI/EndlessBossHPManager.cs |   75 ++++++++++++++++++++++++-------------
 1 files changed, 48 insertions(+), 27 deletions(-)

diff --git a/Assets/Scripts/TowerDefense/UI/EndlessBossHPManager.cs b/Assets/Scripts/TowerDefense/UI/EndlessBossHPManager.cs
index 30d83a6..8eefc28 100644
--- a/Assets/Scripts/TowerDefense/UI/EndlessBossHPManager.cs
+++ b/Assets/Scripts/TowerDefense/UI/EndlessBossHPManager.cs
@@ -41,16 +41,9 @@
         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>
@@ -114,7 +137,6 @@
         /// <param name="end"></param>
         public void SwitchHP(bool end = false)
         {
-            tween.Pause();
             HPImage2.fillAmount = 0;
             index = ++index % count;
             ChangeHPImageIndex();
@@ -125,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>
@@ -194,17 +226,6 @@
         private Sprite GetSprite(int index)
         {
             return Resources.Load($"{path}{index}", typeof(Sprite)) as Sprite;
-        }
-
-        /// <summary>
-        /// 设置boss形象
-        /// </summary>
-        /// <param name="resId"></param>
-        public void SetBossImage(int resId)
-        {
-            resId = (resId + 1) % 2 + 1;
-            // BossImage.sprite = Resources.Load<Sprite>($"{bossPath}{resId}");
-            // BossImage.SetNativeSize();
         }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1