using System; using System.Collections.Generic; using NodeCanvas.Framework; using ParadoxNotion; using ParadoxNotion.Design; 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 SignalDefinition signalDefinition; protected override string info { get { return $"Input {actionName.value} was {actionPhase.value}"; } } protected override string OnInit(){ try { signalDefinition = Resources.Load("InputSignal"); } catch (Exception e) { Debug.LogError($"Error finding the Input Signal defintion: {e.Message}"); throw; } return null; } protected override void OnEnable() { signalDefinition.onInvoke -= OnSignalInvoke; signalDefinition.onInvoke += OnSignalInvoke; } protected override void OnDisable() { signalDefinition.onInvoke -= OnSignalInvoke; } void OnSignalInvoke(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]; if (actionName.value == thisAction.name && actionPhase.value == thisActionPhase) { YieldReturn(true); } } protected override bool OnCheck() { return false; } } }