TestCodeStructure/Assets/Scripts/UI/UIPanel/UI_LoadingPanel.cs

60 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UI_LoadingPanel : BasePanel
{
public Slider loadSlider;
private float currentProgress = 0;
public float speed;
public bool isLoading = false;
protected override void Awake()
{
base.Awake();
loadSlider = GetControl<Slider>("loadSlider");
}
public override void ShowMe()
{
base.ShowMe();
Bootstrap.Instance.eventCenter.AddEventListener<float>(Enum_EventType.UpdateProgress, UpdateProgress);
}
public override void HideMe()
{
base.HideMe();
loadSlider.value = 0;
currentProgress = 0;
speed = 0;
Bootstrap.Instance.eventCenter.RemoveEventListener<float>(Enum_EventType.UpdateProgress, UpdateProgress);
}
private void Update()
{
if (isLoading)
{
if (currentProgress < 0.98f)
{
currentProgress += Time.deltaTime * speed;
loadSlider.value = currentProgress;
}
else
{
isLoading = false;
HideMe();
}
}
}
private void UpdateProgress(float speed)
{
isLoading = true;
this.speed = speed;
}
}