changed: rebuilt player input management

This commit is contained in:
Chris
2025-08-01 16:50:05 -04:00
parent 6ebfd4ef2b
commit f2df9a6910
7 changed files with 106 additions and 41 deletions

View File

@@ -1,49 +1,54 @@
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")]
[Description("Check if input condition was matched this frame by phase.")]
public class CheckInput : ConditionTask<Transform>{
public BBParameter<string> actionName;
public BBParameter<string> actionValue;
public BBParameter<InputActionPhase> actionPhase;
private SignalDefinition signalDefinition;
protected override string info {
get { return "Player Input"; }
get { return $"Input <b>{actionName.value}</b> was <b>{actionPhase.value}</b>"; }
}
private InputAction action;
//Use for initialization. This is called only once in the lifetime of the task.
//Return null if init was successfull. Return an error string otherwise
protected override string OnInit(){
try {
signalDefinition = Resources.Load<SignalDefinition>("InputSignal");
} catch (Exception e) {
Debug.LogError($"Error finding the Input Signal defintion: {e.Message}");
throw;
}
return null;
}
//Called whenever the condition gets enabled.
protected override void OnEnable(){
action = agent.GetComponent<PlayerInput>().actions.FindAction(actionName.value);
protected override void OnEnable() {
signalDefinition.onInvoke -= OnSignalInvoke;
signalDefinition.onInvoke += OnSignalInvoke;
}
//Called whenever the condition gets disabled.
protected override void OnDisable() {
signalDefinition.onInvoke -= OnSignalInvoke;
}
//Called once per frame while the condition is active.
//Return whether the condition is success or failure.
protected override bool OnCheck() {
// if (action.type == InputActionType.Button){
if (action.WasPressedThisFrame()) { return true; }
// } else if (action.type == InputActionType.Value) {
//
// }
return false;
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; }
}
}