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 : HUDElement

Inheritance: SerializedMonoBehaviourParagonBehaviourParagonUIBehaviourHUDElement → 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 OnFocus event 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 OnUnfocus event 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

Goal
How

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.

circle-info

Unfocus() is async void — the 2-second delay is non-blocking. The OnUnfocus event fires immediately, not after the delay.

Lifecycle

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation

See Also

Last updated