ProjectDDD/Assets/_DDD/_Scripts/GameUi/BaseUi/InteractionUis/InteractionMessageUi.cs

77 lines
2.3 KiB
C#
Raw Normal View History

using TMPro;
2025-08-14 08:21:17 +00:00
using Unity.VisualScripting;
2025-08-05 10:46:36 +00:00
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Components;
using UnityEngine.UI;
namespace DDD
{
public class InteractionMessageUi : BaseUi, IEventHandler<ShowInteractionUiEvent>, IEventHandler<HideInteractionUiEvent>
{
[SerializeField] private Image _filledImage;
[SerializeField] private TextMeshProUGUI _textLabel;
2025-08-05 10:46:36 +00:00
[SerializeField] private LocalizeStringEvent _textLabelLocalizeStringEvent;
2025-08-14 08:21:17 +00:00
[SerializeField] private Color _canInteractTextColor = Color.white;
[SerializeField] private Color _cannotInteractTextColor = Color.gray2;
2025-08-05 10:46:36 +00:00
private LocalizedString _previousLocalizedString;
2025-08-14 08:21:17 +00:00
protected override void Awake()
2025-08-05 10:46:36 +00:00
{
2025-08-14 08:21:17 +00:00
base.Awake();
2025-08-05 10:46:36 +00:00
_filledImage.fillAmount = 0f;
2025-08-14 08:21:17 +00:00
}
2025-08-21 07:25:27 +00:00
2025-08-24 11:44:32 +00:00
protected override void OnOpenedEvents()
2025-08-14 08:21:17 +00:00
{
2025-08-24 11:44:32 +00:00
base.OnOpenedEvents();
2025-08-14 08:21:17 +00:00
2025-08-05 10:46:36 +00:00
EventBus.Register<ShowInteractionUiEvent>(this);
EventBus.Register<HideInteractionUiEvent>(this);
}
2025-08-24 11:44:32 +00:00
protected override void OnClosedEvents()
2025-08-05 10:46:36 +00:00
{
2025-08-24 11:44:32 +00:00
base.OnClosedEvents();
2025-08-14 08:21:17 +00:00
2025-08-05 10:46:36 +00:00
EventBus.Unregister<ShowInteractionUiEvent>(this);
EventBus.Unregister<HideInteractionUiEvent>(this);
}
public void Invoke(ShowInteractionUiEvent evt)
2025-08-14 08:21:17 +00:00
{
ShowInteractionUiEvent(evt);
}
public void Invoke(HideInteractionUiEvent evt)
{
HideInteractionUiEvent(evt);
}
private void ShowInteractionUiEvent(ShowInteractionUiEvent evt)
2025-08-05 10:46:36 +00:00
{
_previousLocalizedString = LocalizationManager.Instance.GetLocalizedString(evt.TextKey);
_textLabel.color = evt.CanInteract ? _canInteractTextColor : _cannotInteractTextColor;
2025-08-14 08:21:17 +00:00
2025-08-05 10:46:36 +00:00
if (_textLabelLocalizeStringEvent.StringReference != _previousLocalizedString)
{
_textLabelLocalizeStringEvent.StringReference = _previousLocalizedString;
}
_filledImage.fillAmount = evt.HoldProgress;
if (_panel.activeInHierarchy == false)
{
OpenPanel();
}
}
2025-08-14 08:21:17 +00:00
private void HideInteractionUiEvent(HideInteractionUiEvent evt)
2025-08-05 10:46:36 +00:00
{
_filledImage.fillAmount = 0f;
ClosePanel();
}
}
}