baseUi 기반으로 ui들 수정

This commit is contained in:
NTG 2025-08-14 17:21:17 +09:00
parent c2ecdad492
commit 9572e9335a
3 changed files with 55 additions and 23 deletions

View File

@ -16,6 +16,11 @@ protected virtual void Awake()
_panel = transform.Find(CommonConstants.Panel).gameObject; _panel = transform.Find(CommonConstants.Panel).gameObject;
} }
protected virtual void OnEnable()
{
}
protected virtual void Start() protected virtual void Start()
{ {
TryRegister(); TryRegister();
@ -27,6 +32,11 @@ protected virtual void Update()
} }
protected virtual void OnDisable()
{
}
protected virtual void OnDestroy() protected virtual void OnDestroy()
{ {
TryUnregister(); TryUnregister();

View File

@ -1,48 +1,54 @@
using System.Threading.Tasks;
using DG.Tweening; using DG.Tweening;
using UnityEngine; using UnityEngine;
namespace DDD namespace DDD
{ {
public class FadeUi : MonoBehaviour, IEventHandler<FadeInEvent>, IEventHandler<FadeOutEvent> public class FadeUi : BaseUi, IEventHandler<FadeInEvent>, IEventHandler<FadeOutEvent>
{ {
private CanvasGroup _canvasGroup; protected override void Awake()
private GameObject _panel;
private void Awake()
{ {
_canvasGroup = GetComponent<CanvasGroup>(); base.Awake();
_panel = transform.Find(CommonConstants.Panel).gameObject;
_canvasGroup.alpha = 0f; _canvasGroup.alpha = 0f;
_panel.SetActive(false);
} }
private void OnEnable() protected override void TryRegister()
{ {
EventBus.Register<FadeInEvent>(this); EventBus.Register<FadeInEvent>(this);
EventBus.Register<FadeOutEvent>(this); EventBus.Register<FadeOutEvent>(this);
} }
private void OnDisable() protected override void TryUnregister()
{ {
EventBus.Unregister<FadeInEvent>(this); EventBus.Unregister<FadeInEvent>(this);
EventBus.Unregister<FadeOutEvent>(this); EventBus.Unregister<FadeOutEvent>(this);
} }
public async void Invoke(FadeInEvent evt) public void Invoke(FadeInEvent evt)
{
_ = FadeInAsync(evt);
}
public void Invoke(FadeOutEvent evt)
{
_ = FadeOutAsync(evt);
}
private async Task FadeInAsync(FadeInEvent evt)
{ {
await _canvasGroup.DOFade(0f, evt.Duration) await _canvasGroup.DOFade(0f, evt.Duration)
.SetUpdate(true) .SetUpdate(true)
.AsyncWaitForCompletion(); .AsyncWaitForCompletion();
_panel.SetActive(false); ClosePanel();
evt.CompletionSource.SetResult(true); evt.CompletionSource.SetResult(true);
} }
public async void Invoke(FadeOutEvent evt) private async Task FadeOutAsync(FadeOutEvent evt)
{ {
_panel.SetActive(true); OpenPanel();
await _canvasGroup.DOFade(1f, evt.Duration) await _canvasGroup.DOFade(1f, evt.Duration)
.SetUpdate(true) .SetUpdate(true)

View File

@ -1,4 +1,5 @@
using TMPro; using TMPro;
using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
using UnityEngine.Localization; using UnityEngine.Localization;
using UnityEngine.Localization.Components; using UnityEngine.Localization.Components;
@ -17,25 +18,40 @@ public class InteractionMessageUi : BaseUi, IEventHandler<ShowInteractionUiEvent
private LocalizedString _previousLocalizedString; private LocalizedString _previousLocalizedString;
protected override void Start() protected override void Awake()
{ {
base.Start(); base.Awake();
_filledImage.fillAmount = 0f; _filledImage.fillAmount = 0f;
}
protected override void TryRegister()
{
base.TryRegister();
EventBus.Register<ShowInteractionUiEvent>(this); EventBus.Register<ShowInteractionUiEvent>(this);
EventBus.Register<HideInteractionUiEvent>(this); EventBus.Register<HideInteractionUiEvent>(this);
} }
protected override void OnDestroy() protected override void TryUnregister()
{ {
base.OnDestroy(); base.TryUnregister();
EventBus.Unregister<ShowInteractionUiEvent>(this); EventBus.Unregister<ShowInteractionUiEvent>(this);
EventBus.Unregister<HideInteractionUiEvent>(this); EventBus.Unregister<HideInteractionUiEvent>(this);
} }
public void Invoke(ShowInteractionUiEvent evt) public void Invoke(ShowInteractionUiEvent evt)
{
ShowInteractionUiEvent(evt);
}
public void Invoke(HideInteractionUiEvent evt)
{
HideInteractionUiEvent(evt);
}
private void ShowInteractionUiEvent(ShowInteractionUiEvent evt)
{ {
_previousLocalizedString = LocalizationManager.Instance.GetLocalizedString(evt.TextKey); _previousLocalizedString = LocalizationManager.Instance.GetLocalizedString(evt.TextKey);
_textLabel.color = evt.CanInteract ? _canInteractTextColor : _cannotInteractTextColor; _textLabel.color = evt.CanInteract ? _canInteractTextColor : _cannotInteractTextColor;
@ -52,7 +68,7 @@ public void Invoke(ShowInteractionUiEvent evt)
} }
} }
public void Invoke(HideInteractionUiEvent evt) private void HideInteractionUiEvent(HideInteractionUiEvent evt)
{ {
_filledImage.fillAmount = 0f; _filledImage.fillAmount = 0f;
ClosePanel(); ClosePanel();