using UnityEngine; using UnityEngine.UIElements; using System.Collections.Generic; public class TownManager : MonoBehaviour { [Header("Town Configuration")] public string townName = "Haven Village"; public bool hasHarbor = true; [Header("UI References")] public UIDocument townUI; public Camera townCamera; [Header("Shop Manager")] public TownShopManager shopManager; [Header("Team Reference")] [HideInInspector] public TeamCharacter[] currentTeam; private VisualElement rootElement; void Start() { InitializeTown(); SetupUI(); LoadTeamData(); } private void InitializeTown() { // Check if we have settlement context data if (SettlementContext.Instance != null) { // Use data from settlement context townName = SettlementContext.Instance.settlementName; hasHarbor = SettlementContext.Instance.hasHarbor; Debug.Log($"Initialized {townName} ({SettlementContext.Instance.settlementType}) from SettlementContext"); // Update UI with settlement name UpdateTownNameDisplay(); } else { Debug.Log($"Initialized {townName} (no SettlementContext - using defaults)"); } // Initialize shop manager if not already done if (shopManager == null) { // First check if singleton instance exists if (TownShopManager.Instance != null) { shopManager = TownShopManager.Instance; Debug.Log("TownManager: Using existing TownShopManager singleton"); } else { // Try to find any existing instance in scene shopManager = FindFirstObjectByType(); if (shopManager != null) { Debug.Log("TownManager: Found existing TownShopManager in scene"); } } } // If we still don't have a shop manager, create one if (shopManager == null) { Debug.Log("TownManager: Creating new TownShopManager"); GameObject shopManagerObj = new GameObject("TownShopManager"); shopManager = shopManagerObj.AddComponent(); shopManager.townUI = townUI; } else { Debug.Log($"TownManager: Using existing TownShopManager: {shopManager.gameObject.name}"); // Make sure the existing manager has the correct UI reference if (shopManager.townUI == null) { shopManager.townUI = townUI; Debug.Log("TownManager: Updated TownShopManager UI reference"); } } } private void SetupUI() { if (townUI == null) return; rootElement = townUI.rootVisualElement; UpdateTownNameDisplay(); // Let TownShopManager handle building interactions } private void UpdateTownNameDisplay() { if (rootElement == null) return; var townNameLabel = rootElement.Q