using UnityEngine; using UnityEngine.UI; using TMPro; using System; public class ReviewPromptUI : MonoBehaviour { [Header("UI References")] [SerializeField] private GameObject promptPanel; [SerializeField] private TextMeshProUGUI promptText; [SerializeField] private Button brokenButton; [SerializeField] private Button okButton; private Action currentCallback; private GameObject currentObject; private void OnEnable() { SubscribeToLevelManager(); } private void OnDisable() { UnsubscribeFromLevelManager(); } private void Start() { // Hide panel initially if (promptPanel != null) { promptPanel.SetActive(false); } else { Debug.LogError("ReviewPromptUI: Prompt Panel is NULL in Start!"); } // Setup button listeners if (brokenButton != null) { brokenButton.onClick.AddListener(() => OnReviewResponse(true)); } else { Debug.LogError("ReviewPromptUI: Broken Button is NULL!"); } if (okButton != null) { okButton.onClick.AddListener(() => OnReviewResponse(false)); } else { Debug.LogError("ReviewPromptUI: OK Button is NULL!"); } // Ensure subscription (in case OnEnable ran before LevelManager existed) SubscribeToLevelManager(); } private void SubscribeToLevelManager() { if (LevelManager.Instance != null) { LevelManager.Instance.OnRequestReview -= ShowReviewPrompt; // Remove first to avoid double subscription LevelManager.Instance.OnRequestReview += ShowReviewPrompt; } } private void UnsubscribeFromLevelManager() { if (LevelManager.Instance != null) { LevelManager.Instance.OnRequestReview -= ShowReviewPrompt; } } private void ShowReviewPrompt(GameObject obj, Action callback) { // Hide interaction pop-up when showing review prompt if (PopUpManager.Instance != null) { PopUpManager.Instance.HidePopUp(); } currentObject = obj; currentCallback = callback; // Unlock cursor so player can click buttons Cursor.lockState = CursorLockMode.None; Cursor.visible = true; // Pause game (optional - remove if you want gameplay to continue) Time.timeScale = 0f; // Show the panel if (promptPanel != null) { promptPanel.SetActive(true); } else { Debug.LogError("ReviewPromptUI: PromptPanel is NULL! Assign it in the Inspector."); } // Update prompt text if (promptText != null) { string objectName = obj != null ? obj.name : "Item"; promptText.text = $"Is the {objectName} working correctly?"; } else { Debug.LogError("ReviewPromptUI: PromptText is NULL! Assign it in the Inspector."); } } private void OnReviewResponse(bool isBroken) { // Hide the panel if (promptPanel != null) { promptPanel.SetActive(false); } // Lock cursor back for gameplay Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; // Resume game Time.timeScale = 1f; // Invoke the callback currentCallback?.Invoke(isBroken); // Clear references currentObject = null; currentCallback = null; } }