using System.Collections; using Cute; using UnityEngine; using Wizard; public class LoadingBase : UIBase { [SerializeField] private GameObject mainObj; [SerializeField] private UILabel ParLabel; [SerializeField] private UIGauge LoadingBar; [SerializeField] protected UILabel LoadTitleLabel; [SerializeField] protected UILabel LoadTextLabel; [SerializeField] private UITexture BGTexture; private int loadIndex; private string comment = ""; private Coroutine coroutine; protected bool isLabelUpdate = true; private float loadAssetsMaxNum; public bool IsOpponentWait; public float CurrentProgress { get; private set; } public bool MaximumValueFixedMode { get; set; } private void Awake() { MaximumValueFixedMode = false; CurrentProgress = 0f; } protected virtual void Start() { if ((bool)LoadTextLabel) { comment = Data.SystemText.Get("System_0001"); } if ((bool)ParLabel) { ParLabel.text = "0%"; } if ((bool)mainObj) { mainObj.SetActive(value: false); mainObj.GetComponent().uiCamera = UIManager.GetInstance().UIRootLoadingCamera; } OnEnable(); } public virtual void fadeOutLoading() { } public void closeLoading() { if (base.gameObject != null) { Object.Destroy(base.gameObject); } } private void OnEnable() { if (coroutine == null) { setParLabelActive(isactive: true); coroutine = StartCoroutine(lodingAnimation()); } } private void OnDisable() { if (coroutine != null) { StopCoroutine(coroutine); coroutine = null; } IsOpponentWait = false; } public void setMaxAssetsNum(bool enable, float num) { MaximumValueFixedMode = enable; loadAssetsMaxNum = num; } public void setLoadingComment(string comment) { this.comment = comment; } public void setParLabelActive(bool isactive) { if ((bool)ParLabel && ParLabel.gameObject.activeSelf != isactive) { ParLabel.gameObject.SetActive(isactive); } } public IEnumerator lodingAnimation() { if ((bool)mainObj) { mainObj.SetActive(value: false); } WaitForSeconds waitTime = new WaitForSeconds(0.05f); while (true) { float num = ((!MaximumValueFixedMode) ? (Toolbox.ResourcesManager.GetDownloadMaxSize() + (float)Toolbox.ResourcesManager.GetLoadingMax()) : loadAssetsMaxNum); float num2 = CalculateProgress(); CurrentProgress = ((num == 0f) ? 0f : (num2 / num)); if (CurrentProgress > 1f) { CurrentProgress = 1f; } if ((bool)ParLabel) { ParLabel.text = $"{CurrentProgress * 100f:f1}%"; } if ((bool)LoadingBar) { LoadingBar.Value = CurrentProgress; } string str = ""; for (int i = 0; i < loadIndex; i++) { str += "."; } if (Data.SystemText == null) { yield return 0; } if (isLabelUpdate && (bool)LoadTextLabel) { LoadTextLabel.text = comment + str; } loadIndex++; if (loadIndex >= 4) { loadIndex = 0; } yield return waitTime; if ((bool)mainObj && !mainObj.activeSelf) { mainObj.SetActive(value: true); mainObj.GetComponent().enabled = true; } if (IsOpponentWait) { if (CurrentProgress >= 1f) { setLoadingComment(Data.SystemText.Get("Battle_0408")); setParLabelActive(isactive: false); } else { setLoadingComment(Data.SystemText.Get("System_0001")); setParLabelActive(isactive: true); } } } } protected virtual float CalculateProgress() { return Toolbox.ResourcesManager.GetLoadingCompleted(); } }