using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UI_LoadingPanel : BasePanel
{
///
/// 当前进度
///
private float currentProgress = 0;
///
/// 目标进度
///
private float targetProgress = 0;
///
/// 是否更新
///
private bool isUpdate = false;
///
/// 显示
///
public override void ShowMe()
{
EventCenter.Instance.AddEventListener(Enum_EventType.UpdateProgress, UpdateProgress);
}
///
/// 隐藏面板
///
public override void HideMe()
{
EventCenter.Instance.RemoveEventListener(Enum_EventType.UpdateProgress, UpdateProgress);
}
private void Update()
{
if (isUpdate)
{
if (currentProgress < targetProgress)
{
currentProgress += Time.deltaTime;
if (currentProgress >= targetProgress)
currentProgress = targetProgress;
GetControl("Slider").value = currentProgress;
}
else
{
isUpdate = false;
if (currentProgress == 1)
GameManager.UIMgr.HidePanel();
}
}
}
///
/// 更新进度
///
///
private void UpdateProgress(float progress)
{
Debug.Log(progress);
targetProgress += progress;
isUpdate = true;
}
///
/// 初始化
///
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(Const.LoadBGPath + tB_System.loadName, (sprite) =>
{
this.GetComponent().sprite = sprite;
});
}
}