ApplicationCoordinator
The main manager for the application. It is an abstract MonoBehaviour, so each project creates a concrete subclass and attaches it to a root GameObject in the startup scene.
Responsibilities:
- Singleton and persistence: In
Awake, the first instance becomesInstance, is markedDontDestroyOnLoad, and is registered withInitializationRegistryas both a sync and an async initializable. Duplicates are destroyed. - Startup sequencing:
Initcreates theApplicationLogicManager.InitAsyncsubscribesInitializeApplicationtoSaffronLibrarySignals.SystemsReadythrough theSignalBusand awaitsInitializeVolumeState. - Project hooks: Subclasses implement
RegisterPlatformModules,RunPlatformModules,InitializeStartupPresentation,InitializeVolumeState,CreateLifecycleHandler, andCreateLifecycleAdapter. - Query answering:
ProcessQueryanswers focus-duration queries and writes the result toCoreParamKeys.Duration.
Interaction with dependencies:
SignalBus(throughServiceLocator) notifies the coordinator whenSystemsReadyis raised.InitializationRegistryandInitializationManagerdecide whenInitandInitAsyncrun.ApplicationFlowControllerforwards Application-domain queries toProcessQuery.
ApplicationFlowController
The FlowController for Domain.Application. It is the connection between the query bus and the coordinator.
Responsibilities:
- Registers the command handler for
Domain.Applicationthrough the base class. - Registers
OnQuerywith theQueryBusforDomain.Application. - Forwards each query to
ApplicationCoordinator.Instance.ProcessQuery. - Has an empty
HandleCommand, because no commands are routed through this domain.
Interaction with dependencies:
FlowController(base class) registers with theCommandBusduringInit.QueryBusroutes queries toOnQuery.ServiceLocatorprovides the bus registry used to reach theQueryBus.
ApplicationLifecycleHandler
The abstract base for project lifecycle handlers. It implements IApplicationLifecycleHandler.
Responsibilities:
- Its
OnFocusChangedmethod raises the standard focus-changed event throughApplicationEventFactorybefore calling the project hook. Projects cannot overrideOnFocusChanged. - Projects implement
ProcessFocusChangedto react to focus changes.
Interaction with dependencies:
ApplicationEventFactoryraises the event onDomain.Applicationthrough theEventBus.ApplicationCoordinatorreceives the handler throughSetLifecycleHandlerduring startup.
UnityLifecycleAdapter
A MonoBehaviour that connects Unity's application callbacks to the framework. It implements IApplicationLifecycleAdapter.
Responsibilities:
- Its private
OnApplicationFocusforwards focus changes to the handler set throughInitialize, if one is set. - Its private
OnApplicationQuitcallsApplicationEventFactory.OnApplicationQuit. GetRealtimeSinceStartupreturnsTime.realtimeSinceStartup, soApplicationCoordinatorandApplicationLogicManageruse the same clock.
Interaction with dependencies:
ApplicationCoordinatorcallsInitializeduring its lifecycle setup.- The adapter raises events through
ApplicationEventFactory, which uses theEventBus.
IApplicationLifecycleHandler and IApplicationLifecycleAdapter
The two contracts that separate engine code from project code.
IApplicationLifecycleHandlerreceivesOnFocusChanged(bool)calls.ApplicationLifecycleHandleris the standard implementation.IApplicationLifecycleAdapterprovidesInitialize(handler)andGetRealtimeSinceStartup().UnityLifecycleAdapteris the Unity implementation.
Projects that run on another engine implement the adapter for that engine, and the rest of the system stays unchanged.
ApplicationLogicManager
A plain C# class that owns focus-loss timing.
SetFocusLossTime(float)records the time focus was lost.GetFocusLossDuration(float)returns the elapsed time since that record.
It is created by ApplicationCoordinator.Init and stored in the protected logicManager field. It has no MonoBehaviour dependency.
ApplicationEventFactory and ApplicationQueryFactory
Two static factories that build messages for Domain.Application.
ApplicationEventFactoryraises the focus-changed and quit events throughBusUtility.Raise.ApplicationQueryFactorybuilds the focus-duration query and returns its answer throughBusUtility.AskAndGet.
Both use ApplicationParamKeys for subject and state values. Both depend on the bus system to deliver messages.
ServiceLocator
A static class that holds the BusRegistry for global access. InitializationManager sets it during bootstrap, and ApplicationFlowController, ApplicationCoordinator, and the factories read it through GetBusRegistry.
ApplicationFlowService
A static partial class with content-agnostic helpers. Its one method, ResetLocalData, clears PlayerPrefs and then calls an optional reload action supplied by the caller. Projects can extend the class in other files.
Event and key types
ApplicationEventVerb(Changed,Quit) describes what happened.ApplicationSubjects(Focus,Application) describes what the message is about.ApplicationKeyNamesandApplicationParamKeysdefine the names and typed keys used inParams.ApplicationConstants.PausedGameSpeedprovides the time scale value used to pause game time.