TG9six 03a642d635 first push
first push
2025-09-06 17:17:39 +04:00

61 lines
1.6 KiB
C#

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<GameObject>("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<ChatMessage>().SetData(text);
}
else
{
string nameColoured = $"<b>[</b><color=orange>{name}</color><b>]</b>";
string boldMessage = $"<b>{text}</b>";
m.GetComponent<ChatMessage>().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<GameObject> messageList = new List<GameObject>();
private GameObject chatPanel;
private GameObject chatMessage;
}