ChatHUD
Root HUDElement for the in-game chat interface. Coordinates a ChatWindow, ChatTabs, and ChatInput component, and manages the focus/unfocus lifecycle with animated fade transitions using DOTween.
Definition
Namespace: Paragon.Townskeep.ChatSystem.HUD
Assembly: Townskeep.dll
public class ChatHUD : HUDElementInheritance: SerializedMonoBehaviour → ParagonBehaviour → ParagonUIBehaviour → HUDElement → ChatHUD
Remarks
ChatHUD acts as the central coordinator for all chat UI components. It discovers its children (ChatWindow, ChatTabs, ChatInput) via GetComponentInChildren in Awake(), and initializes them in Start() — ensuring all child Awake() calls complete before initialization.
The focus system is the core state machine:
Focused — Input field is active, tabs and background are fully visible. The
OnFocusevent fires.Unfocused — Input field is deactivated and cleared. After a 2-second delay, if still unfocused, the tabs fade out over 1.5 seconds. The
OnUnfocusevent fires immediately (not after the delay).
The delayed fade prevents the chat from flickering when the user briefly clicks away and returns. If Focus() is called during the 2-second delay, the fade is cancelled because the IsFocused check prevents it.
Quick Lookup
Open chat for input
chatHUD.Focus()
Close chat
chatHUD.Unfocus()
Check if focused
chatHUD.IsFocused
Get the chat window
chatHUD.Window
Get the input field
chatHUD.Input
Get the tab bar
chatHUD.Tabs
Listen for focus
chatHUD.OnFocus += handler
Listen for unfocus
chatHUD.OnUnfocus += handler
Properties
Window
The chat message display area. Manages the active channel and message rendering.
Input
The text input component for typing messages.
Tabs
The tab bar for switching between chat channels.
IsFocused
Whether the chat is currently in the focused state.
Events
OnFocus
Fires when the chat becomes focused. Use this to disable gameplay input or update UI state.
OnUnfocus
Fires immediately when the chat loses focus. The visual fade happens 2 seconds later.
Methods
Focus
Activates the chat input field, sets IsFocused to true, fires OnFocus, and fades in the tabs group. No-op if already focused.
Unfocus
Deactivates the chat input field, sets IsFocused to false, fires OnUnfocus, then waits 2 seconds before fading out the tabs group. If Focus() is called during the delay, the fade is cancelled. No-op if already unfocused.
Unfocus() is async void — the 2-second delay is non-blocking. The OnUnfocus event fires immediately, not after the delay.
Lifecycle
Common Pitfalls
Child components must exist in hierarchy
GetComponentInChildren is used without null checks. Missing ChatWindow, ChatTabs, or ChatInput children cause a NullReferenceException in Start().
Tabs GameObject must be named "Tabs"
The CanvasGroup for the tabs fade is found via transform.Find("Tabs"). If the child is named differently, a NullReferenceException occurs.
Unfocus delay does not cancel the tween
If Focus() → Unfocus() → Focus() happens rapidly, the fade-in tween from the second Focus() may conflict with a pending fade-out from the first Unfocus(). DOTween resolves this by applying the latest value, but visual jitter is possible.
See Also
HUDElement — base class
ChatInput — input field component
ChatMessageLine — individual message renderer
HUD — parent container
Last updated