using UnityEngine; using System; public class GameManager : MonoBehaviour { #region Singleton public static GameManager Instance { get; private set; } private void Awake() { if (Instance != null && Instance != this) { Destroy(this.gameObject); return; } Instance = this; DontDestroyOnLoad(this.gameObject); } #endregion [Header("Game Speed Settings")] [SerializeField] private float normalSpeed = 1f; [SerializeField] private float fastSpeed = 2f; [SerializeField] private float ultraSpeed = 4f; [Header("Game State")] public GameState currentGameState = GameState.Building; [Header("Hotel Requirements")] public bool hasEntrance = false; public bool hasReception = false; public bool canOpenHotel = false; [Header("UI References")] [SerializeField] private UnityEngine.UI.Text speedText; [SerializeField] private UnityEngine.UI.Text gameStateText; public enum GameSpeed { Paused = 0, Normal = 1, Fast = 2, Ultra = 3 } public enum GameState { Building, PreOpening, Operating, Paused } private GameSpeed currentSpeed = GameSpeed.Normal; // Events public static event Action OnSpeedChanged; public static event Action OnGameStateChanged; public static event Action OnHotelOpened; void Start() { SetGameSpeed(GameSpeed.Normal); UpdateGameState(); } void Update() { HandleSpeedInput(); CheckHotelRequirements(); UpdateUI(); } #region Speed Control private void HandleSpeedInput() { if (Input.GetKeyDown(KeyCode.Alpha1)) { SetGameSpeed(GameSpeed.Paused); } else if (Input.GetKeyDown(KeyCode.Alpha2)) { SetGameSpeed(GameSpeed.Normal); } else if (Input.GetKeyDown(KeyCode.Alpha3)) { SetGameSpeed(GameSpeed.Fast); } else if (Input.GetKeyDown(KeyCode.Alpha4)) { SetGameSpeed(GameSpeed.Ultra); } } public void SetGameSpeed(GameSpeed speed) { currentSpeed = speed; switch (speed) { case GameSpeed.Paused: Time.timeScale = 0f; break; case GameSpeed.Normal: Time.timeScale = normalSpeed; break; case GameSpeed.Fast: Time.timeScale = fastSpeed; break; case GameSpeed.Ultra: Time.timeScale = ultraSpeed; break; } OnSpeedChanged?.Invoke(speed); Debug.Log($"Game speed changed to: {speed} (TimeScale: {Time.timeScale})"); } public GameSpeed GetCurrentSpeed() { return currentSpeed; } #endregion #region Game State Management private void CheckHotelRequirements() { bool previousCanOpen = canOpenHotel; canOpenHotel = hasEntrance && hasReception; if (canOpenHotel && !previousCanOpen && currentGameState == GameState.Building) { currentGameState = GameState.PreOpening; OnGameStateChanged?.Invoke(currentGameState); } } public void OpenHotel() { if (canOpenHotel) { currentGameState = GameState.Operating; OnGameStateChanged?.Invoke(currentGameState); OnHotelOpened?.Invoke(); Debug.Log("Hotel is now open for business!"); } else { Debug.LogWarning("Cannot open hotel: Missing requirements (Entrance: " + hasEntrance + ", Reception: " + hasReception + ")"); } } public void SetEntrance(bool value) { hasEntrance = value; Debug.Log("Hotel entrance: " + (value ? "Added" : "Removed")); } public void SetReception(bool value) { hasReception = value; Debug.Log("Hotel reception: " + (value ? "Added" : "Removed")); } private void UpdateGameState() { OnGameStateChanged?.Invoke(currentGameState); } #endregion #region UI Updates private void UpdateUI() { if (speedText != null) { speedText.text = $"Speed: {currentSpeed} ({Time.timeScale}x)"; } if (gameStateText != null) { string stateInfo = $"State: {currentGameState}"; if (currentGameState == GameState.Building || currentGameState == GameState.PreOpening) { stateInfo += $"\nEntrance: {(hasEntrance ? "✓" : "✗")}"; stateInfo += $"\nReception: {(hasReception ? "✓" : "✗")}"; if (canOpenHotel) { stateInfo += "\n[Ready to Open!]"; } } gameStateText.text = stateInfo; } } #endregion #region Utility Methods public bool IsGamePaused() { return currentSpeed == GameSpeed.Paused || currentGameState == GameState.Paused; } public bool IsHotelOperating() { return currentGameState == GameState.Operating; } public bool IsBuilding() { return currentGameState == GameState.Building; } #endregion }