61 lines
1.5 KiB
C#
61 lines
1.5 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 targetProgress;
|
|
public bool isLoading = false;
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
loadSlider = GetControl<Slider>("loadSlider");
|
|
}
|
|
|
|
public override void ShowMe()
|
|
{
|
|
base.ShowMe();
|
|
Debug.Log("UI_LoadingPanel ShowMe");
|
|
Bootstrap.Instance.eventCenter.AddEventListener<float>(Enum_EventType.UpdateProgress, UpdateProgress);
|
|
|
|
}
|
|
|
|
public override void HideMe()
|
|
{
|
|
base.HideMe();
|
|
Debug.Log("UI_LoadingPanel HideMe");
|
|
Bootstrap.Instance.eventCenter.RemoveEventListener<float>(Enum_EventType.UpdateProgress, UpdateProgress);
|
|
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (isLoading)
|
|
{
|
|
if (currentProgress < targetProgress)
|
|
{
|
|
currentProgress += Time.deltaTime;
|
|
if (currentProgress >= targetProgress)
|
|
currentProgress = targetProgress;
|
|
loadSlider.value = currentProgress;
|
|
}
|
|
else
|
|
{
|
|
isLoading = false;
|
|
Bootstrap.Instance.uiManager.HidePanel<UI_LoadingPanel>();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void UpdateProgress(float progress)
|
|
{
|
|
isLoading = true;
|
|
targetProgress += progress;
|
|
}
|
|
}
|
|
|