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() { } /// /// 初始化 /// /// /// 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(); 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; } /// /// 更新进度显示 /// /// 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; } /// /// 重置进度 /// public void RewindLoading() { circle_img.fillAmount = 0; fillVal = 0; } /// /// 取消进度 /// public void CancelLoading() { DestroyImmediate(this.gameObject); } } }