added: item pickups with online persistency
This commit is contained in:
@@ -9,6 +9,8 @@ namespace NodeCanvas.Tasks.Conditions {
|
||||
public BBParameter<string> observerLabel;
|
||||
public BBParameter<RaycastHit> outputHitTo;
|
||||
|
||||
public bool deactivateOnFinish = true;
|
||||
|
||||
protected override string info{
|
||||
get {
|
||||
return $"Check Environment Observer, [\"{observerLabel.value}\"]";
|
||||
@@ -33,7 +35,9 @@ namespace NodeCanvas.Tasks.Conditions {
|
||||
|
||||
//Called whenever the condition gets disabled.
|
||||
protected override void OnDisable() {
|
||||
agent.FindObserverFromString(observerLabel.value).active = false;
|
||||
if (deactivateOnFinish){
|
||||
agent.FindObserverFromString(observerLabel.value).active = false;
|
||||
}
|
||||
}
|
||||
|
||||
//Called once per frame while the condition is active.
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion;
|
||||
using ParadoxNotion.Design;
|
||||
using ParadoxNotion.Services;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
@@ -12,15 +13,31 @@ namespace NodeCanvas.Tasks.Conditions {
|
||||
public class CheckInput : ConditionTask<Transform>{
|
||||
public BBParameter<string> actionName;
|
||||
public BBParameter<InputActionPhase> actionPhase;
|
||||
|
||||
private bool blocked;
|
||||
|
||||
private SignalDefinition signalDefinition;
|
||||
// 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 {
|
||||
signalDefinition = Resources.Load<SignalDefinition>("InputSignal");
|
||||
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;
|
||||
@@ -30,25 +47,52 @@ namespace NodeCanvas.Tasks.Conditions {
|
||||
}
|
||||
|
||||
protected override void OnEnable() {
|
||||
signalDefinition.onInvoke -= OnSignalInvoke;
|
||||
signalDefinition.onInvoke += OnSignalInvoke;
|
||||
inputSignalDefinition.onInvoke -= InputSignalInvoke;
|
||||
inputSignalDefinition.onInvoke += InputSignalInvoke;
|
||||
|
||||
blockInputDefinition.onInvoke -= BlockInputDefinition;
|
||||
blockInputDefinition.onInvoke += BlockInputDefinition;
|
||||
}
|
||||
|
||||
protected override void OnDisable() {
|
||||
signalDefinition.onInvoke -= OnSignalInvoke;
|
||||
inputSignalDefinition.onInvoke -= InputSignalInvoke;
|
||||
blockInputDefinition.onInvoke -= BlockInputDefinition;
|
||||
}
|
||||
|
||||
void OnSignalInvoke(Transform sender, Transform receiver, bool isGlobal, params object[] args){
|
||||
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];
|
||||
|
||||
if (actionName.value == thisAction.name && actionPhase.value == thisActionPhase) {
|
||||
// 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; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user