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.
84 lines
2.1 KiB
84 lines
2.1 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
|
|
namespace DisComputer
|
|
{
|
|
/*
|
|
* @func 执行进度
|
|
* */
|
|
public class WorkLoading : MonoBehaviour
|
|
{
|
|
private Image circle_img;
|
|
|
|
private float fillVal = 0;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
/// <param name="texture"></param>
|
|
/// <param name="fillColor"></param>
|
|
public void InitLoading(Texture2D texture,Color fillColor)
|
|
{
|
|
GameObject temp = new GameObject("circle");
|
|
temp.transform.SetParent(this.transform);
|
|
temp.transform.localPosition = Vector3.zero;
|
|
temp.transform.localScale = new Vector3(0.5f,0.5f,0.5f);
|
|
|
|
circle_img = temp.AddComponent<Image>();
|
|
Sprite sp = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
|
|
circle_img.sprite = sp;
|
|
circle_img.type = Image.Type.Filled;
|
|
circle_img.fillMethod = Image.FillMethod.Radial360;
|
|
circle_img.fillOrigin = 0;
|
|
circle_img.fillAmount = 0;
|
|
circle_img.color = fillColor;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 更新进度显示
|
|
/// </summary>
|
|
/// <param name="finish"></param>
|
|
public void UpdateLoading(System.Action finish)
|
|
{
|
|
fillVal += Time.deltaTime * 0.75f;
|
|
if(fillVal >= 1.0f)
|
|
{
|
|
fillVal = 1.0f;
|
|
circle_img.fillAmount = fillVal;
|
|
finish?.Invoke();
|
|
}
|
|
circle_img.fillAmount = fillVal;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 重置进度
|
|
/// </summary>
|
|
public void RewindLoading()
|
|
{
|
|
circle_img.fillAmount = 0;
|
|
fillVal = 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取消进度
|
|
/// </summary>
|
|
public void CancelLoading()
|
|
{
|
|
DestroyImmediate(this.gameObject);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|