using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class LoadingWin : UIBase { protected int currentProgress = 0; protected int targetProgress = 0; protected Text titleText; protected Text tipsText; protected Image progressBar; protected Text progressText; protected override void InitComponent() { base.InitComponent(); titleText = transform.Find("Text_Loading").GetComponent(); tipsText = transform.Find("Text_Tips").GetComponent(); progressBar = transform.Find("Img_Progress/Img_Foreground").GetComponent(); progressText = transform.Find("Text_Progress").GetComponent(); } protected override void OnPreOpen() { base.OnPreOpen(); currentProgress = targetProgress = 0; Refresh(); } protected override void OnPreClose() { base.OnPreClose(); } public override void Refresh() { base.Refresh(); UpdateProgress(); } public void SetProgress(float value, bool directly = false) { if (directly) { currentProgress = targetProgress = (int)(value * 100); UpdateProgress(); } else { currentProgress = (int)(value * 100); } } protected void UpdateProgress() { progressText.text = currentProgress + "%"; progressBar.fillAmount = currentProgress / 100f; } protected void Update() { if (currentProgress < targetProgress) { currentProgress = (int)Mathf.Lerp(currentProgress, targetProgress, 0.1f); UpdateProgress(); } } }