91 lines
2.2 KiB
C#
91 lines
2.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UI_LoadingPanel : BasePanel
|
|
{
|
|
/// <summary>
|
|
/// 当前进度
|
|
/// </summary>
|
|
private float currentProgress = 0;
|
|
|
|
/// <summary>
|
|
/// 目标进度
|
|
/// </summary>
|
|
private float targetProgress = 0;
|
|
|
|
/// <summary>
|
|
/// 是否更新
|
|
/// </summary>
|
|
private bool isUpdate = false;
|
|
|
|
/// <summary>
|
|
/// 显示
|
|
/// </summary>
|
|
public override void ShowMe()
|
|
{
|
|
EventCenter.Instance.AddEventListener<float>(Enum_EventType.UpdateProgress, UpdateProgress);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 隐藏面板
|
|
/// </summary>
|
|
public override void HideMe()
|
|
{
|
|
EventCenter.Instance.RemoveEventListener<float>(Enum_EventType.UpdateProgress, UpdateProgress);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (isUpdate)
|
|
{
|
|
if (currentProgress < targetProgress)
|
|
{
|
|
currentProgress += Time.deltaTime;
|
|
if (currentProgress >= targetProgress)
|
|
currentProgress = targetProgress;
|
|
GetControl<Slider>("Slider").value = currentProgress;
|
|
}
|
|
else
|
|
{
|
|
isUpdate = false;
|
|
if (currentProgress == 1)
|
|
UIManager.Instance.HidePanel<UI_LoadingPanel>();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新进度
|
|
/// </summary>
|
|
/// <param name="progress"></param>
|
|
private void UpdateProgress(float progress)
|
|
{
|
|
Debug.Log(progress);
|
|
targetProgress += progress;
|
|
isUpdate = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
public void Init()
|
|
{
|
|
currentProgress = 0;
|
|
targetProgress = 0;
|
|
isUpdate = false;
|
|
TB_System tB_System = GameManager.DataMgr.GetSystemInfo(GameManager.Instance.systemId);
|
|
print(tB_System);
|
|
if (tB_System == null)
|
|
return;
|
|
GameManager.ResourcesMgr.LoadAsync<Sprite>(Const.LoadBGPath + tB_System.loadName, (sprite) =>
|
|
{
|
|
this.GetComponent<Image>().sprite = sprite;
|
|
});
|
|
|
|
|
|
}
|
|
|
|
}
|