Skip to main content

ApplicationManager

A class in Root.Township, the global namespace.

Singleton that handles app start, pause, reload and shutdown, and tells you whether this is a headless (server) build. Both sides.

Constructors​

MemberWhat it is
ApplicationManager()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
static bool IsApplicationPausedWhether the app is paused right now.
static bool ShouldRestartAfterShutdownWhen true, the server heartbeat isn't shut down on quit.
8 private and internal fields
MemberWhat it is
private static bool hasQuitTrue once OnApplicationQuit has run, so it only runs once.
private static bool isCleaningTrue while CleanMemory is running, so calls don't overlap.
private static bool isHeadlessCached result of IsHeadless.
private static bool isQuitTrue once Update has triggered the quit after an external shutdown request.
private static Logger loggerNLog logger for this class.
private static bool needsToCacheTrue until IsHeadless has checked the command line for -batchmode or -nographics.
private IServerHostController serverHostControllerInjected IServerHostController. Set by Inject but not used in this file.
private static ShutdownReason shutdownReasonReason passed to ExternalOnApplicationQuit, given to GameModeManager.StopCurrentModeAsync on quit.

Properties​

MemberWhat it is
static bool IsHeadless { get; }True when launched with -batchmode or -nographics, as dedicated servers are. Most visual code checks this.
static bool IsQuitting { get; private set; }True once a shutdown has started.
static bool IsReloading { get; private set; }True between StartReload and FinishReload.

Events​

MemberWhat it is
static event Action<bool> ApplicationPausedStatic. Raised with the new state when the app is paused or resumed.
static event Action ApplicationQuitStatic. Raised once at shutdown. Handlers run in the order set by ApplicationShutdownOrder on their declaring type.
static event Action GameReloadStatic. Raised when a scene reload starts.

Methods​

MemberWhat it is
static async Task CleanMemory()Unloads unused assets and runs a full garbage collection. Skipped if a clean is already running.
static void ExternalOnApplicationQuit(ShutdownReason reason)Asks for a shutdown with a reason. The actual shutdown runs on the next Update.
static string FilteredCommandLine()The process command line with access, refresh and identity tokens and /login details masked out.
static void FinishReload()Clears IsReloading.
void OnApplicationQuit()Shuts down once: stops the game mode, stops the heartbeat unless restarting, saves preferences, runs ApplicationQuit, finishes file writes and quits.
static void StartReload()Starts a scene reload and raises GameReload, unless already reloading or quitting.
protected void Inject(IServerHostController injectedServerHostController)Receives the server host controller through dependency injection.
5 private and internal methods
MemberWhat it is
private static void LogGameInfo()Logs the build version, player mode, filtered command line and system stats at startup.
private void OnApplicationPause(bool isPaused)Unity callback: sets IsApplicationPaused and raises ApplicationPaused.
private static void Setup()Turns on run-in-background and sets the target frame rate to 90.
private void Start()Clears IsReloading, applies Setup and logs game info.
private void Update()Runs OnApplicationQuit once after ExternalOnApplicationQuit has set IsQuitting.