Aimbot-PPO/Aimbot-PPO-MultiScene/Assets/Script/InGame/InGameMessages.cs
Koha9 1aaf6c7069 Add Message Box & TimeLimit Change Button
Add Message Box & TimeLimit Change Button.
Start Using XXManager to keep script, now changed in UIManger GameObject.
2022-09-07 06:48:37 +09:00

82 lines
2.2 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class InGameMessages : MonoBehaviour
{
public GameObject MessageBox; // scrollView contents
public GameObject TextPrefab; // TextPrefab
public int maxMassages = 25;
public Color infoColor = Color.white;
public Color successColor = Color.green;
public Color errorColor = Color.red;
public Color warningColor = Color.yellow;
[System.NonSerialized]List<Message> messageList = new List<Message>();
public void SendMessagetoBox(string text,Message.MessageType messageType = Message.MessageType.info)
{
if (messageList.Count > maxMassages)
{
// keep mesages under maxMassages
Destroy(messageList[0].textOBJ.gameObject);
messageList.Remove(messageList[0]);
}
// add timestamp
string date = "[" + DateTime.Now.ToString("MMdd_hh:mm:ss") + "] ";
text = date + text;
Message newMessage = new Message();
newMessage.text = text;
GameObject newText = Instantiate(TextPrefab, MessageBox.transform);
newMessage.textOBJ = newText.GetComponent<Text>();
newMessage.textOBJ.text = newMessage.text;
newMessage.textOBJ.color = MessageTypeColor(messageType);
messageList.Add(newMessage);
}
// parse messageType to Color
Color MessageTypeColor(Message.MessageType messageType)
{
Color thisColor = infoColor;
switch (messageType)
{
case Message.MessageType.info:
thisColor = infoColor;
break;
case Message.MessageType.success:
thisColor = successColor;
break;
case Message.MessageType.error:
thisColor = errorColor;
break;
case Message.MessageType.warnning:
thisColor = warningColor;
break;
}
return thisColor;
}
}
// Message Class
[System.Serializable]
public class Message
{
public string text;
public Text textOBJ;
public MessageType messageType;
public enum MessageType
{
info,
success,
error,
warnning
}
}