61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
using TMPro;
|
|
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;
|
|
[SerializeField] private LocalizeStringEvent _textLabelLocalizeStringEvent;
|
|
|
|
[SerializeField] private Color _canInteractTextColor = Color.white;
|
|
[SerializeField] private Color _cannotInteractTextColor = Color.gray2;
|
|
|
|
private LocalizedString _previousLocalizedString;
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
|
|
_filledImage.fillAmount = 0f;
|
|
|
|
EventBus.Register<ShowInteractionUiEvent>(this);
|
|
EventBus.Register<HideInteractionUiEvent>(this);
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
base.OnDestroy();
|
|
|
|
EventBus.Unregister<ShowInteractionUiEvent>(this);
|
|
EventBus.Unregister<HideInteractionUiEvent>(this);
|
|
}
|
|
|
|
public void Invoke(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();
|
|
}
|
|
}
|
|
|
|
public void Invoke(HideInteractionUiEvent evt)
|
|
{
|
|
_filledImage.fillAmount = 0f;
|
|
ClosePanel();
|
|
}
|
|
}
|
|
} |