Game.UI.Menu.UserBindings
Assembly: Assembly-CSharp
Namespace: Game.UI.Menu
Type: class
Base: CompositeBinding, IDisposable
Summary:
Manages UI bindings for the user section in the main menu (avatar, user name, switch prompt and a switch-user trigger). Creates ValueBinding entries under the "user" binding group, constructs an avatar URI with a version counter to force updates, and registers to GameManager and PlatformManager events to keep bindings in sync with platform/user changes. Implements IDisposable to unregister the game-loading event handler when no longer needed.
Fields
-
private const string kGroup = "user"
Name of the binding group used for all user-related bindings. -
private ValueBinding<bool> m_SwitchPromptVisible
Controls visibility of the "switch user" prompt in the UI. This is initialized based on GameManager.configuration.disableUserSection and platform support for user switching/section. -
private ValueBinding<string> m_AvatarBinding
Binding that provides the avatar URI string. The binding is initialized to a generated "useravatar://" URI that embeds a version counter and requested size; the version is incremented when the platform reports an avatar change to force a refresh. -
private ValueBinding<string> m_UserIDBinding
Binding that exposes the current platform user name. -
private ValueBinding<string> m_SwitchUserHintOverload
Binding that can contain an overload hint for the "switch user" UI element (e.g., a fallback string like "Steam Overlay" when platform switching isn't supported). -
private static int s_AvatarVersion
Static version counter used to generate unique avatar URIs to force avatar refreshes when the underlying avatar changes.
Properties
- None (all bindings are stored as private fields).
Constructors
public UserBindings()
Creates the binding entries and wire-ups:- Subscribes to GameManager.instance.onGameLoadingComplete to update the switch prompt visibility when the main menu is reached.
- Adds ValueBinding instances to the composite binding for switch prompt visibility, avatar URI, user ID, and switch-user hint. The avatar URI is built like "useravatar://UserAvatar#
?size=Auto" and uses ValueWriters.Nullable with a StringWriter for serialization. - Adds a TriggerBinding for "user/switchUser" that calls SwitchUser.
- Subscribes anonymous delegates to PlatformManager.instance.onStatusChanged and PlatformManager.instance.onUserUpdated to update the relevant bindings (visibility, user name, avatar) when platform or user state changes.
Methods
-
private void OnMainMenuReached(Purpose purpose, GameMode mode)
Called when game loading completes. If the reached mode is GameMode.MainMenu, updates m_SwitchPromptVisible based on configuration and platform support. Registered in the constructor and unregistered in Dispose. -
public void Dispose()
Unsubscribes OnMainMenuReached from GameManager.instance.onGameLoadingComplete. Call this when the bindings are no longer needed to avoid dangling event handlers. -
public string getSwitchUserHintOverload()
Returns null when the platform supports user switching; otherwise returns a fallback hint string "Steam Overlay". Used to populate m_SwitchUserHintOverload. -
private void SwitchUser()
Invoked by the "switchUser" TriggerBinding. If the switch prompt is visible: - If the platform supports user switching, opens the SwitchUserScreen via GameManager.instance.SetScreenActive
(). - Otherwise, if the platform supports a user section, shows the platform overlay to the community page via PlatformManager.instance.ShowOverlay(Page.Community).
Usage Example
// Create bindings when initializing a menu component
var userBindings = new UserBindings();
// ... later when cleaning up the component:
userBindings.Dispose();
Additional notes: - Avatar URIs use a simple incrementing static version (s_AvatarVersion) to force the UI to refresh when PlatformManager reports an avatar change. - Bindings are added to the CompositeBinding base, so they will be serialized/managed according to the UI binding system in use. - The class expects GameManager.instance and PlatformManager.instance to be available (typical in the game's runtime).