using OTGIntegrated.Abilities; using OTGIntegrated.Crafting; using OTGIntegrated.Dialogue; using OTGIntegrated.Inventory; using OTGIntegrated.Player; using OTGIntegrated.Quests; using OTGIntegrated.Save; using OTGIntegrated.Stats; using OTGIntegrated.Talents; using OTGIntegrated.UI; using OTGIntegrated.Weapons; using UnityEngine; namespace OTGIntegrated.Core { public sealed class GameManager : MonoBehaviour { public static GameManager Instance { get; private set; } [Header("Player")] public PlayerController playerController; public PlayerStats playerStats; public OTGIntegrated.Inventory.Inventory inventory; public LevelSystem levelSystem; public WeaponManager weaponManager; public AbilityManager abilityManager; public TalentManager talentManager; [Header("World Systems")] public QuestManager questManager; public DialogueManager dialogueManager; public CraftingSystem craftingSystem; [Header("UI / Save")] public UIManager uiManager; public SaveSystem saveSystem; private bool initialized; private void Awake() { if (Instance != null && Instance != this) { Destroy(gameObject); return; } Instance = this; ResolveMissingReferences(); InitializeSystems(); } public void ResolveMissingReferences() { if (playerController == null) playerController = FindObjectOfType(); if (playerStats == null) playerStats = FindObjectOfType(); if (inventory == null) inventory = FindObjectOfType(); if (levelSystem == null) levelSystem = FindObjectOfType(); if (weaponManager == null) weaponManager = FindObjectOfType(); if (abilityManager == null) abilityManager = FindObjectOfType(); if (talentManager == null) talentManager = FindObjectOfType(); if (questManager == null) questManager = FindObjectOfType(); if (dialogueManager == null) dialogueManager = FindObjectOfType(); if (craftingSystem == null) craftingSystem = FindObjectOfType(); if (uiManager == null) uiManager = FindObjectOfType(); if (saveSystem == null) saveSystem = FindObjectOfType(); } public void InitializeSystems() { if (initialized) { return; } if (playerController != null) playerController.Initialize(playerStats); if (levelSystem != null) levelSystem.Initialize(talentManager); if (weaponManager != null) weaponManager.Initialize(playerStats, inventory); if (abilityManager != null) abilityManager.Initialize(playerStats); if (talentManager != null) talentManager.Initialize(playerStats); if (questManager != null) questManager.Initialize(inventory, levelSystem, talentManager); if (dialogueManager != null) dialogueManager.Initialize(questManager, uiManager, playerController); if (craftingSystem != null) craftingSystem.Initialize(inventory, uiManager); if (uiManager != null) uiManager.Initialize(playerController); if (saveSystem != null) saveSystem.Initialize(this); ValidateReferences(); initialized = true; } private void ValidateReferences() { Require(playerStats, "PlayerStats"); Require(inventory, "Inventory"); Require(levelSystem, "LevelSystem"); Require(weaponManager, "WeaponManager"); Require(abilityManager, "AbilityManager"); Require(talentManager, "TalentManager"); Require(questManager, "QuestManager"); Require(dialogueManager, "DialogueManager"); Require(craftingSystem, "CraftingSystem"); Require(uiManager, "UIManager"); Require(saveSystem, "SaveSystem"); } private void Require(Object value, string label) { if (value == null) { Debug.LogWarning($"GameManager reference is missing: {label}", this); } } } }