Lifecycle System Refactor & Logging Centralization (#56)
## ManagedBehaviour System Refactor - **Sealed `Awake()`** to prevent override mistakes that break singleton registration - **Added `OnManagedAwake()`** for early initialization (fires during registration) - **Renamed lifecycle hook:** `OnManagedAwake()` → `OnManagedStart()` (fires after boot, mirrors Unity's Awake→Start) - **40 files migrated** to new pattern (2 core, 38 components) - Eliminated all fragile `private new void Awake()` patterns - Zero breaking changes - backward compatible ## Centralized Logging System - **Automatic tagging** via `CallerMemberName` and `CallerFilePath` - logs auto-tagged as `[ClassName][MethodName] message` - **Unified API:** Single `Logging.Debug/Info/Warning/Error()` replaces custom `LogDebugMessage()` implementations - **~90 logging call sites** migrated across 10 files - **10 redundant helper methods** removed - All logs broadcast via `Logging.OnLogEntryAdded` event for real-time monitoring ## Custom Log Console (Editor Window) - **Persistent filter popups** for multi-selection (classes, methods, log levels) - windows stay open during selection - **Search** across class names, methods, and message content - **Time range filter** with MinMaxSlider - **Export** filtered logs to timestamped `.txt` files - **Right-click context menu** for quick filtering and copy actions - **Visual improvements:** White text, alternating row backgrounds, color-coded log levels - **Multiple instances** supported for simultaneous system monitoring - Open via `AppleHills > Custom Log Console` Co-authored-by: Michal Pikulski <michal@foolhardyhorizons.com> Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Reviewed-on: #56
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using AppleHills.Core.Settings;
|
||||
using UnityEngine;
|
||||
using Core;
|
||||
@@ -33,11 +33,9 @@ namespace Bootstrap
|
||||
// Run very early - need to set up loading screen before other systems initialize
|
||||
public override int ManagedAwakePriority => 5;
|
||||
|
||||
protected override void Awake()
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.Awake(); // Register with LifecycleManager
|
||||
|
||||
LogDebugMessage("BootSceneController.Awake() - Initializing loading screen DURING bootstrap");
|
||||
Logging.Debug("BootSceneController.Awake() - Initializing loading screen DURING bootstrap");
|
||||
|
||||
// Validate loading screen exists
|
||||
if (initialLoadingScreen == null)
|
||||
@@ -71,11 +69,11 @@ namespace Bootstrap
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnManagedAwake()
|
||||
internal override void OnManagedStart()
|
||||
{
|
||||
LogDebugMessage("BootSceneController.OnManagedAwake() - Boot is GUARANTEED complete, starting scene loading");
|
||||
Logging.Debug("BootSceneController.OnManagedStart() - Boot is GUARANTEED complete, starting scene loading");
|
||||
|
||||
// Boot is GUARANTEED complete at this point - that's the whole point of OnManagedAwake!
|
||||
// Boot is GUARANTEED complete at this point - that's the whole point of OnManagedStart!
|
||||
// No need to subscribe to OnBootCompleted or check CustomBoot.Initialised
|
||||
_bootComplete = true;
|
||||
_currentPhase = LoadingPhase.SceneLoading;
|
||||
@@ -102,12 +100,12 @@ namespace Bootstrap
|
||||
/// </summary>
|
||||
private void OnInitialLoadingComplete()
|
||||
{
|
||||
LogDebugMessage("Initial loading screen fully hidden, boot sequence completed");
|
||||
Logging.Debug("Initial loading screen fully hidden, boot sequence completed");
|
||||
|
||||
// Play the intro cinematic if available
|
||||
if (CinematicsManager.Instance != null)
|
||||
{
|
||||
LogDebugMessage("Attempting to play intro cinematic");
|
||||
Logging.Debug("Attempting to play intro cinematic");
|
||||
|
||||
// Use LoadAndPlayCinematic to play the intro sequence
|
||||
CinematicsManager.Instance.LoadAndPlayCinematic("IntroSequence", false);
|
||||
@@ -149,13 +147,13 @@ namespace Bootstrap
|
||||
{
|
||||
if (debugMode)
|
||||
{
|
||||
LogDebugMessage($"Bootstrap progress: {progress:P0}, Combined: {GetCombinedProgress():P0}");
|
||||
Logging.Debug($"Bootstrap progress: {progress:P0}, Combined: {GetCombinedProgress():P0}");
|
||||
}
|
||||
}
|
||||
|
||||
private void LogDebugInfo()
|
||||
{
|
||||
LogDebugMessage($"Debug - Phase: {_currentPhase}, Bootstrap: {CustomBoot.CurrentProgress:P0}, " +
|
||||
Logging.Debug($"Debug - Phase: {_currentPhase}, Bootstrap: {CustomBoot.CurrentProgress:P0}, " +
|
||||
$"Scene: {_sceneLoadingProgress:P0}, Combined: {GetCombinedProgress():P0}, Boot Complete: {_bootComplete}");
|
||||
}
|
||||
|
||||
@@ -172,7 +170,7 @@ namespace Bootstrap
|
||||
|
||||
private async void LoadMainScene()
|
||||
{
|
||||
LogDebugMessage($"Loading main menu scene: {mainSceneName}");
|
||||
Logging.Debug($"Loading main menu scene: {mainSceneName}");
|
||||
|
||||
try
|
||||
{
|
||||
@@ -186,7 +184,7 @@ namespace Bootstrap
|
||||
|
||||
if (debugMode)
|
||||
{
|
||||
LogDebugMessage($"Scene loading raw: {value:P0}, Combined: {GetCombinedProgress():P0}");
|
||||
Logging.Debug($"Scene loading raw: {value:P0}, Combined: {GetCombinedProgress():P0}");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -210,13 +208,13 @@ namespace Bootstrap
|
||||
_sceneLoadingProgress = 1f;
|
||||
|
||||
// CRITICAL: Broadcast lifecycle events so components get their OnSceneReady callbacks
|
||||
LogDebugMessage($"Broadcasting OnSceneReady for: {mainSceneName}");
|
||||
Logging.Debug($"Broadcasting OnSceneReady for: {mainSceneName}");
|
||||
LifecycleManager.Instance?.BroadcastSceneReady(mainSceneName);
|
||||
|
||||
// Restore scene data for the main menu
|
||||
if (SaveLoadManager.Instance != null)
|
||||
{
|
||||
LogDebugMessage($"Restoring scene data for: {mainSceneName}");
|
||||
Logging.Debug($"Restoring scene data for: {mainSceneName}");
|
||||
SaveLoadManager.Instance.RestoreSceneData();
|
||||
}
|
||||
|
||||
@@ -246,7 +244,7 @@ namespace Bootstrap
|
||||
Scene currentScene = SceneManager.GetActiveScene();
|
||||
string startingSceneName = currentScene.name;
|
||||
|
||||
LogDebugMessage($"Unloading StartingScene: {startingSceneName}");
|
||||
Logging.Debug($"Unloading StartingScene: {startingSceneName}");
|
||||
|
||||
// Unload the StartingScene
|
||||
await SceneManager.UnloadSceneAsync(startingSceneName);
|
||||
@@ -255,14 +253,14 @@ namespace Bootstrap
|
||||
Scene mainMenuScene = SceneManager.GetSceneByName(mainSceneName);
|
||||
SceneManager.SetActiveScene(mainMenuScene);
|
||||
|
||||
LogDebugMessage($"Transition complete: {startingSceneName} unloaded, {mainSceneName} is now active");
|
||||
Logging.Debug($"Transition complete: {startingSceneName} unloaded, {mainSceneName} is now active");
|
||||
|
||||
// Destroy the boot scene controller since its job is done
|
||||
Destroy(gameObject);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logging.Warning($"[BootSceneController] Error unloading StartingScene: {e.Message}");
|
||||
Logging.Warning($"Error unloading StartingScene: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,13 +281,5 @@ namespace Bootstrap
|
||||
_progressAction?.Invoke(value);
|
||||
}
|
||||
}
|
||||
|
||||
private void LogDebugMessage(string message)
|
||||
{
|
||||
if ( _logVerbosity <= LogVerbosity.Debug)
|
||||
{
|
||||
Logging.Debug($"[BootSceneController] {message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using AppleHills.Core.Settings;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using UnityEngine;
|
||||
@@ -105,7 +104,7 @@ namespace Bootstrap
|
||||
// Notify the LifecycleManager that boot is complete
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
LogDebugMessage("Calling LifecycleManager.OnBootCompletionTriggered()");
|
||||
Logging.Debug("Calling LifecycleManager.OnBootCompletionTriggered()");
|
||||
if (LifecycleManager.Instance != null)
|
||||
{
|
||||
LifecycleManager.Instance.OnBootCompletionTriggered();
|
||||
@@ -127,7 +126,7 @@ namespace Bootstrap
|
||||
// Notify the LifecycleManager that boot is complete
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
LogDebugMessage("Calling LifecycleManager.OnBootCompletionTriggered()");
|
||||
Logging.Debug("Calling LifecycleManager.OnBootCompletionTriggered()");
|
||||
if (LifecycleManager.Instance != null)
|
||||
{
|
||||
LifecycleManager.Instance.OnBootCompletionTriggered();
|
||||
@@ -238,16 +237,7 @@ namespace Bootstrap
|
||||
{
|
||||
CurrentProgress = Mathf.Clamp01(progress);
|
||||
OnBootProgressChanged?.Invoke(CurrentProgress);
|
||||
LogDebugMessage($"Progress: {CurrentProgress:P0}");
|
||||
}
|
||||
|
||||
private static void LogDebugMessage(string message)
|
||||
{
|
||||
if (DeveloperSettingsProvider.Instance.GetSettings<DebugSettings>().bootstrapLogVerbosity <=
|
||||
LogVerbosity.Debug)
|
||||
{
|
||||
Logging.Debug($"[CustomBoot] {message}");
|
||||
}
|
||||
Logging.Debug($"Progress: {CurrentProgress:P0}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,7 +138,7 @@ namespace Bootstrap
|
||||
float displayProgress = Mathf.Min(steadyProgress, actualProgress);
|
||||
|
||||
// Log the progress values for debugging
|
||||
LogDebugMessage($"Progress - Default: {steadyProgress:F2}, Actual: {actualProgress:F2}, Display: {displayProgress:F2}");
|
||||
Logging.Debug($"Progress - Default: {steadyProgress:F2}, Actual: {actualProgress:F2}, Display: {displayProgress:F2}");
|
||||
|
||||
// Directly set the progress bar fill amount without smoothing
|
||||
if (progressBarImage != null)
|
||||
@@ -151,7 +151,7 @@ namespace Bootstrap
|
||||
if (steadyProgress >= 1.0f && displayProgress >= 1.0f)
|
||||
{
|
||||
_animationComplete = true;
|
||||
LogDebugMessage("Animation complete");
|
||||
Logging.Debug("Animation complete");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ namespace Bootstrap
|
||||
if (progressBarImage != null)
|
||||
{
|
||||
progressBarImage.fillAmount = 1.0f;
|
||||
LogDebugMessage("Final progress set to 1.0");
|
||||
Logging.Debug("Final progress set to 1.0");
|
||||
}
|
||||
|
||||
// Hide the screen if loading is also complete
|
||||
@@ -172,7 +172,7 @@ namespace Bootstrap
|
||||
if (loadingScreenContainer != null)
|
||||
{
|
||||
loadingScreenContainer.SetActive(false);
|
||||
LogDebugMessage("Animation AND loading complete, hiding screen");
|
||||
Logging.Debug("Animation AND loading complete, hiding screen");
|
||||
|
||||
// Invoke the callback when fully hidden
|
||||
_onLoadingScreenFullyHidden?.Invoke();
|
||||
@@ -189,7 +189,7 @@ namespace Bootstrap
|
||||
/// </summary>
|
||||
public void HideLoadingScreen()
|
||||
{
|
||||
LogDebugMessage("Loading complete, marking loading as finished");
|
||||
Logging.Debug("Loading complete, marking loading as finished");
|
||||
|
||||
// Mark that loading is complete
|
||||
_loadingComplete = true;
|
||||
@@ -200,7 +200,7 @@ namespace Bootstrap
|
||||
if (loadingScreenContainer != null)
|
||||
{
|
||||
loadingScreenContainer.SetActive(false);
|
||||
LogDebugMessage("Animation already complete, hiding screen immediately");
|
||||
Logging.Debug("Animation already complete, hiding screen immediately");
|
||||
|
||||
// Invoke the callback when fully hidden
|
||||
_onLoadingScreenFullyHidden?.Invoke();
|
||||
@@ -210,7 +210,7 @@ namespace Bootstrap
|
||||
}
|
||||
else
|
||||
{
|
||||
LogDebugMessage("Animation still in progress, waiting for it to complete");
|
||||
Logging.Debug("Animation still in progress, waiting for it to complete");
|
||||
// The coroutine will handle hiding when animation completes
|
||||
}
|
||||
}
|
||||
@@ -244,13 +244,5 @@ namespace Bootstrap
|
||||
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
private void LogDebugMessage(string message)
|
||||
{
|
||||
if ( _logVerbosity <= LogVerbosity.Debug)
|
||||
{
|
||||
Logging.Debug($"[InitialLoadingScreen] {message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user