84 lines
1.7 KiB
C#
84 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
|
|
public class ChatMessage : MonoBehaviour
|
|
{
|
|
|
|
public Image modIcon;
|
|
private TMP_Text tMessage;
|
|
|
|
float pos;
|
|
|
|
//server message
|
|
public void SetData(string message)
|
|
{
|
|
modIcon = gameObject.GetComponentInChildren<Image>();
|
|
modIcon.color = new Color(1.0f, 1.0f, 1.0f, 0.0f);
|
|
tMessage = GetComponent<TMP_Text>();
|
|
tMessage.text = message;
|
|
}
|
|
|
|
//unused.
|
|
//public float GetSizeOfWord(TMP_Text text, string word)
|
|
//{
|
|
// float width = 0.0f;
|
|
// CharacterInfo charInfo;
|
|
// foreach (char c in word)
|
|
// {
|
|
// text.font.GetCharacterInfo(c, out charInfo, text.fontSize);
|
|
|
|
// width += charInfo.advance;
|
|
|
|
// }
|
|
// return width;
|
|
//}
|
|
|
|
//player message
|
|
public void setData(int rights, string username, string message)
|
|
{
|
|
modIcon = gameObject.GetComponentInChildren<Image>();
|
|
|
|
bool icon = false;
|
|
|
|
if (rights == 2)
|
|
{
|
|
modIcon.gameObject.SetActive(true);
|
|
modIcon.sprite = OnDemandLoader.Load<Sprite>("Sprites/moderator");
|
|
icon = true;
|
|
}
|
|
if (rights == 3)
|
|
{
|
|
modIcon.gameObject.SetActive(true);
|
|
modIcon.sprite = OnDemandLoader.Load<Sprite>("Sprites/staff");
|
|
icon = true;
|
|
}
|
|
if (rights == 4)
|
|
{
|
|
modIcon.gameObject.SetActive(true);
|
|
modIcon.sprite = OnDemandLoader.Load<Sprite>("Sprites/admin");
|
|
icon = true;
|
|
}
|
|
if (rights >= 5)
|
|
{
|
|
modIcon.sprite = OnDemandLoader.Load<Sprite>("Sprites/owner");
|
|
modIcon.gameObject.SetActive(true);
|
|
icon = true;
|
|
}
|
|
if (rights <= 1) {
|
|
modIcon.gameObject.SetActive(false);
|
|
}
|
|
//set and position username
|
|
tMessage = gameObject.GetComponent<TMP_Text>();
|
|
tMessage.text = username + ": " + message;
|
|
|
|
if (icon)
|
|
{
|
|
tMessage.text = " " + tMessage.text;
|
|
}
|
|
|
|
}
|
|
}
|