ChatWindow

Message display area for the chat UI. Binds to a ChatChannel, listens for new messages, and delegates rendering to a ChatScrollRect. Manages background visibility with animated fade transitions tied to the ChatHUD focus state.

Definition

Namespace: Paragon.Townskeep.ChatSystem.HUD Assembly: Townskeep.dll

public class ChatWindow : ParagonUIBehaviour

Inheritance: SerializedMonoBehaviourParagonBehaviourParagonUIBehaviour → ChatWindow

Remarks

ChatWindow is the bridge between the data model (ChatChannel) and the virtualized display (ChatScrollRect). When a channel is set via SetChannel(), the window:

  1. Unsubscribes from the previous channel's MessageSent event

  2. Clears the scroll rect

  3. Subscribes to the new channel's MessageSent event

  4. Pushes all existing messages to the scroll rect

Focus-Driven Background Fade

The window has a background CanvasGroup (found via transform.Find("Background")) that fades in/out based on the ChatHUD focus state:

  • On focus — Fades background alpha to 1.0 over 1.5s via DOTween

  • On unfocus — Waits 2.0s (via Yield.WaitForSeconds), then fades to 0.0 over 1.5s if the chat is still unfocused

The background starts hidden (alpha = 0) in Awake().

Message Access

ChatWindow exposes GetMessage(Index) and GetAllMessages() which delegate directly to the bound ChatChannel. These are used by ChatScrollRect during virtualized line cycling.

Quick Lookup

Goal
How

Initialize

window.Initialize(chatHUD)

Switch to a channel

window.SetChannel(channel)

Get a message by index

window.GetMessage(^1) (newest)

Get all messages

window.GetAllMessages()

Read message count

window.MessageCount

Read active channel

window.Channel

Properties

Property
Type
Description

ID

int

Window identifier

Name

string

Name of the currently bound channel (null-safe)

Channel

ChatChannel

The currently bound chat channel

MessageCount

int

Number of messages in the current channel (0 if no channel bound)

Methods

Initialize

Sets up the window with its parent ChatHUD. Initializes the child ChatScrollRect and subscribes to focus/unfocus events for background fading.

Parameter
Type
Description

chatHUD

ChatHUD

The parent chat HUD coordinator

SetChannel

Switches the window to display messages from a different chat channel. Clears existing messages and loads the new channel's history.

Parameter
Type
Description

channel

ChatChannel

The channel to bind to (can be null to unbind)

Behavior:

  1. Unsubscribes OnMessageSent from the previous channel (if any)

  2. Clears the scroll rect

  3. If channel is not null: subscribes to MessageSent and pushes all existing messages

GetMessage

Retrieves a message from the current channel by index. Supports C# Index with hat (^) operator for reverse indexing.

Parameter
Type
Description

index

Index

Message index (e.g., ^1 for newest)

Returns: The ChatMessage at the specified index.

GetAllMessages

Returns all messages from the current channel, or an empty enumerable if no channel is bound.

Returns: All messages in the channel, or Enumerable.Empty<ChatMessage>() if channel is null.

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation
circle-exclamation

See Also

  • ChatScrollRect — virtualized scroll view that renders messages

  • ChatTab — triggers channel switching via ChatTabs.SelectTab()

  • ChatTabs — tab bar that calls SetChannel() on selection

  • ChatHUD — root coordinator providing focus events

  • Chat Overview — system architecture

Last updated