ChatInput
Text input component for the chat UI. Wraps a TMP_InputField and manages its activation state, message submission to the Chat singleton, and visual visibility via a CanvasGroup. Coordinates with ChatHUD for focus lifecycle.
Definition
Namespace: Paragon.Townskeep.ChatSystem.HUD
Assembly: Townskeep.dll
public class ChatInput : ParagonUIBehaviourInheritance: SerializedMonoBehaviour → ParagonBehaviour → ParagonUIBehaviour → ChatInput
Remarks
ChatInput bridges the UI input field with the Chat messaging system. When the user submits a message, OnSubmit validates the input (rejecting empty/whitespace), sends it via Chat.SendMessage() to the currently active channel (from ChatWindow.Name), clears the input field, and triggers ChatHUD.Unfocus().
The input field starts deactivated (hidden via canvasGroup.alpha = 0). It is activated/deactivated by ChatHUD during focus transitions. When a chat tab is selected while the chat is focused, the input field is re-activated to maintain keyboard focus.
Quick Lookup
Get current message text
chatInput.Message
Show and focus input field
chatInput.ActivateInputField()
Hide and clear input field
chatInput.DeactivateInputField()
Clear text without hiding
chatInput.ClearMessage()
Properties
Message
The current text content of the input field. Read-only accessor to inputField.text.
Methods
Initialize
Called by ChatHUD.Start(). Stores references to the parent HUD and its sub-components, and subscribes to ChatTabs.OnTabSelected.
chatHUD
ChatHUD
The parent chat HUD
ActivateInputField
Enables the TMP_InputField, gives it keyboard focus, and makes the input visible by setting canvasGroup.alpha = 1.0.
DeactivateInputField
Removes keyboard focus, disables the TMP_InputField, clears the text, and hides the input by setting canvasGroup.alpha = 0.0.
ClearMessage
Clears the input field text without changing visibility or activation state.
Internal Behavior
OnSubmit (private)
Triggered when the user submits text in the TMP_InputField:
OnTabSelected (private)
Triggered when a chat tab is selected. If the chat is currently focused, re-activates the input field to restore keyboard focus (which is lost when clicking a tab button).
Common Pitfalls
CanvasGroup required on the same GameObject
GetComponent<CanvasGroup>() is called in Awake(). The ChatInput GameObject must have a CanvasGroup component or a NullReferenceException occurs.
TMP_InputField must be a child
GetComponentInChildren<TMP_InputField>() is used in Awake(). The input field must exist somewhere in the ChatInput hierarchy.
Input field disabled by default
The input field is deactivated in Awake(). It will not accept input until ActivateInputField() is called (typically via ChatHUD.Focus()).
Message sent to current window's channel
OnSubmit sends the message to chatWindow.Name, which is the currently displayed channel. If the channel is null or not set, Chat.SendMessage may fail.
See Also
ChatHUD — parent coordinator that manages focus transitions
ChatMessageLine — renders individual messages
Last updated