From a251b401dd2535b7583d1813e08dc2e3cced05d5 Mon Sep 17 00:00:00 2001 From: chenxin <chenxin6991@163.com> Date: Sat, 05 Dec 2020 18:42:11 +0800 Subject: [PATCH] 随机 --- Assets/Scripts/TowerDefense/UI/EndlessBossHPManager.cs | 87 ++++++++++++++++++++++++++----------------- 1 files changed, 52 insertions(+), 35 deletions(-) diff --git a/Assets/Scripts/TowerDefense/UI/EndlessBossHPManager.cs b/Assets/Scripts/TowerDefense/UI/EndlessBossHPManager.cs index 7d03af3..8eefc28 100644 --- a/Assets/Scripts/TowerDefense/UI/EndlessBossHPManager.cs +++ b/Assets/Scripts/TowerDefense/UI/EndlessBossHPManager.cs @@ -30,17 +30,10 @@ private string path = "UI/Endless/Blood/"; - private string bossPath = "UI/Endless/Boss/"; - /// <summary> /// 血条底图 /// </summary> public Sprite BaseBlood; - - /// <summary> - /// 当前的进度值 - /// </summary> - private float current; /// <summary> /// 目标进度值 @@ -48,16 +41,9 @@ private float target; /// <summary> - /// 血条消失速度 - /// </summary> - public float Speed = 50f; - - /// <summary> /// 当前颜色索引 /// </summary> private int index; - - private Tween tween; public TextMeshProUGUI WaveNumText; @@ -71,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> @@ -94,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> @@ -109,7 +125,6 @@ /// </summary> private void ResetProgress() { - current = 1f; target = 1f; HPImage1.fillAmount = 1; HPImage2.fillAmount = 1; @@ -122,7 +137,6 @@ /// <param name="end"></param> public void SwitchHP(bool end = false) { - tween.Pause(); HPImage2.fillAmount = 0; index = ++index % count; ChangeHPImageIndex(); @@ -133,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> @@ -147,6 +171,10 @@ public void UpdateWave(int wave) { WaveNumText.text = $"x{wave}"; + if (wave == 0) + { + AudioSourceManager.Ins.Play(AudioEnum.BossDie); + } } /// <summary> @@ -198,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