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.

120 lines
2.7 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace DisComputer
{
/*
*@func 拆装机进度条
* @author lz
* @data 2020/5/27
*/
public class ProgressStater : UIShowOrHide
{
//顶部进度条
public Image topProgress_img;
//切分个数
public float divisionNum;
//步骤标签
public List<Transform> items;
/// <summary>
/// 进度模式
/// </summary>
public Text progress_txt;
public override void OnShow(object data)
{
base.OnShow(data);
InitItemsPos(data);
}
private void Start()
{
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.G))
{
GrouwthProgress();
}
}
/// <summary>
/// 初始化标签位置及信息
/// </summary>
void InitItemsPos(object data)
{
if (GameConfig.state == GameState.Load)
progress_txt.text = "安装进度";
else
progress_txt.text = "拆卸进度";
SpareType[] spareTypes = (SpareType[])data;
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]);
}
}
/// <summary>
/// 进度条增长
/// </summary>
/// <returns></returns>
IEnumerator GrouwthBar()
{
float curValue = 0;
float unitVal = 1 / 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());
}
/// <summary>
/// 重置清理进度
/// </summary>
public void ClearProgress()
{
topProgress_img.fillAmount = 0;
}
}
}