diff --git a/Assets/Scripts/Core/Graph Tasks/ChangeAgentTransform.cs b/Assets/Scripts/Core/Graph Tasks/ChangeAgentTransform.cs new file mode 100644 index 0000000..5ee5fcc --- /dev/null +++ b/Assets/Scripts/Core/Graph Tasks/ChangeAgentTransform.cs @@ -0,0 +1,121 @@ +using System; +using NodeCanvas.Framework; +using ParadoxNotion.Design; +using ParadoxNotion.Serialization.FullSerializer; +using Sirenix.OdinInspector; +using UnityEngine; + +namespace NodeCanvas.Tasks.Actions { + + [Category("Reset")] + [Description("Update the agent's position and rotation (scale too, sure whynot) either instantly or over time.")] + public class ChangeAgentTransform : ActionTask{ + public enum TransformProperty{ + Position, + Rotation, + Scale + } + + protected override string info { + get{ + string basicText = string.Format($"Player {targetProperty.ToString()} to {(targetValue.isPresumedDynamic ? targetValue.name : targetValue.value)}"); + basicText += relativeToSelf.value ? ", relative to Self" : ""; + + return basicText; + } + } + + public TransformProperty targetProperty; + + [ParadoxNotion.Design.ShowIf("targetProperty", 0), Space(5)] + public BBParameter forcePositionChange; + + public BBParameter targetValue; + + public BBParameter relativeToSelf; + + [Tooltip("Set this to the current position if you're trying to rotate by 'this much'. Keep it zero for world space values.")] + public BBParameter relativeValue; + + public BBParameter changeInstantly; + public BBParameter smoothing; + + private Vector3 currentVel; + + + //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() { + switch (targetProperty) { + case TransformProperty.Position: + Vector3 relativeUseValue = relativeValue.value; + if (relativeToSelf.value) { + relativeUseValue = agent.transform.position; + } + + if (changeInstantly.value) { + agent.Move(agent.transform.position.DirectionTo(relativeUseValue + targetValue.value)); + } + + break; + case TransformProperty.Rotation: + // agent.transform = Quaternion.Euler(relativeValue.value + targetValue.value); + break; + case TransformProperty.Scale: + break; + default: + throw new ArgumentOutOfRangeException(); + } + + if (changeInstantly.value) { + EndAction(true); + } + } + + //Called once per frame while the action is active. + protected override void OnUpdate() { + switch (targetProperty) { + case TransformProperty.Position: + Vector3 relativeUseValue = relativeValue.value; + if (relativeToSelf.value) { + relativeUseValue = agent.transform.position; + } + + if (!changeInstantly.value) { + Vector3 targetPosition = relativeUseValue + targetValue.value; + // agent.transform.position = Vector3.SmoothDamp(agent.transform.position, targetPosition, + // ref currentVel, smoothing.value * Time.deltaTime); + + agent.Move((agent.transform.position.DirectionTo(targetPosition)).normalized * .5f * Mathf.Lerp(0, 1, Vector3.Distance(agent.transform.position, targetPosition)) * smoothing.value * Time.deltaTime); + EndAction(); + } + + break; + case TransformProperty.Rotation: + agent.transform.rotation = Quaternion.Euler(relativeValue.value + targetValue.value); + break; + case TransformProperty.Scale: + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + //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/ChangeAgentTransform.cs.meta b/Assets/Scripts/Core/Graph Tasks/ChangeAgentTransform.cs.meta new file mode 100644 index 0000000..5bdbb3d --- /dev/null +++ b/Assets/Scripts/Core/Graph Tasks/ChangeAgentTransform.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: b77e2b9ac9aad644480508d5a86f4006 \ No newline at end of file diff --git a/Assets/Scripts/Core/Graph Tasks/DecomposeRaycastHit.cs b/Assets/Scripts/Core/Graph Tasks/DecomposeRaycastHit.cs new file mode 100644 index 0000000..4f0a6c5 --- /dev/null +++ b/Assets/Scripts/Core/Graph Tasks/DecomposeRaycastHit.cs @@ -0,0 +1,55 @@ +using NodeCanvas.Framework; +using ParadoxNotion.Design; +using UnityEngine; + + +namespace NodeCanvas.Tasks.Actions { + + [Category("Reset")] + [Description("Breaks down an incoming RaycastHit into it's constituent parts for later use.")] + public class DecomposeRaycastHit : ActionTask{ + public BBParameter raycastHit; + + public BBParameter transform; + public BBParameter collider; + public BBParameter gameObject; + public BBParameter distance; + public BBParameter normal; + public BBParameter point; + + //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(){ + if (transform.isDefined){ transform.value = raycastHit.value.transform; } + if (collider.isDefined){ collider.value = raycastHit.value.collider; } + if (gameObject.isDefined){ gameObject.value = raycastHit.value.transform.gameObject; } + if (distance.isDefined){ distance.value = raycastHit.value.distance; } + if (normal.isDefined){ normal.value = raycastHit.value.normal; } + if (point.isDefined){ point.value = raycastHit.value.point; } + + 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/DecomposeRaycastHit.cs.meta b/Assets/Scripts/Core/Graph Tasks/DecomposeRaycastHit.cs.meta new file mode 100644 index 0000000..92889a5 --- /dev/null +++ b/Assets/Scripts/Core/Graph Tasks/DecomposeRaycastHit.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 79f7cbb75d876f84b8edfae676ba324c \ No newline at end of file