You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
3.1 KiB

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<Transform> items;
/// <summary>
/// 进度模式
/// </summary>
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();
}
}
/// <summary>
/// 初始化标签位置及信息
/// </summary>
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>().text = CommonTool.GetSpareName(spareTypes[i]);
}
StartCoroutine(GrouwthBar(GameConfig.curProgressIndex,true));
}
/// <summary>
/// 进度条增长
/// </summary>
/// <returns></returns>
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;
}
}
}
/// <summary>
/// 增长进度
/// </summary>
public void GrouwthProgress()
{
StartCoroutine(GrouwthBar(1,false));
}
/// <summary>
/// 重置清理进度
/// </summary>
public void ClearProgress()
{
topProgress_img.fillAmount = 0;
curIndex = 0;
}
}
}