Finalize by subscribing to the new boot init order
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Bootstrap;
|
||||
using Core;
|
||||
using Input;
|
||||
using UnityEngine;
|
||||
@@ -14,7 +15,14 @@ namespace Cinematics
|
||||
private float _holdStartTime;
|
||||
private bool _isHolding;
|
||||
private bool _skipPerformed;
|
||||
private bool _initialized = false;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
// Register for post-boot initialization
|
||||
BootCompletionService.RegisterInitAction(InitializePostBoot);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Reset the progress bar
|
||||
@@ -23,32 +31,93 @@ namespace Cinematics
|
||||
radialProgressBar.fillAmount = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (CinematicsManager.Instance.IsCinematicPlaying)
|
||||
HandleCinematicStarted();
|
||||
|
||||
CinematicsManager.Instance.OnCinematicStarted += HandleCinematicStarted;
|
||||
CinematicsManager.Instance.OnCinematicStopped += HandleCinematicStopped;
|
||||
// Only handle the case where the GameObject is enabled after boot is already complete
|
||||
if (!_initialized && BootCompletionService.IsBootComplete)
|
||||
{
|
||||
// Boot is already complete but we haven't initialized yet, do it now
|
||||
Logging.Debug("[SkipCinematic] OnEnable: Boot already complete, initializing now");
|
||||
InitializePostBoot();
|
||||
}
|
||||
else if (_initialized)
|
||||
{
|
||||
// If we're already initialized, just ensure subscriptions are active
|
||||
SubscribeToCinematicsEvents();
|
||||
}
|
||||
// If boot isn't complete, our InitializePostBoot method will be called via the BootCompletionService
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
CinematicsManager.Instance.OnCinematicStarted -= HandleCinematicStarted;
|
||||
CinematicsManager.Instance.OnCinematicStopped -= HandleCinematicStopped;
|
||||
// If still registered, unregister input override
|
||||
InputManager.Instance.UnregisterOverrideConsumer(this);
|
||||
// Clean up subscriptions regardless of initialization state
|
||||
UnsubscribeFromCinematicsEvents();
|
||||
}
|
||||
|
||||
private void InitializePostBoot()
|
||||
{
|
||||
// Safe initialization of manager dependencies after boot is complete
|
||||
if (_initialized)
|
||||
return;
|
||||
|
||||
_initialized = true;
|
||||
|
||||
// Subscribe to CinematicsManager events now that boot is complete
|
||||
SubscribeToCinematicsEvents();
|
||||
|
||||
Logging.Debug("[SkipCinematic] Post-boot initialization complete");
|
||||
}
|
||||
|
||||
private void SubscribeToCinematicsEvents()
|
||||
{
|
||||
if (CinematicsManager.Instance == null) return;
|
||||
|
||||
// First unsubscribe to prevent duplicate subscriptions
|
||||
UnsubscribeFromCinematicsEvents();
|
||||
|
||||
// Now subscribe
|
||||
CinematicsManager.Instance.OnCinematicStarted += HandleCinematicStarted;
|
||||
CinematicsManager.Instance.OnCinematicStopped += HandleCinematicStopped;
|
||||
|
||||
// Check if a cinematic is already playing
|
||||
if (CinematicsManager.Instance.IsCinematicPlaying)
|
||||
HandleCinematicStarted();
|
||||
|
||||
Logging.Debug("[SkipCinematic] Subscribed to cinematics events");
|
||||
}
|
||||
|
||||
private void UnsubscribeFromCinematicsEvents()
|
||||
{
|
||||
if (CinematicsManager.Instance != null)
|
||||
{
|
||||
CinematicsManager.Instance.OnCinematicStarted -= HandleCinematicStarted;
|
||||
CinematicsManager.Instance.OnCinematicStopped -= HandleCinematicStopped;
|
||||
Logging.Debug("[SkipCinematic] Unsubscribed from cinematics events");
|
||||
}
|
||||
|
||||
// If still registered as an input override consumer, unregister
|
||||
if (InputManager.Instance != null)
|
||||
{
|
||||
InputManager.Instance.UnregisterOverrideConsumer(this);
|
||||
Logging.Debug("[SkipCinematic] Unregistered as input override consumer");
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleCinematicStarted()
|
||||
{
|
||||
InputManager.Instance.RegisterOverrideConsumer(this);
|
||||
if (InputManager.Instance != null)
|
||||
{
|
||||
InputManager.Instance.RegisterOverrideConsumer(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleCinematicStopped()
|
||||
{
|
||||
InputManager.Instance.UnregisterOverrideConsumer(this);
|
||||
if (InputManager.Instance != null)
|
||||
{
|
||||
InputManager.Instance.UnregisterOverrideConsumer(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
|
||||
Reference in New Issue
Block a user