using TMPro; using Unity.VisualScripting; using UnityEngine; using UnityEngine.Localization; using UnityEngine.Localization.Components; using UnityEngine.UI; namespace DDD { public class InteractionMessageUi : BaseUi, IEventHandler, IEventHandler { [SerializeField] private Image _filledImage; [SerializeField] private TextMeshProUGUI _textLabel; [SerializeField] private LocalizeStringEvent _textLabelLocalizeStringEvent; [SerializeField] private Color _canInteractTextColor = Color.white; [SerializeField] private Color _cannotInteractTextColor = Color.gray2; private LocalizedString _previousLocalizedString; protected override void Awake() { base.Awake(); _filledImage.fillAmount = 0f; } protected override void TryRegister() { base.TryRegister(); EventBus.Register(this); EventBus.Register(this); } protected override void TryUnregister() { base.TryUnregister(); EventBus.Unregister(this); EventBus.Unregister(this); } 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); _textLabel.color = evt.CanInteract ? _canInteractTextColor : _cannotInteractTextColor; if (_textLabelLocalizeStringEvent.StringReference != _previousLocalizedString) { _textLabelLocalizeStringEvent.StringReference = _previousLocalizedString; } _filledImage.fillAmount = evt.HoldProgress; if (_panel.activeInHierarchy == false) { OpenPanel(); } } private void HideInteractionUiEvent(HideInteractionUiEvent evt) { _filledImage.fillAmount = 0f; ClosePanel(); } } }