MainBootstrapSystem - jimdroberts/FishMMO GitHub Wiki
Main bootstrap system for FishMMO. Handles initialization, logging, version management, and graceful shutdown. Coordinates startup and shutdown flows for both server and client, ensuring proper configuration, logging, and versioning are established at launch.
-
public static string GameVersion
The current game version string. Set during initialization.
-
public string configFileName
The name of the logging configuration JSON file (e.g., logging.json).
-
private VersionConfig versionConfig
Reference to the VersionConfig asset.
-
private static bool isInitiatingShutdown
Indicates if shutdown is currently being initiated.
-
private static bool canQuitApplication
Controls if Application.wantsToQuit should allow quitting.
-
void Awake()
Unity Awake message. Starts the bootstrap initialization chain.
-
private void OnInternalLogCallback(string message)
Callback for internal logging messages from FishMMO.Logging.Log. Ensures UnityLoggerBridge does not re-capture internal log calls. message: string - The log message.
-
private bool OnApplicationWantsToQuit()
Unity message called before the application quits. Allows delaying quit for async cleanup. Returns: bool - True if the application should quit, false to defer quitting.
-
public void InitiateShutdown()
Initiates the shutdown process, including graphics cleanup and logging system shutdown.
-
private async Task PerformAsyncShutdown()
Performs asynchronous cleanup tasks before the application quits. Returns: Task representing the async shutdown process.
-
private async Task GraphicsCleanup()
Placeholder for actual graphics cleanup logic. Typically does nothing for dedicated server builds. Returns: Task representing the graphics cleanup process.
-
public override void OnPreload()
Initializes the logging system and other bootstrap components. Loads version info and configures initial scene loading.
-
void OnDestroy()
Unity OnDestroy message. Handles shutdown and cleanup when the object is destroyed.
#if UNITY_EDITOR
-
private void OnEditorPlayModeStateChanged(PlayModeStateChange state)
Handles changes in Unity Editor's Play Mode state. Initiates shutdown when exiting Play Mode. state: PlayModeStateChange - The play mode state change event. #endif
- Attach
MainBootstrapSystem
to a GameObject in your main bootstrap scene. - Assign the
versionConfig
asset and set theconfigFileName
as needed. - The system will automatically initialize logging, versioning, and scene loading on Awake.
- Shutdown and cleanup are handled gracefully on application quit or destruction.
// Example 1: Setting up MainBootstrapSystem
mainBootstrapSystem.configFileName = "logging.json";
mainBootstrapSystem.versionConfig = myVersionConfigAsset;
// On Awake, the system will initialize logging, versioning, and load the initial scene.
// Example 2: Initiating shutdown manually
mainBootstrapSystem.InitiateShutdown();
- Always assign a valid
versionConfig
asset to ensure correct versioning at startup. - Use
configFileName
to specify the logging configuration file for flexible log management. - Allow the system to handle shutdown and cleanup to ensure all async tasks and logging are completed.
- Use the internal log callback for diagnostics and to monitor initialization and shutdown flows.
- Integrate with AddressableLoadProcessor for staged scene and asset loading.