diff --git a/Assets/Data/Bootstrap/Runtime/CustomBootSettings_Runtime.asset b/Assets/Data/Bootstrap/Runtime/CustomBootSettings_Runtime.asset index 3130718a..3b77c3c9 100644 --- a/Assets/Data/Bootstrap/Runtime/CustomBootSettings_Runtime.asset +++ b/Assets/Data/Bootstrap/Runtime/CustomBootSettings_Runtime.asset @@ -22,3 +22,4 @@ MonoBehaviour: - {fileID: 6399527186463168339, guid: ac41583865245bc4bb3de6c15929b9fc, type: 3} - {fileID: 2755712733105741372, guid: 70e6fca1164d9a140b271f4261f1f023, type: 3} - {fileID: 5034240524438268576, guid: adbb9bfd5489f3f4995966535ca5f24b, type: 3} + - {fileID: 2326026072467672024, guid: c8d9eb8c3ca524b4eb67f6364b455b87, type: 3} diff --git a/Assets/Prefabs/Managers/QuickAccess.prefab b/Assets/Prefabs/Managers/QuickAccess.prefab new file mode 100644 index 00000000..d052e0da --- /dev/null +++ b/Assets/Prefabs/Managers/QuickAccess.prefab @@ -0,0 +1,46 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &2326026072467672024 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2864744343528369288} + - component: {fileID: 8478071710053730667} + m_Layer: 0 + m_Name: QuickAccess + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2864744343528369288 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2326026072467672024} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 2.98359, y: 1.67676, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &8478071710053730667 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2326026072467672024} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 86c6fcf337334bf0a69a2d6e536c6f0b, type: 3} + m_Name: + m_EditorClassIdentifier: AppleHillsScripts::AppleHills.Core.QuickAccess diff --git a/Assets/Prefabs/Managers/QuickAccess.prefab.meta b/Assets/Prefabs/Managers/QuickAccess.prefab.meta new file mode 100644 index 00000000..319fc317 --- /dev/null +++ b/Assets/Prefabs/Managers/QuickAccess.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: c8d9eb8c3ca524b4eb67f6364b455b87 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Core/QuickAccess.cs b/Assets/Scripts/Core/QuickAccess.cs new file mode 100644 index 00000000..17d43235 --- /dev/null +++ b/Assets/Scripts/Core/QuickAccess.cs @@ -0,0 +1,185 @@ +using UnityEngine; +using Interactions; +using System.Collections.Generic; +using AppleHills.Core.Settings; +using AppleHills.Data.CardSystem; +using CinematicsM; +using Core; +using Input; +using Minigames.DivingForPictures; +using PuzzleS; + +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. + /// + public class QuickAccess : MonoBehaviour + { + #region Singleton Setup + private static QuickAccess _instance; + private static bool _isQuitting = false; + + public static QuickAccess Instance + { + get + { + if (_instance == null && Application.isPlaying && !_isQuitting) + { + _instance = FindAnyObjectByType(); + if (_instance == null) + { + var go = new GameObject("QuickAccess"); + _instance = go.AddComponent(); + } + } + return _instance; + } + } + + void OnApplicationQuit() + { + _isQuitting = true; + } + #endregion Singleton Setup + + #region Manager Instances + + // Core Managers + public GameManager GameManager => GameManager.Instance; + public ItemManager ItemManager => ItemManager.Instance; + public SceneManagerService SceneManager => SceneManagerService.Instance; + + // Other Managers + public InputManager InputManager => InputManager.Instance; + public PuzzleManager PuzzleManager => PuzzleManager.Instance; + public CinematicsManager CinematicsManager => CinematicsManager.Instance; + public CardSystemManager CardSystemManager => CardSystemManager.Instance; + + #endregion + + #region Player and Follower References + + private GameObject _playerGameObject; + private GameObject _followerGameObject; + private PlayerTouchController _playerController; + private FollowerController _followerController; + private Camera _mainCamera; + private bool _initialized = false; + + /// + /// Returns the player GameObject. Finds it if not already cached. + /// + public GameObject PlayerGameObject + { + get + { + if (_playerGameObject == null) + { + _playerGameObject = GameObject.FindGameObjectWithTag("Player"); + } + return _playerGameObject; + } + } + + /// + /// Returns the follower (Pulver) GameObject. Finds it if not already cached. + /// + public GameObject FollowerGameObject + { + get + { + if (_followerGameObject == null) + { + _followerGameObject = GameObject.FindGameObjectWithTag("Pulver"); + } + return _followerGameObject; + } + } + + /// + /// Returns the player controller component. Finds it if not already cached. + /// + public PlayerTouchController PlayerController + { + get + { + if (_playerController == null && PlayerGameObject != null) + { + _playerController = PlayerGameObject.GetComponent(); + } + return _playerController; + } + } + + /// + /// Returns the follower controller component. Finds it if not already cached. + /// + public FollowerController FollowerController + { + get + { + if (_followerController == null && FollowerGameObject != null) + { + _followerController = FollowerGameObject.GetComponent(); + } + return _followerController; + } + } + + /// + /// Returns the main camera. Caches for performance. + /// + public Camera MainCamera + { + get + { + if (_mainCamera == null) + { + _mainCamera = Camera.main; + } + return _mainCamera; + } + } + + #endregion + + #region Initialization and Scene Management + + private void Awake() + { + if (!_initialized) + { + // Subscribe to scene changes + if (SceneManager != null) + { + SceneManager.SceneLoadCompleted += OnSceneLoadCompleted; + } + _initialized = true; + } + } + + /// + /// Handle scene changes by clearing cached references. + /// + private void OnSceneLoadCompleted(string sceneName) + { + ClearReferences(); + } + + /// + /// Clear all cached references. + /// + public void ClearReferences() + { + _playerGameObject = null; + _followerGameObject = null; + _playerController = null; + _followerController = null; + _mainCamera = null; + } + + #endregion + } +} diff --git a/Assets/Scripts/Core/QuickAccess.cs.meta b/Assets/Scripts/Core/QuickAccess.cs.meta new file mode 100644 index 00000000..bbfe6606 --- /dev/null +++ b/Assets/Scripts/Core/QuickAccess.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 86c6fcf337334bf0a69a2d6e536c6f0b +timeCreated: 1760104860 \ No newline at end of file diff --git a/Assets/Scripts/Examples.meta b/Assets/Scripts/Examples.meta new file mode 100644 index 00000000..b41c61b7 --- /dev/null +++ b/Assets/Scripts/Examples.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d5112d15beb144088e8b8752879deda3 +timeCreated: 1760105142 \ No newline at end of file diff --git a/Assets/Scripts/Examples/QuickAccessExample.cs b/Assets/Scripts/Examples/QuickAccessExample.cs new file mode 100644 index 00000000..a7a5cb1d --- /dev/null +++ b/Assets/Scripts/Examples/QuickAccessExample.cs @@ -0,0 +1,85 @@ +using UnityEngine; +using AppleHills.Core; + +namespace AppleHills.Examples +{ + /// + /// Example script demonstrating how to use QuickAccess to quickly retrieve and use game objects + /// + public class QuickAccessExample : MonoBehaviour + { + void Start() + { + // Retrieve player and follower objects using QuickAccess + GameObject player = QuickAccess.Instance.PlayerGameObject; + GameObject follower = QuickAccess.Instance.FollowerGameObject; + + // Print info about the player + if (player != null) + { + Debug.Log($"[QuickAccessExample] Player found: {player.name}"); + Debug.Log($"[QuickAccessExample] Player position: {player.transform.position}"); + + // Access player controller + var playerController = QuickAccess.Instance.PlayerController; + if (playerController != null) + { + Debug.Log($"[QuickAccessExample] Player controller found on object"); + } + else + { + Debug.LogWarning($"[QuickAccessExample] Player controller not found"); + } + } + else + { + Debug.LogWarning($"[QuickAccessExample] Player not found in scene"); + } + + // Print info about the follower (Pulver) + if (follower != null) + { + Debug.Log($"[QuickAccessExample] Follower found: {follower.name}"); + Debug.Log($"[QuickAccessExample] Follower position: {follower.transform.position}"); + + // Access follower controller + var followerController = QuickAccess.Instance.FollowerController; + if (followerController != null) + { + Debug.Log($"[QuickAccessExample] Follower controller found on object"); + } + else + { + Debug.LogWarning($"[QuickAccessExample] Follower controller not found"); + } + } + else + { + Debug.LogWarning($"[QuickAccessExample] Follower not found in scene"); + } + + // Access camera + var camera = QuickAccess.Instance.MainCamera; + if (camera != null) + { + Debug.Log($"[QuickAccessExample] Main camera found: {camera.name}"); + Debug.Log($"[QuickAccessExample] Camera position: {camera.transform.position}"); + } + else + { + Debug.LogWarning($"[QuickAccessExample] Main camera not found"); + } + + // Access managers + try + { + Debug.Log($"[QuickAccessExample] Game Manager instance accessed: {QuickAccess.Instance.GameManager != null}"); + Debug.Log($"[QuickAccessExample] Input Manager instance accessed: {QuickAccess.Instance.InputManager != null}"); + } + catch (System.Exception e) + { + Debug.LogError($"[QuickAccessExample] Error accessing managers: {e.Message}"); + } + } + } +} diff --git a/Assets/Scripts/Examples/QuickAccessExample.cs.meta b/Assets/Scripts/Examples/QuickAccessExample.cs.meta new file mode 100644 index 00000000..1e28d7e1 --- /dev/null +++ b/Assets/Scripts/Examples/QuickAccessExample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c6086c2645c14cad92be0a9c7c191fdc +timeCreated: 1760105142 \ No newline at end of file diff --git a/Assets/Scripts/Utils/QuickAccess.cs b/Assets/Scripts/Utils/QuickAccess.cs deleted file mode 100644 index 952319b3..00000000 --- a/Assets/Scripts/Utils/QuickAccess.cs +++ /dev/null @@ -1,32 +0,0 @@ -using UnityEngine; - -namespace Utils -{ - public class QuickAccess : MonoBehaviour - { - private static QuickAccess _instance; - private static bool _isQuitting = false; - - public static QuickAccess Instance - { - get - { - if (_instance == null && Application.isPlaying && !_isQuitting) - { - _instance = FindAnyObjectByType(); - if (_instance == null) - { - var go = new GameObject("QuickAccess"); - _instance = go.AddComponent(); - } - } - return _instance; - } - } - - void OnApplicationQuit() - { - _isQuitting = true; - } - } -} \ No newline at end of file diff --git a/Assets/Scripts/Utils/QuickAccess.cs.meta b/Assets/Scripts/Utils/QuickAccess.cs.meta deleted file mode 100644 index cf88c407..00000000 --- a/Assets/Scripts/Utils/QuickAccess.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: e276089fbc344b3d8cb14729dbe3508a -timeCreated: 1760095787 \ No newline at end of file