using System; using Convai.Scripts.Utils; using UnityEngine; #if ENABLE_INPUT_SYSTEM using UnityEngine.InputSystem; #endif /// /// Controls player input to trigger a notification if there is no active NPC available for conversation. /// public class ActiveNPCChecker : MonoBehaviour { #if ENABLE_INPUT_SYSTEM /// /// Subscribes to the talk key input action when the script starts. /// private void Start() { ConvaiInputManager.Instance.GetTalkKeyAction().started += ConvaiInputManager_TalkKeyActionStarted; } /// /// Unsubscribes from the talk key input action when the script is destroyed. /// private void OnDestroy() { ConvaiInputManager.Instance.GetTalkKeyAction().started -= ConvaiInputManager_TalkKeyActionStarted; } /// /// Handles the talk key action and triggers a notification if no active NPC is available. /// /// The input context of the talk key action. private void ConvaiInputManager_TalkKeyActionStarted(InputAction.CallbackContext input) { try { if (!input.action.WasPressedThisFrame() || UIUtilities.IsAnyInputFieldFocused() || ConvaiNPCManager.Instance.activeConvaiNPC == null || ConvaiNPCManager.Instance.CheckForNPCToNPCConversation(ConvaiNPCManager.Instance.activeConvaiNPC)) if (ConvaiNPCManager.Instance.activeConvaiNPC == null && ConvaiNPCManager.Instance.nearbyNPC == null) NotificationSystemHandler.Instance.NotificationRequest(NotificationType.NotCloseEnoughForConversation); } catch (NullReferenceException) { Debug.Log("No active NPC available for conversation"); } } #elif ENABLE_LEGACY_INPUT_MANAGER private void Update() { if (ConvaiInputManager.Instance.WasTalkKeyPressed()) { if (ConvaiNPCManager.Instance.activeConvaiNPC == null) NotificationSystemHandler.Instance.NotificationRequest(NotificationType.NotCloseEnoughForConversation); } } #endif }