Files
Unity20GameJam/Assets/Gameplay/Scripts/UI/LoadingPanel.cs
2025-11-08 15:42:56 +08:00

75 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cysharp.Threading.Tasks;
using A2W;
using DG.Tweening;
public class LoadingPanel : UIPanel, ITransition
{
[SerializeField] CanvasGroup canvasGroup;
bool isDirty;
public override void Init()
{
isDirty = false;
canvasGroup.alpha = 0;
}
public override async UniTask Show()
{
isDirty = true;
Tween tween = canvasGroup.DOFade(1, 0.2f);
while (tween != null && tween.active && !tween.IsComplete())
{
await UniTask.Yield();
}
//canvasGroup.alpha = 1;
isDirty = false;
canvasGroup.blocksRaycasts = false;
}
public override async UniTask Hide()
{
isDirty = true;
Tween tween = canvasGroup.DOFade(0, 0.2f);
while (tween != null && tween.active && !tween.IsComplete())
{
await UniTask.Yield();
}
//canvasGroup.alpha = 0;
isDirty = false;
canvasGroup.blocksRaycasts = false;
}
public void Init(Transform parent)
{
}
public void Begin()
{
UIManager.instance.ShowPanel<LoadingPanel>();
}
public void Finish()
{
UIManager.instance.HidePanel<LoadingPanel>();
}
public bool IsDone()
{
return !isDirty;
}
}