From 77fcd2059af4a713171a581f70d2c9cbdab5166b Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 20 Oct 2025 13:45:23 -0400 Subject: [PATCH] added: new tasks for interactions with units --- .../Core/Graph Tasks/IsInteractable.cs | 49 ++++++++++++++ .../Core/Graph Tasks/IsInteractable.cs.meta | 2 + .../Core/Graph Tasks/SendAnimationTrigger.cs | 49 ++++++++++++++ .../Graph Tasks/SendAnimationTrigger.cs.meta | 2 + .../Core/Graph Tasks/SendEventToUnit.cs | 66 +++++++++++++++++++ .../Core/Graph Tasks/SendEventToUnit.cs.meta | 2 + 6 files changed, 170 insertions(+) create mode 100644 Assets/Scripts/Core/Graph Tasks/IsInteractable.cs create mode 100644 Assets/Scripts/Core/Graph Tasks/IsInteractable.cs.meta create mode 100644 Assets/Scripts/Core/Graph Tasks/SendAnimationTrigger.cs create mode 100644 Assets/Scripts/Core/Graph Tasks/SendAnimationTrigger.cs.meta create mode 100644 Assets/Scripts/Core/Graph Tasks/SendEventToUnit.cs create mode 100644 Assets/Scripts/Core/Graph Tasks/SendEventToUnit.cs.meta diff --git a/Assets/Scripts/Core/Graph Tasks/IsInteractable.cs b/Assets/Scripts/Core/Graph Tasks/IsInteractable.cs new file mode 100644 index 0000000..5247671 --- /dev/null +++ b/Assets/Scripts/Core/Graph Tasks/IsInteractable.cs @@ -0,0 +1,49 @@ +using NodeCanvas.Framework; +using ParadoxNotion.Design; +using UnityEngine; + + +namespace Reset.Core { + + [Category("Reset")] + [Description("Checks if the object has IInteractable and if the interactable object is available for use.")] + public class IsInteractable : ConditionTask{ + public BBParameter target; + protected override string info{ + + + get{ + // string agentName = agent == null ? agentType.ToString() : target.ToString(); + return $"{target.ToString()} is interactable"; + } + } + + //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(){ + return null; + } + + //Called whenever the condition gets enabled. + protected override void OnEnable() { + + } + + //Called whenever the condition gets disabled. + protected override void OnDisable() { + + } + + //Called once per frame while the condition is active. + //Return whether the condition is success or failure. + protected override bool OnCheck(){ + IInteractable interactable = agent.GetComponent(); + + if (interactable == null) { + return false; + } + + return interactable.CanInteract(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Core/Graph Tasks/IsInteractable.cs.meta b/Assets/Scripts/Core/Graph Tasks/IsInteractable.cs.meta new file mode 100644 index 0000000..8767717 --- /dev/null +++ b/Assets/Scripts/Core/Graph Tasks/IsInteractable.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 05ba64cebc9dea24daaf3f204b387610 \ No newline at end of file diff --git a/Assets/Scripts/Core/Graph Tasks/SendAnimationTrigger.cs b/Assets/Scripts/Core/Graph Tasks/SendAnimationTrigger.cs new file mode 100644 index 0000000..f596be6 --- /dev/null +++ b/Assets/Scripts/Core/Graph Tasks/SendAnimationTrigger.cs @@ -0,0 +1,49 @@ +using System; +using NodeCanvas.Framework; +using ParadoxNotion.Design; +using Unity.Netcode; +using Unity.Netcode.Components; +using UnityEngine; + + +namespace Reset.Core { + + [Category("Reset")] + [Description("Sends an animation trigger with network sync to networked objects")] + public class SendAnimationTrigger : ActionTask{ + public BBParameter trigger; + + //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() { + return null; + } + + //This is called once each time the task is enabled. + //Call EndAction() to mark the action as finished, either in success or failure. + //EndAction can be called from anywhere. + protected override void OnExecute(){ + try { + agent.SetTrigger("trigger"); + } catch (Exception e) { + Debug.LogError($"Did not set Network Animator trigger {trigger.name} on {(agent == null ? null : agent.name)}: {e.Message}"); + } + EndAction(true); + } + + //Called once per frame while the action is active. + protected override void OnUpdate() { + + } + + //Called when the task is disabled. + protected override void OnStop() { + + } + + //Called when the task is paused. + protected override void OnPause() { + + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Core/Graph Tasks/SendAnimationTrigger.cs.meta b/Assets/Scripts/Core/Graph Tasks/SendAnimationTrigger.cs.meta new file mode 100644 index 0000000..5570623 --- /dev/null +++ b/Assets/Scripts/Core/Graph Tasks/SendAnimationTrigger.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 02e8360f34e218546b718ebe401dd5b6 \ No newline at end of file diff --git a/Assets/Scripts/Core/Graph Tasks/SendEventToUnit.cs b/Assets/Scripts/Core/Graph Tasks/SendEventToUnit.cs new file mode 100644 index 0000000..b78b770 --- /dev/null +++ b/Assets/Scripts/Core/Graph Tasks/SendEventToUnit.cs @@ -0,0 +1,66 @@ +using System; +using NodeCanvas.Framework; +using ParadoxNotion.Design; +using Unity.Netcode; +using UnityEngine; + + +namespace Reset.Units { + [Category("Reset")] + [Description("Send a string as an event to another unit. Works online as well")] + public class SendEventToUnit : ActionTask{ + public BBParameter target; + public string eventToSend; + + protected override string info{ + get{ + return $"Send event {eventToSend} to {target}"; + } + } + + //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() { + return null; + } + + //This is called once each time the task is enabled. + //Call EndAction() to mark the action as finished, either in success or failure. + //EndAction can be called from anywhere. + protected override void OnExecute() { + EndAction(true); + } + + //Called once per frame while the action is active. + protected override void OnUpdate(){ + try { + if (target.value.GetComponent().UnitIsNetworked()) { + ulong targetID = (target.value.GetComponent()).NetworkObjectId; + + + SendEventRpc(agent.RpcTarget.Single(targetID, RpcTargetUse.Temp)); + } else { + target.value.GetComponent().SendEvent("eventToSend"); + } + } catch (Exception e) { + Debug.LogError($"Failed to send event {eventToSend} to {target}: {e.Message}"); + } + } + + [Rpc(SendTo.SpecifiedInParams)] + void SendEventRpc(RpcParams rpcParams = default){ + target.value.GetComponent().SendEvent("eventToSend"); + Debug.Log(""); + } + + //Called when the task is disabled. + protected override void OnStop() { + + } + + //Called when the task is paused. + protected override void OnPause() { + + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Core/Graph Tasks/SendEventToUnit.cs.meta b/Assets/Scripts/Core/Graph Tasks/SendEventToUnit.cs.meta new file mode 100644 index 0000000..4612e14 --- /dev/null +++ b/Assets/Scripts/Core/Graph Tasks/SendEventToUnit.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: f8c4b6409f7727e4fa7a6cec09d42751 \ No newline at end of file