feature/fix_ui_system #16
@ -35,7 +35,7 @@ public class TimeScaleChangeEvent : IEvent
|
|||||||
public class FadeInEvent : IEvent
|
public class FadeInEvent : IEvent
|
||||||
{
|
{
|
||||||
public float Duration;
|
public float Duration;
|
||||||
public TaskCompletionSource<bool> CompletionSource;
|
public TaskCompletionSource<bool> CompletionSource = new();
|
||||||
|
|
||||||
public Task WaitAsync() => CompletionSource.Task;
|
public Task WaitAsync() => CompletionSource.Task;
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ public class FadeInEvent : IEvent
|
|||||||
public class FadeOutEvent : IEvent
|
public class FadeOutEvent : IEvent
|
||||||
{
|
{
|
||||||
public float Duration;
|
public float Duration;
|
||||||
public TaskCompletionSource<bool> CompletionSource;
|
public TaskCompletionSource<bool> CompletionSource = new();
|
||||||
|
|
||||||
public Task WaitAsync() => CompletionSource.Task;
|
public Task WaitAsync() => CompletionSource.Task;
|
||||||
}
|
}
|
||||||
|
@ -6,19 +6,24 @@ namespace DDD
|
|||||||
public class FadeUi : MonoBehaviour, IEventHandler<FadeInEvent>, IEventHandler<FadeOutEvent>
|
public class FadeUi : MonoBehaviour, IEventHandler<FadeInEvent>, IEventHandler<FadeOutEvent>
|
||||||
{
|
{
|
||||||
private CanvasGroup _canvasGroup;
|
private CanvasGroup _canvasGroup;
|
||||||
|
private GameObject _panel;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
_canvasGroup = GetComponent<CanvasGroup>();
|
_canvasGroup = GetComponent<CanvasGroup>();
|
||||||
|
_panel = transform.Find(CommonConstants.Panel).gameObject;
|
||||||
|
|
||||||
_canvasGroup.alpha = 0f;
|
_canvasGroup.alpha = 0f;
|
||||||
_canvasGroup.gameObject.SetActive(false);
|
_panel.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEnable()
|
||||||
|
{
|
||||||
EventBus.Register<FadeInEvent>(this);
|
EventBus.Register<FadeInEvent>(this);
|
||||||
EventBus.Register<FadeOutEvent>(this);
|
EventBus.Register<FadeOutEvent>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDisable()
|
||||||
{
|
{
|
||||||
EventBus.Unregister<FadeInEvent>(this);
|
EventBus.Unregister<FadeInEvent>(this);
|
||||||
EventBus.Unregister<FadeOutEvent>(this);
|
EventBus.Unregister<FadeOutEvent>(this);
|
||||||
@ -30,16 +35,14 @@ await _canvasGroup.DOFade(0f, evt.Duration)
|
|||||||
.SetUpdate(true)
|
.SetUpdate(true)
|
||||||
.AsyncWaitForCompletion();
|
.AsyncWaitForCompletion();
|
||||||
|
|
||||||
_canvasGroup.blocksRaycasts = false;
|
_panel.SetActive(false);
|
||||||
_canvasGroup.gameObject.SetActive(false);
|
|
||||||
|
|
||||||
evt.CompletionSource.SetResult(true);
|
evt.CompletionSource.SetResult(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void Invoke(FadeOutEvent evt)
|
public async void Invoke(FadeOutEvent evt)
|
||||||
{
|
{
|
||||||
_canvasGroup.gameObject.SetActive(true);
|
_panel.SetActive(true);
|
||||||
_canvasGroup.blocksRaycasts = true;
|
|
||||||
|
|
||||||
await _canvasGroup.DOFade(1f, evt.Duration)
|
await _canvasGroup.DOFade(1f, evt.Duration)
|
||||||
.SetUpdate(true)
|
.SetUpdate(true)
|
||||||
|
Loading…
Reference in New Issue
Block a user