| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- 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<CameraController>() == null)
- {
- existingCamera.gameObject.AddComponent<CameraController>();
- }
- }
- else
- {
- // Create new camera
- GameObject cameraObj = new GameObject("Main Camera");
- Camera camera = cameraObj.AddComponent<Camera>();
- cameraObj.AddComponent<AudioListener>();
- cameraObj.AddComponent<CameraController>();
- 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<Canvas>();
- if (existingCanvas == null)
- {
- GameObject canvasObj = new GameObject("Canvas");
- Canvas canvas = canvasObj.AddComponent<Canvas>();
- canvas.renderMode = RenderMode.ScreenSpaceOverlay;
- canvasObj.AddComponent<CanvasScaler>();
- canvasObj.AddComponent<UnityEngine.UI.GraphicRaycaster>();
- // Create Event System if needed
- if (FindObjectOfType<UnityEngine.EventSystems.EventSystem>() == null)
- {
- GameObject eventSystemObj = new GameObject("EventSystem");
- eventSystemObj.AddComponent<UnityEngine.EventSystems.EventSystem>();
- eventSystemObj.AddComponent<UnityEngine.EventSystems.StandaloneInputModule>();
- }
- }
- // Create UI Controllers
- CreateUIController();
- CreateGuestInfoUI();
- Debug.Log("Basic UI setup complete");
- }
- private void CreateUIController()
- {
- if (FindObjectOfType<UIController>() == null)
- {
- GameObject uiControllerObj = new GameObject("UI Controller");
- uiControllerObj.AddComponent<UIController>();
- }
- }
- private void CreateGuestInfoUI()
- {
- if (FindObjectOfType<GuestInfoUI>() == null)
- {
- GameObject guestInfoObj = new GameObject("Guest Info UI");
- guestInfoObj.AddComponent<GuestInfoUI>();
- }
- }
- #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<Renderer>();
- 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<InitialRoomSetup>() == null)
- {
- GameObject initialRoomObj = new GameObject("Initial Room Setup");
- initialRoomObj.AddComponent<InitialRoomSetup>();
- Debug.Log("Created Initial Room Setup");
- }
- }
- private void CreateRoomBuilder()
- {
- // Remove old RoomBuilder if it exists
- RoomBuilder oldBuilder = FindFirstObjectByType<RoomBuilder>();
- if (oldBuilder != null)
- {
- DestroyImmediate(oldBuilder.gameObject);
- }
- // Create new building system
- if (FindFirstObjectByType<NewRoomBuilder>() == null)
- {
- GameObject roomBuilderObj = new GameObject("New Room Builder");
- NewRoomBuilder newBuilder = roomBuilderObj.AddComponent<NewRoomBuilder>();
- // Create UI Controller for building interface
- GameObject uiObj = new GameObject("Building UI Controller");
- BuildingUIController uiController = uiObj.AddComponent<BuildingUIController>();
- // Add UIDocument component for the new UI
- UIDocument uiDocument = uiObj.AddComponent<UIDocument>();
- // 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<GameManager>() == 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<CameraController>() != null ? "✓" : "✗")}");
- Debug.Log($"UI Controller: {(FindObjectOfType<UIController>() != null ? "✓" : "✗")}");
- Debug.Log($"Room Builder: {(FindObjectOfType<RoomBuilder>() != null ? "✓" : "✗")}");
- Debug.Log($"Initial Room Setup: {(FindObjectOfType<InitialRoomSetup>() != null ? "✓" : "✗")}");
- Debug.Log("=== Validation Complete ===");
- }
- #endregion
- }
|