Rework of base interactables and managed behaviors
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using UnityEngine;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using Cinematics;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using Data.CardSystem;
|
||||
using Input;
|
||||
using PuzzleS;
|
||||
@@ -12,7 +12,7 @@ namespace AppleHills.Core
|
||||
/// Provides quick access to frequently used game objects, components, and manager instances.
|
||||
/// References are cached for performance and automatically invalidated on scene changes.
|
||||
/// </summary>
|
||||
public class QuickAccess : MonoBehaviour
|
||||
public class QuickAccess : ManagedBehaviour
|
||||
{
|
||||
#region Singleton Setup
|
||||
private static QuickAccess _instance;
|
||||
@@ -24,6 +24,9 @@ namespace AppleHills.Core
|
||||
|
||||
#endregion Singleton Setup
|
||||
|
||||
// Very early initialization - QuickAccess should be available immediately
|
||||
public override int ManagedAwakePriority => 5;
|
||||
|
||||
#region Manager Instances
|
||||
|
||||
// Core Managers
|
||||
@@ -46,7 +49,6 @@ namespace AppleHills.Core
|
||||
private PlayerTouchController _playerController;
|
||||
private FollowerController _followerController;
|
||||
private Camera _mainCamera;
|
||||
private bool _initialized = false;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the player GameObject. Finds it if not already cached.
|
||||
@@ -125,31 +127,31 @@ namespace AppleHills.Core
|
||||
|
||||
#endregion
|
||||
|
||||
#region Initialization and Scene Management
|
||||
#region Lifecycle Methods
|
||||
|
||||
private void Awake()
|
||||
private new void Awake()
|
||||
{
|
||||
_instance = this;
|
||||
base.Awake(); // CRITICAL: Register with LifecycleManager!
|
||||
|
||||
if (!_initialized)
|
||||
{
|
||||
// Subscribe to scene changes
|
||||
if (SceneManager != null)
|
||||
{
|
||||
SceneManager.SceneLoadCompleted += OnSceneLoadCompleted;
|
||||
}
|
||||
_initialized = true;
|
||||
}
|
||||
// Set instance immediately so it's available before OnManagedAwake() is called
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle scene changes by clearing cached references.
|
||||
/// </summary>
|
||||
private void OnSceneLoadCompleted(string sceneName)
|
||||
protected override void OnManagedAwake()
|
||||
{
|
||||
// QuickAccess has minimal initialization
|
||||
}
|
||||
|
||||
protected override void OnSceneUnloading()
|
||||
{
|
||||
// Clear references BEFORE scene unloads for better cleanup timing
|
||||
ClearReferences();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Reference Management
|
||||
|
||||
/// <summary>
|
||||
/// Clear all cached references.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user