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)
UIManager.Instance.HidePanel();
}
}
}
///
/// 更新进度
///
///
private void UpdateProgress(float progress)
{
Debug.Log(progress);
targetProgress += progress;
isUpdate = true;
}
public void Init()
{
currentProgress = 0;
targetProgress = 0;
isUpdate = false;
}
}