Game.AppBindings
Assembly: Assembly-CSharp
Namespace: Game.UI
Type: class
Base: CompositeBinding, IDisposable
Summary:
AppBindings wires game state and UI via a set of data/trigger bindings used by the in-game UI. It exposes FPS/frame timing info, error/confirmation dialog handling, save/backup helpers, clipboard access, and management of active UI mod locations. It registers bindings in its constructor and updates frame timing and adaptive dynamic resolution each Update cycle.
Fields
-
private struct FrameTiming : IJsonWritable
FrameTiming is a private nested struct used to sample and expose frame timing stats (FPS, full frame time, CPU/GPU times). It reads from HDRenderPipeline debug frame timing when available and can write itself to JSON. -
private const string kGroup = "app"
Internal constant group name used when registering bindings. -
public const string kBodyClassNames = ""
Public constant for body class names (empty by default). Kept for compatibility with binding keys. -
private ValueBinding<string> m_BackgroundProcessMessageBinding
Binding used to expose a background process message string to the UI. -
private EventBinding<ConfirmationDialogBase> m_ConfirmationDialogBinding
Event binding used to trigger confirmation/ message dialogs in the UI. -
private ValueBinding<HashSet<string>> m_ActiveUIModsLocation
Binding that exposes the set of active UI mod locations to the UI. -
private GetterValueBinding<SaveInfo> m_CanContinueBinding
Getter binding that supplies info about whether the player can continue the last save (returns SaveInfo or null). -
private ValueBinding<string[]> m_OwnedPrerequisites
Binding that exposes an array of owned prerequisite IDs/names (nullable). -
private EventBinding m_CheckContinueGamePrerequisites
Event binding used to trigger checking of prerequisites required to continue a game (used by launcher flow). -
private Action<int> m_ConfirmationDialogCallback
Callback stored for single-shot confirmation dialog replies (int result). -
private Action<int, bool> m_DismissibleConfirmationDialogCallback
Callback stored for dismissible confirmation dialog replies (int result + don't-show-again flag). -
private DebugUISystem m_DebugUISystem
Cached reference to the DebugUISystem (queried lazily). -
private static FrameTiming m_FrameTiming
Static instance of the FrameTiming struct used and updated during Update().
Properties
-
public bool ready { get; set; }
Flag exposed to UI indicating whether the application (UI layer) is ready. Backed by a GetterValueBinding in the constructor. -
public string activeUI { get; set; }
String property indicating which UI is active ("Menu", "Game", "Editor", or null). Exposed to UI via a binding; used by other code to switch context.
Constructors
public AppBindings()
Creates and registers all bindings used by the UI. Initializes ErrorDialogManager, sets up value/getter/call/trigger bindings for fps/frameStats, locale, error dialogs, confirmation callbacks, platform, save continuation info, active UI mod locations, clipboard and save/exit triggers, and more.
Methods
-
private float GetFPS()
Returns the current FPS. Uses HDRenderPipeline precise frame timing when the general settings request Precise mode; otherwise uses 1 / Time.smoothDeltaTime. -
private float GetFullFrameTime()
Returns the last full frame time sampled from HDRenderPipeline debug frame timing (or 0 if not available). -
private float GetCPUMainThreadTime()
Returns the last main-thread CPU frame time sampled from HDRenderPipeline (or 0 if not available). -
private float GetCPURenderThreadTime()
Returns the last render-thread CPU frame time sampled from HDRenderPipeline (or 0 if not available). -
private float GetGPUTime()
Returns the last GPU frame time sampled from HDRenderPipeline (or 0 if not available). -
public void SetMainMenuActive()
Sets the activeUI property to "Menu". Convenience for other systems. -
public void SetGameActive()
Sets the activeUI property to "Game". Convenience for other systems. -
public void SetEditorActive()
Sets the activeUI property to "Editor". Convenience for other systems. -
public void SetNoneActive()
Sets the activeUI property to null. -
internal Task<bool> LauncherContinueGame()
Triggers the checkContinueGamePrerequisites event and returns a completed Task(always true). Used by launcher flows to ask the UI to verify prerequisites. -
public void UpdateCanContinueBinding()
Forces the m_CanContinueBinding to refresh its value (GetLastSaveInfo). -
public void UpdateOwnedPrerequisiteBinding()
Updates the m_OwnedPrerequisites binding with the current list retrieved from GameManager. -
private SaveInfo GetLastSaveInfo()
Helper that inspects GameManager.instance.settings.userState.lastSaveGameMetadata and returns the target SaveInfo if present and valid; otherwise null. -
public void UpdateActiveUIModsLocation(IList<string> locations)
Replaces the active UI mods location set with the provided list and triggers the binding update. -
public void AddActiveUIModLocation(IList<string> locations)
Adds the supplied locations to the active UI mods set and triggers an update only if there was a change. -
public void RemoveActiveUIModLocation(IList<string> locations)
Removes the supplied locations from the active UI mods set and triggers an update only if there was a change. -
public void Dispose()
Disposes the ErrorDialogManager and the static m_FrameTiming. Intended to clean up resources when the bindings are no longer needed. -
public override bool Update()
Updates frame timing (m_FrameTiming.Update), toggles DebugManager adaptiveDRSActive based on AdaptiveDynamicResolutionScale, updates AdaptiveDynamicResolutionScale with recent timing samples when available, then calls base.Update() to propagate binding updates. -
private void ExitApplication()
Calls GameManager.QuitGame() to exit the application. -
private async void SaveBackupAndExitApplication()
Asynchronously saves a backup save (creates a preview texture, captures screenshot, invokes GameManager.Save) and then quits the game. Exceptions are logged. -
private async void SaveBackup()
Asynchronously saves a backup save without exiting. -
private async Task SaveBackupImpl()
Internal implementation used by SaveBackup and SaveBackupAndExitApplication: captures a save preview, constructs a save name, calls GameManager.instance.Save, disposes resources and handles exceptions. -
private void SetClipboard(string text)
Copies text to the OS clipboard via GUIUtility.systemCopyBuffer. -
private void DismissCurrentError()
Dismisses the currently shown error dialog via ErrorDialogManager. -
public void ShowConfirmationDialog([NotNull] ConfirmationDialog dialog, [NotNull] Action<int> callback)
Shows a standard confirmation dialog and stores a single-shot callback to be invoked with the dialog result. -
public void ShowMessageDialog([NotNull] MessageDialog dialog, Action<int> callback)
Shows a message dialog (treated like a confirmation dialog) and stores a callback. -
public void ShowConfirmationDialog([NotNull] DismissibleConfirmationDialog dialog, [NotNull] Action<int, bool> callback)
Shows a dismissible confirmation dialog and stores a callback that receives (result, dontShowAgain). -
private void OnConfirmationDialogCallback(int msg)
Internal handler invoked by the binding to forward the message to the stored m_ConfirmationDialogCallback and clear it. -
private void OnDismissibleConfirmationDialogCallback(int msg, bool dontShowAgain)
Internal handler invoked by the binding to forward the message and flag to the stored m_DismissibleConfirmationDialogCallback and clear it.
Usage Example
// Create and register bindings (usually done during UI subsystem init)
var appBindings = new AppBindings();
// Mark the UI as ready and set active UI context
appBindings.ready = true;
appBindings.SetGameActive(); // sets activeUI = "Game"
// Update bindings when game state changes
appBindings.UpdateCanContinueBinding();
appBindings.UpdateOwnedPrerequisiteBinding();
// Show a confirmation dialog
appBindings.ShowConfirmationDialog(
new ConfirmationDialog("Quit", "Are you sure you want to quit?"),
result => {
if (result == 1) {
// user confirmed
GameManager.QuitGame();
}
});
// When done, dispose to release resources
appBindings.Dispose();