using System; using System.Collections.Generic; using NodeCanvas.Framework; using ParadoxNotion; using ParadoxNotion.Design; using ParadoxNotion.Services; using UnityEngine; using UnityEngine.InputSystem; namespace NodeCanvas.Tasks.Conditions { [Category("Reset/Input")] [Description("Check if input condition was matched this frame by phase.")] public class CheckInput : ConditionTask{ public BBParameter actionName; public BBParameter actionPhase; private bool blocked; // Add buffered input here private SignalDefinition inputSignalDefinition; private SignalDefinition blockInputDefinition; protected override string info { get { return $"Input {actionName.value} was {actionPhase.value}"; } } protected override string OnInit(){ MonoManager.current.onLateUpdate += UnblockOnFrameEnd; try { inputSignalDefinition = Resources.Load("InputSignal"); } catch (Exception e) { Debug.LogError($"Error finding the Input Signal defintion: {e.Message}"); throw; } try { blockInputDefinition = Resources.Load("BlockInputSignal"); } catch (Exception e) { Debug.LogError($"Error finding the Input Signal defintion: {e.Message}"); throw; } return null; } protected override void OnEnable() { inputSignalDefinition.onInvoke -= InputSignalInvoke; inputSignalDefinition.onInvoke += InputSignalInvoke; blockInputDefinition.onInvoke -= BlockInputDefinition; blockInputDefinition.onInvoke += BlockInputDefinition; } protected override void OnDisable() { inputSignalDefinition.onInvoke -= InputSignalInvoke; blockInputDefinition.onInvoke -= BlockInputDefinition; } void InputSignalInvoke(Transform sender, Transform receiver, bool isGlobal, params object[] args){ // Take the input arguments as objects and convert them to InputAction & Phases InputAction thisAction = (InputAction)args[0]; InputActionPhase thisActionPhase = (InputActionPhase)args[1]; // Debug.Log(thisActionPhase); if (actionName.value == thisAction.name && actionPhase.value == thisActionPhase && !blocked) { Debug.Log($"Recieved an unblocked {thisAction} @ {Time.time}."); YieldReturn(true); } } void BlockInputDefinition(Transform sender, Transform receiver, bool isGlobal, params object[] args){ // Take the input arguments as objects and convert them to InputAction & Phases string thisAction = (string)args[0]; if (actionName.value == thisAction) { Debug.Log($"Blocking {thisAction} @ {Time.time}."); blocked = true; } } void UnblockOnFrameEnd(){ if (blocked) { blocked = false; Debug.Log($"Unblocking {actionName} @ {Time.time}."); } } protected override bool OnCheck() { return false; } } }