using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace DisComputer { /* *@func 拆装机进度条 * @author lz * @date 2020/5/27 */ public class ProgressStater : UIShowOrHide { //顶部进度条 public Image topProgress_img; //切分个数 public float divisionNum; //步骤标签 public List items; /// /// 进度模式 /// public Text progress_txt; //当前进度 private int curIndex = 0; public override void OnShow(object data =null) { base.OnShow(data); InitItemsPos(); } private void Start() { } private void Update() { if (Input.GetKeyDown(KeyCode.G)) { GrouwthProgress(); } } /// /// 初始化标签位置及信息 /// void InitItemsPos() { if (GameConfig.state == GameState.Load) progress_txt.text = "组装进度"; else progress_txt.text = "拆解进度"; SpareType[] spareTypes = GameConfig.GetItemInfos; for (int i = 0;i< divisionNum; i++) { items[i].localPosition = new Vector3(-317+(106*i),-34.42f,0); GameObject tempTxtGo = items[i].Find("Text").gameObject; tempTxtGo.GetComponent().text = CommonTool.GetSpareName(spareTypes[i]); } StartCoroutine(GrouwthBar(GameConfig.curProgressIndex,true)); } /// /// 进度条增长 /// /// IEnumerator GrouwthBar(int step,bool isJudge) { if (step <= 0) yield break; if (isJudge) { if(curIndex != 0 && curIndex == step) { yield break; } curIndex = step; } float curValue = 0; float unitVal = step / divisionNum; float curFill = topProgress_img.fillAmount; while (true) { yield return new WaitForEndOfFrame(); curValue += Time.deltaTime; topProgress_img.fillAmount = curFill + curValue; if (curValue >= unitVal) { curValue = unitVal; topProgress_img.fillAmount = curFill + curValue; break; } } } /// /// 增长进度 /// public void GrouwthProgress() { StartCoroutine(GrouwthBar(1,false)); } /// /// 重置清理进度 /// public void ClearProgress() { topProgress_img.fillAmount = 0; curIndex = 0; } } }