48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
using TankAndHealerStudioAssets;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace UltimateChatBoxExample
|
|
{
|
|
public class ChatStylesExample : MonoBehaviour
|
|
{
|
|
public UltimateChatBox chatBox;
|
|
|
|
public string myUsername = "LocalPlayer";
|
|
|
|
public UltimateChatBox.ChatStyle customStyle = new UltimateChatBox.ChatStyle();
|
|
|
|
private List<UltimateChatBox.ChatStyle> chatStyles = new List<UltimateChatBox.ChatStyle>();
|
|
|
|
private int currentChatTypeIndex;
|
|
|
|
private void Start()
|
|
{
|
|
chatStyles = new List<UltimateChatBox.ChatStyle>();
|
|
chatStyles.Add(UltimateChatBoxStyles.boldUsername);
|
|
chatStyles.Add(UltimateChatBoxStyles.whisperUsername);
|
|
chatStyles.Add(UltimateChatBoxStyles.blueUsername);
|
|
chatStyles.Add(UltimateChatBoxStyles.greenUsername);
|
|
chatStyles.Add(customStyle);
|
|
chatBox.OnInputFieldSubmitted += delegate(string message)
|
|
{
|
|
chatBox.RegisterChat(myUsername, message, chatStyles[currentChatTypeIndex]);
|
|
};
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (chatBox.IsEnabled && InputSystem.GetDevice<Keyboard>().tabKey.wasPressedThisFrame)
|
|
{
|
|
currentChatTypeIndex++;
|
|
if (currentChatTypeIndex >= chatStyles.Count)
|
|
{
|
|
currentChatTypeIndex = 0;
|
|
}
|
|
chatBox.ExtraImageColor = ((chatStyles[currentChatTypeIndex].usernameColor == Color.clear) ? Color.white : chatStyles[currentChatTypeIndex].usernameColor);
|
|
}
|
|
}
|
|
}
|
|
}
|