using Unity.AI.Navigation; using UnityEngine; using UnityEngine.UIElements; using UnityEngine.UI; public class HotelTycoonBootstrap : MonoBehaviour { [Header("Scene Setup")] [SerializeField] private bool autoSetupScene = true; [SerializeField] private bool createMainCamera = true; [SerializeField] private bool createUI = true; [SerializeField] private bool createNavMesh = true; [Header("Game Objects")] [SerializeField] private GameObject gameManagerPrefab; [SerializeField] private GameObject hotelManagerPrefab; [SerializeField] private GameObject staffManagerPrefab; [SerializeField] private GameObject facilityManagerPrefab; [SerializeField] private GameObject ratingSystemPrefab; private void Awake() { if (autoSetupScene) { SetupScene(); } } private void SetupScene() { Debug.Log("Setting up Hotel Tycoon scene..."); CreateEssentialManagers(); if (createMainCamera) SetupMainCamera(); if (createUI) SetupBasicUI(); if (createNavMesh) SetupNavMeshSurfaces(); CreateInitialRoomSetup(); CreateRoomBuilder(); Debug.Log("Hotel Tycoon scene setup complete!"); } #region Manager Creation private void CreateEssentialManagers() { // Create GameManager if (GameManager.Instance == null) { CreateManager("GameManager", gameManagerPrefab, typeof(GameManager)); } // Create HotelManager if (HotelManager.Instance == null) { CreateManager("HotelManager", hotelManagerPrefab, typeof(HotelManager)); } // Create StaffManager if (StaffManager.Instance == null) { CreateManager("StaffManager", staffManagerPrefab, typeof(StaffManager)); } // Create FacilityManager if (FacilityManager.Instance == null) { CreateManager("FacilityManager", facilityManagerPrefab, typeof(FacilityManager)); } // Create Rating System if (HotelRatingSystem.Instance == null) { CreateManager("HotelRatingSystem", ratingSystemPrefab, typeof(HotelRatingSystem)); } } private void CreateManager(string name, GameObject prefab, System.Type componentType) { GameObject manager; if (prefab != null) { manager = Instantiate(prefab); manager.name = name; } else { manager = new GameObject(name); manager.AddComponent(componentType); } DontDestroyOnLoad(manager); Debug.Log($"Created {name}"); } #endregion #region Camera Setup private void SetupMainCamera() { Camera existingCamera = Camera.main; if (existingCamera != null) { // Add camera controller to existing camera if (existingCamera.GetComponent() == null) { existingCamera.gameObject.AddComponent(); } } else { // Create new camera GameObject cameraObj = new GameObject("Main Camera"); Camera camera = cameraObj.AddComponent(); cameraObj.AddComponent(); cameraObj.AddComponent(); cameraObj.tag = "MainCamera"; // Position camera for good hotel view cameraObj.transform.position = new Vector3(0, 15f, -20f); cameraObj.transform.rotation = Quaternion.Euler(45f, 0f, 0f); } Debug.Log("Main camera setup complete"); } #endregion #region UI Setup private void SetupBasicUI() { // Create Canvas if it doesn't exist Canvas existingCanvas = FindObjectOfType(); if (existingCanvas == null) { GameObject canvasObj = new GameObject("Canvas"); Canvas canvas = canvasObj.AddComponent(); canvas.renderMode = RenderMode.ScreenSpaceOverlay; canvasObj.AddComponent(); canvasObj.AddComponent(); // Create Event System if needed if (FindObjectOfType() == null) { GameObject eventSystemObj = new GameObject("EventSystem"); eventSystemObj.AddComponent(); eventSystemObj.AddComponent(); } } // Create UI Controllers CreateUIController(); CreateGuestInfoUI(); Debug.Log("Basic UI setup complete"); } private void CreateUIController() { if (FindObjectOfType() == null) { GameObject uiControllerObj = new GameObject("UI Controller"); uiControllerObj.AddComponent(); } } private void CreateGuestInfoUI() { if (FindObjectOfType() == null) { GameObject guestInfoObj = new GameObject("Guest Info UI"); guestInfoObj.AddComponent(); } } #endregion #region NavMesh Setup private void SetupNavMeshSurfaces() { // Create a ground plane for navigation GameObject ground = GameObject.Find("Ground"); if (ground == null) { ground = GameObject.CreatePrimitive(PrimitiveType.Plane); ground.name = "Ground"; // Only set tag if it exists, otherwise skip try { ground.tag = "Ground"; } catch (UnityException) { Debug.LogWarning("Ground tag not defined in Tags and Layers. Create it in Project Settings > Tags and Layers if needed."); } ground.transform.position = Vector3.zero; ground.transform.localScale = new Vector3(20f, 1f, 20f); // Make it less visible but keep for navigation Renderer groundRenderer = ground.GetComponent(); groundRenderer.material.color = new Color(0.8f, 0.8f, 0.8f, 0.5f); } // Note: For NavMesh to work properly, you need to: // 1. Install Unity NavMesh Components package (Window > Package Manager > Unity Registry > AI Navigation) // 2. Or manually bake NavMesh through Window > AI > Navigation Debug.Log("NavMesh setup: Go to Window > AI > Navigation and click 'Bake' to create NavMesh for AI agents."); Debug.Log("NavMesh surfaces setup complete - manual baking required"); } #endregion #region Game Object Setup private void CreateInitialRoomSetup() { if (FindObjectOfType() == null) { GameObject initialRoomObj = new GameObject("Initial Room Setup"); initialRoomObj.AddComponent(); Debug.Log("Created Initial Room Setup"); } } private void CreateRoomBuilder() { // Remove old RoomBuilder if it exists RoomBuilder oldBuilder = FindFirstObjectByType(); if (oldBuilder != null) { DestroyImmediate(oldBuilder.gameObject); } // Create new building system if (FindFirstObjectByType() == null) { GameObject roomBuilderObj = new GameObject("New Room Builder"); NewRoomBuilder newBuilder = roomBuilderObj.AddComponent(); // Create UI Controller for building interface GameObject uiObj = new GameObject("Building UI Controller"); BuildingUIController uiController = uiObj.AddComponent(); // Add UIDocument component for the new UI UIDocument uiDocument = uiObj.AddComponent(); // Connect the UI to the builder uiController.roomBuilder = newBuilder; uiController.uiDocument = uiDocument; Debug.Log("Created New Room Builder with UI"); } } #endregion #region Debug and Validation private void OnValidate() { // Validate that essential components are present ValidateScene(); } private void ValidateScene() { if (autoSetupScene) { if (FindObjectOfType() == null && gameManagerPrefab == null) { Debug.LogWarning("No GameManager found and no prefab assigned!"); } } } [ContextMenu("Setup Scene Manually")] public void SetupSceneManually() { SetupScene(); } [ContextMenu("Validate Scene Setup")] public void ValidateSceneSetup() { Debug.Log("=== Hotel Tycoon Scene Validation ==="); Debug.Log($"GameManager: {(GameManager.Instance != null ? "✓" : "✗")}"); Debug.Log($"HotelManager: {(HotelManager.Instance != null ? "✓" : "✗")}"); Debug.Log($"StaffManager: {(StaffManager.Instance != null ? "✓" : "✗")}"); Debug.Log($"FacilityManager: {(FacilityManager.Instance != null ? "✓" : "✗")}"); Debug.Log($"RatingSystem: {(HotelRatingSystem.Instance != null ? "✓" : "✗")}"); Debug.Log($"Camera Controller: {(FindObjectOfType() != null ? "✓" : "✗")}"); Debug.Log($"UI Controller: {(FindObjectOfType() != null ? "✓" : "✗")}"); Debug.Log($"Room Builder: {(FindObjectOfType() != null ? "✓" : "✗")}"); Debug.Log($"Initial Room Setup: {(FindObjectOfType() != null ? "✓" : "✗")}"); Debug.Log("=== Validation Complete ==="); } #endregion }