using UnityEngine; using TMPro; namespace XRMultiplayer { /// /// Represents a message text on a message board. /// public class MessageText : MonoBehaviour { /// /// The text component to display the message. /// [SerializeField] private TMP_Text text; /// /// The text component to display the time. /// [SerializeField] private TMP_Text timeText; /// /// Use this value for any headers or offsets that need to be added to the message text when calculating height. /// [SerializeField, Tooltip("Use this value for any headers or offsets that need to be added to the message text when calculating height.")] float m_BonusScale = 1.0f; [SerializeField] RectTransform m_RectTransform; /// /// Sets the message and time to be displayed. /// /// The message to be displayed. /// The time to be displayed. public void SetMessage(string message, string time) { text.SetText(message); timeText.SetText(time); Canvas.ForceUpdateCanvases(); SnapHeight(); } [ContextMenu("Snap Height")] void SnapHeight() { m_RectTransform.sizeDelta = new Vector2(m_RectTransform.sizeDelta.x, text.preferredHeight * m_BonusScale /* * text.fontSize*/); Canvas.ForceUpdateCanvases(); } } }