aboutsummaryrefslogtreecommitdiff
path: root/Assets/Scripts/SoulCoreGameLoop/UI/MessageBox.cs
blob: 6680dee5b1dbe394a1998fb56af29f612738837b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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;
        }
    }
}