GameManager.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using UnityEngine;
  2. using UnityEngine.InputSystem;
  3. using System.Collections.Generic;
  4. public class GameManager : MonoBehaviour
  5. {
  6. public static GameManager Instance { get; private set; }
  7. [Header("Game State")]
  8. public bool isPaused = false;
  9. [Header("Systems")]
  10. public ResourceManager resourceManager;
  11. public TimeManager timeManager;
  12. public VillagerManager villagerManager;
  13. public SelectionManager selectionManager;
  14. void Awake()
  15. {
  16. // Singleton pattern
  17. if (Instance != null && Instance != this)
  18. {
  19. Destroy(gameObject);
  20. return;
  21. }
  22. Instance = this;
  23. DontDestroyOnLoad(gameObject);
  24. // Initialize systems
  25. InitializeSystems();
  26. }
  27. void InitializeSystems()
  28. {
  29. // Get or create system components
  30. resourceManager = GetComponent<ResourceManager>();
  31. if (resourceManager == null)
  32. resourceManager = gameObject.AddComponent<ResourceManager>();
  33. timeManager = GetComponent<TimeManager>();
  34. if (timeManager == null)
  35. timeManager = gameObject.AddComponent<TimeManager>();
  36. villagerManager = GetComponent<VillagerManager>();
  37. if (villagerManager == null)
  38. villagerManager = gameObject.AddComponent<VillagerManager>();
  39. selectionManager = GetComponent<SelectionManager>();
  40. if (selectionManager == null)
  41. selectionManager = gameObject.AddComponent<SelectionManager>();
  42. }
  43. void Start()
  44. {
  45. // Initialize starting resources
  46. resourceManager.AddResource(ResourceType.Wood, 50);
  47. resourceManager.AddResource(ResourceType.Stone, 30);
  48. resourceManager.AddResource(ResourceType.Food, 100);
  49. }
  50. void Update()
  51. {
  52. // Handle pause/unpause
  53. if (UnityEngine.InputSystem.Keyboard.current.spaceKey.wasPressedThisFrame)
  54. {
  55. TogglePause();
  56. }
  57. }
  58. public void TogglePause()
  59. {
  60. isPaused = !isPaused;
  61. timeManager.SetPaused(isPaused);
  62. }
  63. }