Class ChatPanel
Primary workhorse for the UI. Handles dispatching Send/Received messages events.
Inheritance
Inherited Members
Namespace: LlamaSoftware.Chat.UI
Assembly: LlamaSoftware.Chat.dll
Syntax
[RequireComponent(typeof(Animator))]
public class ChatPanel : MonoBehaviour
Fields
animator
Root Animator for the ChatPanel
Declaration
protected Animator animator
Field Value
Type | Description |
---|---|
UnityEngine.Animator |
AutoFadeDelay
If AutoFadeOut is true, defines the number of seconds of inactivity before the ChatPanel becomes invisible.
Declaration
public float AutoFadeDelay
Field Value
Type | Description |
---|---|
System.Single |
AutoFadeOut
If true, after AutoFadeDelay seconds of inactivity the ChatPanel will become invisible.
Declaration
public bool AutoFadeOut
Field Value
Type | Description |
---|---|
System.Boolean |
CHANNEL_NAME_TEMPLATE
Channel name template text to replace. Cached to avoid string allocations.
Declaration
protected const string CHANNEL_NAME_TEMPLATE = "[{ChannelName}]"
Field Value
Type | Description |
---|---|
System.String |
CHANNEL_NAME_TEMPLATE_REPLACEMENT
Channel name replacement text with a Text Mesh Pro link for ChannelName. Cached to avoid string allocations.
Declaration
protected const string CHANNEL_NAME_TEMPLATE_REPLACEMENT = "<link=\"ChannelName\">[{0}]</link>"
Field Value
Type | Description |
---|---|
System.String |
ChannelClickPopup
Optional. ChatPopup for right clicking on a Channel
Declaration
public ChatPopup ChannelClickPopup
Field Value
Type | Description |
---|---|
ChatPopup |
Channels
List of available Chat Channels
Declaration
public List<ChatPanel.UIChatChannel> Channels
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<ChatPanel.UIChatChannel> |
ChatInputField
Input field to send messages from
Declaration
public TMP_InputField ChatInputField
Field Value
Type | Description |
---|---|
TMPro.TMP_InputField |
ChatMessagePool
Pool of ChatMessages. Instantiated with MaxMessages ChatMessagePrefab in Start(). Make any dynamic changes to MaxMessages in
Declaration
protected List<UIChatMessage> ChatMessagePool
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UIChatMessage> |
ChatMessagePrefab
UIChatMessage Prefab to instantiate all received messages with
Declaration
public UIChatMessage ChatMessagePrefab
Field Value
Type | Description |
---|---|
UIChatMessage |
Commands
List of the supported commands. These can be added and removed at runtime without any consequences other than the users will/won't be able to use that command any more.
Declaration
public List<Command> Commands
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<Command> |
CurrentChannelIndex
The current active index of the Channel. ChangeCurrentChannel(Int32) should be used instead of directly modifying this value.
Declaration
public int CurrentChannelIndex
Field Value
Type | Description |
---|---|
System.Int32 |
DirectMessageColor
Color that Direct Messages should show up as.
Declaration
public Color DirectMessageColor
Field Value
Type | Description |
---|---|
UnityEngine.Color |
EnableCommands
If true enables Chat Commands.
Declaration
public bool EnableCommands
Field Value
Type | Description |
---|---|
System.Boolean |
EnableEnterToFocusChat
If true, pressing UnityEngine.KeyCode.Return will fade in the Chat Panel.
Declaration
public bool EnableEnterToFocusChat
Field Value
Type | Description |
---|---|
System.Boolean |
EnableLanguageFilter
If true, will enable the Language Filter functionality. See WordFilter and WordFilters for details on Language Filtering.
Declaration
public bool EnableLanguageFilter
Field Value
Type | Description |
---|---|
System.Boolean |
FROM
"From" text used for direct messaging players. Cached to avoid string allocations.
Declaration
protected const string FROM = "From"
Field Value
Type | Description |
---|---|
System.String |
LastMessageTime
Time the last message was received. Used to determine time until the panel should auto fade out. Intended for read-only purposes outside of this class.
Declaration
public float LastMessageTime
Field Value
Type | Description |
---|---|
System.Single |
MaxMessages
Maximum number of messages to keep in the ScrollView.
Declaration
public int MaxMessages
Field Value
Type | Description |
---|---|
System.Int32 |
MESSAGE_TEMPLATE
Message template text to replace. Cached to avoid string allocations.
Declaration
protected const string MESSAGE_TEMPLATE = "{Message}"
Field Value
Type | Description |
---|---|
System.String |
MessageClickPopup
Optiona. Chat popup for right clicking on a Message.
Declaration
public ChatPopup MessageClickPopup
Field Value
Type | Description |
---|---|
ChatPopup |
MessageFormat
Format to put all messages into. Can have 4 parameters, {ChannelName}, {SenderName}, {Message} and {Timestamp}. Any of these 4 will be replaced with the appropriate data from the ChatMessage.
Declaration
public string MessageFormat
Field Value
Type | Description |
---|---|
System.String |
NOPARSE_MESSAGE
Message replacement text with
Declaration
protected const string NOPARSE_MESSAGE = "<link=\"MessageContent\"><noparse>{0}</noparse></link>"
Field Value
Type | Description |
---|---|
System.String |
PlaceholderText
Placeholder text of the ChatInputField
Declaration
public TextMeshProUGUI PlaceholderText
Field Value
Type | Description |
---|---|
TMPro.TextMeshProUGUI |
PlayerChat
Local player's Player_Chat reference
Declaration
public Player_Chat PlayerChat
Field Value
Type | Description |
---|---|
Player_Chat |
PlayerClickPopup
Optional. ChatPopup for right clicking on a Player's name
Declaration
public ChatPopup PlayerClickPopup
Field Value
Type | Description |
---|---|
ChatPopup |
PoolIndex
Index of the last used ChatMessagePool Chat Message instance. You should only read this variable.
Declaration
protected int PoolIndex
Field Value
Type | Description |
---|---|
System.Int32 |
RECALCULATE_PANEL_SIZE_METHOD_NAME
Method name for RecalculateContentPanelSize to avoid allocating new strings
Declaration
protected const string RECALCULATE_PANEL_SIZE_METHOD_NAME = "RecalculateContentPanelSize"
Field Value
Type | Description |
---|---|
System.String |
RetainPanelAcrossScenes
If true, makes the ChatPanel's UnityEngine.Canvas a DontDestroyOnLoad game object. This affects the entire parent Canvas GameObject, not just the ChatPanel. This is useful when changing active scenes but wanting to retain chat history. If you would like it to work like games like Counterstrike, where on every map change the chat history is cleared, leave this as false. Note that this must be set on Initialization. Changing this after Start() is called will have no effect.
Declaration
public bool RetainPanelAcrossScenes
Field Value
Type | Description |
---|---|
System.Boolean |
ScrollBar
ScrollBar for the ScrollView
Declaration
protected Scrollbar ScrollBar
Field Value
Type | Description |
---|---|
UnityEngine.UI.Scrollbar |
ScrollView
ScrollRect to put Chat Messages into
Declaration
public ScrollRect ScrollView
Field Value
Type | Description |
---|---|
UnityEngine.UI.ScrollRect |
ScrollViewContentArea
Area the Chat Messages will be instantiated within.
Declaration
protected VerticalLayoutGroup ScrollViewContentArea
Field Value
Type | Description |
---|---|
UnityEngine.UI.VerticalLayoutGroup |
SENDER_NAME_TEMPLATE
Sender name template text to replace. Cached to avoid string allocations.
Declaration
protected const string SENDER_NAME_TEMPLATE = "{SenderName}"
Field Value
Type | Description |
---|---|
System.String |
SENDER_NAME_TEMPLATE_REPLACEMENT
Sender name replacement text with a Text Mesh Pro link for PlayerName. Cached to avoid string allocations.
Declaration
protected const string SENDER_NAME_TEMPLATE_REPLACEMENT = "<link=\"PlayerName\">{0}</link>"
Field Value
Type | Description |
---|---|
System.String |
SERVER_TEMPLATE_REPLACEMENT
"[Server]" replacement text for server broadcast messages. Cached to avoid string allocations.
Declaration
protected const string SERVER_TEMPLATE_REPLACEMENT = "[Server]"
Field Value
Type | Description |
---|---|
System.String |
ServerMessageColor
Color that Server broadcast messages should show up in.
Declaration
public Color ServerMessageColor
Field Value
Type | Description |
---|---|
UnityEngine.Color |
SettingsPanel
Optional. Settings Panel Animator to fade in/out
Declaration
public Animator SettingsPanel
Field Value
Type | Description |
---|---|
UnityEngine.Animator |
SettingsPanelOpen
Intended for read-only purposes outside of this class. Use ToggleSettingsMenu() for changing this value.
Declaration
public bool SettingsPanelOpen
Field Value
Type | Description |
---|---|
System.Boolean |
TabChangesChannel
If true, pressing UnityEngine.KeyCode.Tab will cycle through Chat Channels when the ChatPanel has focus.
Declaration
public bool TabChangesChannel
Field Value
Type | Description |
---|---|
System.Boolean |
TIMESTAMP_TEMPLATE
Timestamp template text to replace. Cached to avoid string allocations.
Declaration
protected const string TIMESTAMP_TEMPLATE = "{Timestamp}"
Field Value
Type | Description |
---|---|
System.String |
TimestampFormat
Format to use for the {Timestamp}. Only used if MessageFormat has {Timestamp} in the template.
Declaration
public string TimestampFormat
Field Value
Type | Description |
---|---|
System.String |
TO
"To" text used for direct messaging players. Cached to avoid string allocations.
Declaration
protected const string TO = "To"
Field Value
Type | Description |
---|---|
System.String |
Visible
Whether or not the Chat Panel is visible. Intended for read-only purposes outside of this class.
Declaration
public bool Visible
Field Value
Type | Description |
---|---|
System.Boolean |
WordFilters
List of words to filter. If this list is updated after Awake() is called, you must also call RebuildWordFilterDictionary().
Declaration
public List<WordFilter> WordFilters
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<WordFilter> |
Methods
AddChatChannel(ChatChannel)
Adds a single chat Channel to the list of available Chat Channels Does not do duplicate checks.
Declaration
public virtual void AddChatChannel(ChatChannel newChannel)
Parameters
Type | Name | Description |
---|---|---|
ChatChannel | newChannel | Channel to add. |
AddChatChannels(IEnumerable<ChatChannel>)
Add the range of channels to the available Chat Channels. Does not do duplicate checks.
Declaration
public virtual void AddChatChannels(IEnumerable<ChatChannel> newChannels)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<ChatChannel> | newChannels | Channels to add. |
Awake()
Sets up internal references and builds Word Filter regular expressions
Declaration
protected virtual void Awake()
BuildChatMessagePool()
Fills ChatMessagePool with MaxMessages ChatMessagePrefab. Sets all to inactive and correctly parents them. If you change MaxMessages after Start() is called you should manually call ClearMessagePool() then BuildChatMessagePool().
Declaration
public virtual void BuildChatMessagePool()
BuildUIForPrivateMessage(Boolean, ChatMessage)
Builds the ChatMessage for private messages. Same as ReceivedMessage(ChatMessage) except colors the message for DirectMessageColor. To save on network traffic - when attempting to send a private message to a player - the sender adds the mesage to the UI immediately using this, then the receiving player gets it via the method above
Declaration
protected virtual void BuildUIForPrivateMessage(bool ReceivedMessage, ChatMessage message)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | ReceivedMessage | If the message was received or sent. Changes the "To"/"From" text |
ChatMessage | message | Message that was sent/received. |
ChangeCurrentChannel(Int32)
Changes the CurrentChannelIndex to a valid index in Channels.
Declaration
public virtual void ChangeCurrentChannel(int channelIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | channelIndex | Index to change the active channel to. |
ClearMessagePool()
Destroys all ChatMessage Prefabs in the pool and clears the ChatMessagePool. To reinstantiate them use BuildChatMessagePool().
Declaration
public virtual void ClearMessagePool()
DirectMessagePlayer(String, String)
Changes the ChatPanel to directly message this player. Does not actually send a message.
Declaration
public virtual void DirectMessagePlayer(string PlayerName, string PlayerIdentifier)
Parameters
Type | Name | Description |
---|---|---|
System.String | PlayerName | Name of the player to send a message to |
System.String | PlayerIdentifier | ID of the player to send the message to |
DoSendMessage(String)
Does the network operations to send the provided text to the server. No validation is done on the string at this point.
Declaration
protected virtual void DoSendMessage(string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | Message to send. |
FadeInChatPanel()
Fades in the Chat Panel
Declaration
protected virtual void FadeInChatPanel()
GetNextMessageFromPool()
Gets the next available UIChatMessage from the ChatMessagePool.
Declaration
protected virtual UIChatMessage GetNextMessageFromPool()
Returns
Type | Description |
---|---|
UIChatMessage | An already instantiated UIChatMessage from the pool. |
GetPlayerName(Player_Chat)
Gets the player name from the provided Player_Chat instance.
Declaration
protected virtual string GetPlayerName(Player_Chat PlayerChat)
Parameters
Type | Name | Description |
---|---|---|
Player_Chat | PlayerChat | Instance to get name from |
Returns
Type | Description |
---|---|
System.String | Name of the player |
HandleOnPointerClick(PointerEventData)
This handles finding the correct Link the player is clicking on. If they click a given link, we call that popup click handler, provided it's bound in inspector or code. If they click something that's not interactable, nothing happens.
Declaration
public virtual void HandleOnPointerClick(PointerEventData pointerEventData)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.EventSystems.PointerEventData | pointerEventData | Click event data from the UnityEngine.EventSystems.EventTrigger |
RebuildWordFilterDictionary()
Updates the regex for each entry of WordFilter. This is called automatically in Awake(). You will only need to call this if you change the WordFilters at runtime.
Declaration
public virtual void RebuildWordFilterDictionary()
RecalculateContentPanelSize()
Resizes the ScrollView's content area (ScrollViewContentArea) based on number of messages and sizes of those messages.
Declaration
protected virtual IEnumerator RecalculateContentPanelSize()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator | UnityEngine.WaitForEndOfFrame |
ReceivedMessage(ChatMessage)
Handles receiving messages from the Network and adding them to the UI. Adds a special kind of entry to the UI based on the ChatMessage received. Called by ReceivedMessage(NetworkMessage)
Declaration
public virtual void ReceivedMessage(ChatMessage message)
Parameters
Type | Name | Description |
---|---|---|
ChatMessage | message | Message received from server. |
ReceivedPrivateMessage(ChatMessage)
Builds UI for private messages. BuildUIForPrivateMessage(Boolean, ChatMessage)
Declaration
public virtual void ReceivedPrivateMessage(ChatMessage message)
Parameters
Type | Name | Description |
---|---|---|
ChatMessage | message | Message received. |
ReceivedServerBroadcastMessage(String)
Handles receiving server broadcast messages. Adds a special kind of entry to the UI with the ServerMessageColor.
Declaration
public virtual void ReceivedServerBroadcastMessage(string message)
Parameters
Type | Name | Description |
---|---|---|
System.String | message | Message |
RemoveChatChannels(IEnumerable<ChatChannel>)
Removes the range of Chat Channels from the list of available Chat Channels. If a Chat Channel is in the list to remove but the current player is not subscribed to that channel it is fine.
Declaration
public virtual void RemoveChatChannels(IEnumerable<ChatChannel> ChannelsToRemove)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<ChatChannel> | ChannelsToRemove | Channels to remove. |
RemoveChatChannels(IEnumerable<ChatPanel.UIChatChannel>)
Removes the range of Chat Channels from the list of available Chat Channels. If a Chat Channel is in the list to remove but the current player is not subscribed to that channel it is fine.
Declaration
public virtual void RemoveChatChannels(IEnumerable<ChatPanel.UIChatChannel> ChannelsToRemove)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<ChatPanel.UIChatChannel> | ChannelsToRemove | Channels to remove. |
ReplaceFilteredWords(String)
Returns a new string with all words blacklisted filtered out. Iteratively goes through WordFilters and replaces them, then returns a new string.
Declaration
protected virtual string ReplaceFilteredWords(string rawText)
Parameters
Type | Name | Description |
---|---|---|
System.String | rawText | Text to filter words from |
Returns
Type | Description |
---|---|
System.String | A new string with filtered words replaced. |
SendMessageToServer(String)
Handles Chat Commands, or sends the provided text to the server. Does nothing if text is null. Actual sending of message is done in DoSendMessage(String).
Declaration
public virtual void SendMessageToServer(string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | Message to send to the server, or chat command |
Start()
Handles RetainPanelAcrossScenes. Prevents having multiple Chat Panels in a scene. If more than 1 Chat Panel is in the scene, this method will automatically destroy the parent canvas of all other Chat Panels. if RetainPanelAcrossScenes is true on that Chat Panel.
Declaration
protected virtual void Start()
ToggleSettingsMenu()
Toggles the Settings menu open/close
Declaration
public virtual void ToggleSettingsMenu()
Update()
Handles user input, shows/hides the Chat Panel, and tab to cycle channels
Declaration
protected virtual void Update()