54 lines
1.4 KiB
C#
54 lines
1.4 KiB
C#
using DG.Tweening;
|
|
using UnityEngine;
|
|
|
|
namespace DDD
|
|
{
|
|
public class FadeUi : MonoBehaviour, IEventHandler<FadeInEvent>, IEventHandler<FadeOutEvent>
|
|
{
|
|
private CanvasGroup _canvasGroup;
|
|
private GameObject _panel;
|
|
|
|
private void Awake()
|
|
{
|
|
_canvasGroup = GetComponent<CanvasGroup>();
|
|
_panel = transform.Find(CommonConstants.Panel).gameObject;
|
|
|
|
_canvasGroup.alpha = 0f;
|
|
_panel.SetActive(false);
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
EventBus.Register<FadeInEvent>(this);
|
|
EventBus.Register<FadeOutEvent>(this);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
EventBus.Unregister<FadeInEvent>(this);
|
|
EventBus.Unregister<FadeOutEvent>(this);
|
|
}
|
|
|
|
public async void Invoke(FadeInEvent evt)
|
|
{
|
|
await _canvasGroup.DOFade(0f, evt.Duration)
|
|
.SetUpdate(true)
|
|
.AsyncWaitForCompletion();
|
|
|
|
_panel.SetActive(false);
|
|
|
|
evt.CompletionSource.SetResult(true);
|
|
}
|
|
|
|
public async void Invoke(FadeOutEvent evt)
|
|
{
|
|
_panel.SetActive(true);
|
|
|
|
await _canvasGroup.DOFade(1f, evt.Duration)
|
|
.SetUpdate(true)
|
|
.AsyncWaitForCompletion();
|
|
|
|
evt.CompletionSource.SetResult(true);
|
|
}
|
|
}
|
|
} |