| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using UnityEngine;
- /// <summary>
- /// Bridge component that connects SettlementInteractionManager's GameObject control
- /// with SettlementInteractionUI's UI Toolkit system
- /// </summary>
- public class SettlementUIBridge : MonoBehaviour
- {
- [Header("UI Bridge")]
- [Tooltip("The SettlementInteractionUI component to control")]
- public SettlementInteractionUI settlementUI;
- [Tooltip("Should this GameObject's active state control the UI visibility?")]
- public bool controlUIVisibility = true;
- private bool lastActiveState;
- void Start()
- {
- // Find SettlementInteractionUI if not assigned
- if (settlementUI == null)
- {
- // First try to get from same GameObject
- settlementUI = GetComponent<SettlementInteractionUI>();
- }
- if (settlementUI == null)
- {
- // Then try to find in scene
- settlementUI = FindFirstObjectByType<SettlementInteractionUI>();
- }
- if (settlementUI != null)
- {
- // Force initial state
- lastActiveState = gameObject.activeSelf;
- UpdateUIVisibility();
- }
- else
- {
- Debug.LogError("[UIBridge] SettlementInteractionUI not found! Make sure it's on the same GameObject.");
- }
- }
- void Update()
- {
- if (!controlUIVisibility) return;
- // Check if GameObject active state changed
- bool currentActiveState = gameObject.activeSelf;
- if (currentActiveState != lastActiveState)
- {
- lastActiveState = currentActiveState;
- UpdateUIVisibility();
- }
- }
- private void UpdateUIVisibility()
- {
- if (settlementUI == null) return;
- if (gameObject.activeSelf)
- {
- // Force UI to show with test data if no real settlement detected
- settlementUI.ForceShowUI();
- }
- else
- {
- settlementUI.ForceHideUI();
- }
- }
- void OnEnable()
- {
- UpdateUIVisibility();
- }
- void OnDisable()
- {
- if (settlementUI != null)
- {
- settlementUI.ForceHideUI();
- }
- }
- }
|