99 lines
2.8 KiB
C#
99 lines
2.8 KiB
C#
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<Transform>{
|
|
public BBParameter<string> actionName;
|
|
public BBParameter<InputActionPhase> actionPhase;
|
|
|
|
private bool blocked;
|
|
|
|
// Add buffered input here
|
|
|
|
|
|
|
|
private SignalDefinition inputSignalDefinition;
|
|
private SignalDefinition blockInputDefinition;
|
|
protected override string info {
|
|
get { return $"Input <b>{actionName.value}</b> was <b>{actionPhase.value}</b>"; }
|
|
}
|
|
|
|
protected override string OnInit(){
|
|
MonoManager.current.onLateUpdate += UnblockOnFrameEnd;
|
|
|
|
try {
|
|
inputSignalDefinition = Resources.Load<SignalDefinition>("InputSignal");
|
|
} catch (Exception e) {
|
|
Debug.LogError($"Error finding the Input Signal defintion: {e.Message}");
|
|
throw;
|
|
}
|
|
|
|
try {
|
|
blockInputDefinition = Resources.Load<SignalDefinition>("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; }
|
|
|
|
}
|
|
}
|
|
|