using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; public class ChatBox : MonoBehaviour { [System.NonSerialized] public bool UsingChatBox = false; [SerializeField] private TMP_Text placeHolderText; // Start is called before the first frame update void Start() { chatMessage = OnDemandLoader.Load("Prefabs/Interfaces/chatMessage"); chatPanel = GameObject.Find("ChatBoxContentPanel"); placeHolderText.text = InputMessageHandler.Instance.Interpolate("Press [[Chat]] to chat."); } public void SendMessageToChat(int rank, string name, string text) { if (messageList.Count >= MAX_MESSAGES) { Destroy(messageList[0]); messageList.Remove(messageList[0]); } GameObject m = Instantiate(chatMessage, chatPanel.transform); if (rank == -1) { m.GetComponent().SetData(text); } else { string nameColoured = $"[{name}]"; string boldMessage = $"{text}"; m.GetComponent().setData(rank, nameColoured, boldMessage); } messageList.Add(m); } public void ClearChat() { foreach (GameObject message in messageList) { Destroy(message); } messageList.Clear(); } private const int MAX_MESSAGES = 100; private List messageList = new List(); private GameObject chatPanel; private GameObject chatMessage; }