diff options
Diffstat (limited to 'Assets/Scripts/SoulCoreGameLoop/UI/MessageBox.cs')
| -rw-r--r-- | Assets/Scripts/SoulCoreGameLoop/UI/MessageBox.cs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Assets/Scripts/SoulCoreGameLoop/UI/MessageBox.cs b/Assets/Scripts/SoulCoreGameLoop/UI/MessageBox.cs new file mode 100644 index 0000000..6680dee --- /dev/null +++ b/Assets/Scripts/SoulCoreGameLoop/UI/MessageBox.cs @@ -0,0 +1,41 @@ +using System; +using UnityEngine; +using TMPro; + +namespace SoulCoreGameLoop.UI +{ + [RequireComponent(typeof(Animator))] + public class MessageBox : MonoBehaviour, IUIEventSender<Message> + { + private static readonly int TriggerPlay = Animator.StringToHash("Play"); + + public TMP_Text messageText; + private Animator _animator; + + private void Awake() + { + _animator = GetComponent<Animator>(); + UIEventListener.Register(this); + } + + private void OnDestroy() + => UIEventListener.Unregister<Message>(); + + + public void OnReceive(Message evt) + { + messageText.text = evt.MessageText; + _animator.SetTrigger(TriggerPlay); + } + } + + public struct Message + { + public readonly string MessageText; + + public Message(string messageText) + { + MessageText = messageText; + } + } +}
\ No newline at end of file |
