first commit
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
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<PlayerController>();
|
||||
if (playerStats == null) playerStats = FindObjectOfType<PlayerStats>();
|
||||
if (inventory == null) inventory = FindObjectOfType<OTGIntegrated.Inventory.Inventory>();
|
||||
if (levelSystem == null) levelSystem = FindObjectOfType<LevelSystem>();
|
||||
if (weaponManager == null) weaponManager = FindObjectOfType<WeaponManager>();
|
||||
if (abilityManager == null) abilityManager = FindObjectOfType<AbilityManager>();
|
||||
if (talentManager == null) talentManager = FindObjectOfType<TalentManager>();
|
||||
if (questManager == null) questManager = FindObjectOfType<QuestManager>();
|
||||
if (dialogueManager == null) dialogueManager = FindObjectOfType<DialogueManager>();
|
||||
if (craftingSystem == null) craftingSystem = FindObjectOfType<CraftingSystem>();
|
||||
if (uiManager == null) uiManager = FindObjectOfType<UIManager>();
|
||||
if (saveSystem == null) saveSystem = FindObjectOfType<SaveSystem>();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user