ChatTabs
Tab bar component that creates, manages, and switches between ChatTab instances — one per chat channel. Provides sequential tab cycling for next/previous navigation.
Definition
Namespace: Paragon.Townskeep
Assembly: Townskeep.dll
public class ChatTabs : ParagonUIBehaviourInheritance: SerializedMonoBehaviour → ParagonBehaviour → ParagonUIBehaviour → ChatTabs
Remarks
ChatTabs is the controller for the tab bar in the chat UI. On Initialize(), it creates one ChatTab per registered ChatChannel (queried via Chat.GetChannels()), then auto-selects the first tab.
Tab Creation
CreateTabs() follows a reuse-then-create pattern:
Collects any pre-existing
ChatTabchildren in the hierarchyIterates over
Chat.GetChannels()— reusing existing tabs by index, creating new ones fromtabPrefabas neededDestroys any surplus tabs beyond the channel count
Subscribes each tab's
OnClickedtoSelectTab()
Tab Selection
When a tab is selected (via click or programmatic call):
The previous tab is visually deselected (
Unselect())The new tab is visually selected (
Select())The
ChatWindowis switched to the new tab's channel viachatHUD.Window.SetChannel()The
OnTabSelectedevent fires
Cycling
SwitchNextTab() and SwitchPreviousTab() wrap around — cycling past the last tab returns to the first, and vice versa.
Quick Lookup
Initialize
tabs.Initialize(chatHUD)
Select a specific tab
tabs.SelectTab(tab)
Next tab (wraps)
tabs.SwitchNextTab()
Previous tab (wraps)
tabs.SwitchPreviousTab()
Listen for tab changes
tabs.OnTabSelected += handler
Fields
tabPrefab
GameObject
[SerializeField]
Prefab instantiated when more tabs are needed than exist in the hierarchy
Events
OnTabSelected
Fired when a tab is selected (by click or programmatic call). Passes the newly selected ChatTab.
Methods
Initialize
Creates tabs for all registered channels and selects the first one.
chatHUD
ChatHUD
Parent chat HUD, used to access Window for channel switching
SelectTab
Selects a tab: deselects the previous, applies visual selection, switches the window channel, and fires OnTabSelected.
tab
ChatTab
The tab to select
SwitchNextTab
Selects the next tab in the list. Wraps to the first tab when at the end.
SwitchPreviousTab
Selects the previous tab in the list. Wraps to the last tab when at the beginning.
Common Pitfalls
Tab creation depends on Chat.GetChannels()
CreateTabs() queries Chat.GetChannels() which returns all channels registered on the Chat singleton. If the Chat singleton has not initialized yet (e.g., script execution order issue), no tabs will be created.
Surplus pre-existing tabs are destroyed
If the hierarchy has more ChatTab children than there are channels, the excess tabs are destroyed. This can cause issues if tabs are manually placed in the hierarchy for layout purposes.
SelectTab does not null-check the tab parameter
Passing null to SelectTab() (e.g., if tabs.FirstOrDefault() returns null because there are no channels) will throw a NullReferenceException when calling currentTab.Select().
Examples
Programmatic Tab Switching
See Also
ChatTab — individual tab button
ChatWindow — displays messages for the selected channel
ChatHUD — root chat coordinator
Chat Overview — system architecture
Last updated