From 344267a8edb7bc6eaa67a0493292f438d31ca20e Mon Sep 17 00:00:00 2001 From: chenxin <chenxin6991@163.com> Date: Tue, 17 Nov 2020 21:10:57 +0800 Subject: [PATCH] buff补充 --- Assets/Scripts/TowerDefense/UI/BulletUICtl.cs | 117 +++++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 79 insertions(+), 38 deletions(-) diff --git a/Assets/Scripts/TowerDefense/UI/BulletUICtl.cs b/Assets/Scripts/TowerDefense/UI/BulletUICtl.cs index 03ed457..9d145a1 100644 --- a/Assets/Scripts/TowerDefense/UI/BulletUICtl.cs +++ b/Assets/Scripts/TowerDefense/UI/BulletUICtl.cs @@ -1,19 +1,10 @@ -using DG.Tweening; -using Protobuf; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; +using UnityEngine; /// <summary> /// 子弹充能对应的数据结构. /// </summary> public class BulletUICtl : MonoBehaviour { - public SpriteRenderer bulletScaleMask; - - public float fAdjValue; - /// <summary> /// 最大子弹数目. /// </summary> @@ -24,18 +15,48 @@ /// </summary> protected int curBulletNum; - private float[] scaleArr = { 0, 0.16f, 0.32f, 0.48f, 0.64f, 0.8f, 1f }; + private int critNum = 3; - private float[] yArr = { 0.4f, 0.377f, 0.307f, 0.227f, 0.153f, 0.074f, 0 }; + /// <summary> + /// 默认的暴击子弹数量 + /// </summary> + public static int defaultCritNum { get; private set; } - private float gap = 0.15f; + /// <summary> + /// 暴击子弹数量 + /// </summary> + /// <value></value> + public int CritBulletNum + { + get { return critNum; } + set + { + if (value < 1) value = 1; + else if (value > maxBulletNum) value = maxBulletNum; + + critNum = value; + UpdateBulletType(); + } + } + + /// <summary> + /// 子弹底图 + /// </summary> + public SpriteRenderer[] BottomArr; + + public SpriteRenderer[] BulletArr; + + public Sprite NormalSprite; + + public Sprite CritSprite; // Start is called before the first frame update void Start() { - resetToMaxBullet(); + defaultCritNum = critNum; + ResetToMaxBullet(); + UpdateBulletType(); } - /// <summary> /// 获取进度条进度. @@ -43,28 +64,28 @@ /// <returns></returns> public int GetCtlProgress() { - return this.curBulletNum; + return curBulletNum; } /// <summary> /// 设置进度. /// </summary> /// <param name="pro"></param> - public void SetCtlProcess( int pro) + public void SetCtlProcess(int pro) { - this.curBulletNum = pro; - this.updateBulletUI(pro, maxBulletNum); + curBulletNum = pro; + updateBulletUI(pro, maxBulletNum); } /// <summary> /// 重设子弹数目到最大. /// </summary> - public void resetToMaxBullet() + public void ResetToMaxBullet() { - if (this.curBulletNum == maxBulletNum) return; - - this.curBulletNum = maxBulletNum; - this.updateBulletUI(curBulletNum, maxBulletNum); + if (curBulletNum == maxBulletNum) return; + + curBulletNum = maxBulletNum; + updateBulletUI(curBulletNum, maxBulletNum); } /// <summary> @@ -73,32 +94,52 @@ /// <returns></returns> public int decBullet() { - if (this.curBulletNum <= 0) return 0; - this.curBulletNum--; - this.updateBulletUI(curBulletNum, maxBulletNum); + if (curBulletNum <= 0) return 0; + + curBulletNum--; + updateBulletUI(curBulletNum, maxBulletNum); + return curBulletNum; } /// <summary> - /// 更新子弹界面对应的缩放信息 + /// 更新子弹显示 /// </summary> /// <param name="curBNum"></param> /// <param name="totalBNum"></param> - public void updateBulletUI( int curBNum,int totalBNum) + public void updateBulletUI(int curBNum, int totalBNum) { - if (bulletScaleMask == null) return; + // 隐藏的子弹数量 + int hideCount = maxBulletNum - curBNum; - Vector3 pos = bulletScaleMask.transform.localPosition; - pos.y = yArr[maxBulletNum - curBulletNum]; - bulletScaleMask.transform.localPosition = pos; - Vector3 s = bulletScaleMask.transform.localScale; - s.y = scaleArr[maxBulletNum - curBulletNum]; - bulletScaleMask.transform.localScale = s; + for (int i = 0; i < BulletArr.Length; ++i) + { + if (hideCount > 0) + { + --hideCount; + BulletArr[i].enabled = false; + } + else + BulletArr[i].enabled = true; + } } - // Update is called once per frame - void Update() + /// <summary> + /// 更新子弹类型 + /// </summary> + private void UpdateBulletType() { + int count = critNum; + for (int i = BulletArr.Length - 1; i >= 0; --i) + { + if (count > 0) + { + --count; + BulletArr[i].sprite = CritSprite; + } + else + BulletArr[i].sprite = NormalSprite; + } } } -- Gitblit v1.9.1