first commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
using UnityEngine;
|
||||
|
||||
using NavMesh = UnityEngine.AI.NavMesh;
|
||||
using NavMeshHit = UnityEngine.AI.NavMeshHit;
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Name("Find Closest NavMesh Edge")]
|
||||
[Category("Movement/Pathfinding")]
|
||||
[Description("Find the closes Navigation Mesh position to the target position")]
|
||||
public class FindClosestEdge : ActionTask
|
||||
{
|
||||
|
||||
public BBParameter<Vector3> targetPosition;
|
||||
[BlackboardOnly]
|
||||
public BBParameter<Vector3> saveFoundPosition;
|
||||
|
||||
private NavMeshHit hit;
|
||||
|
||||
protected override void OnExecute() {
|
||||
if ( NavMesh.FindClosestEdge(targetPosition.value, out hit, -1) ) {
|
||||
saveFoundPosition.value = hit.position;
|
||||
EndAction(true);
|
||||
return;
|
||||
}
|
||||
|
||||
EndAction(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c5db9efb29d06114ab702c7c8095184d
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/Movement/Pathfinding/FindClosestEdge.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,58 @@
|
||||
using UnityEngine;
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
using NavMeshAgent = UnityEngine.AI.NavMeshAgent;
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Category("Movement/Pathfinding")]
|
||||
[Description("Flees away from the target")]
|
||||
public class Flee : ActionTask<NavMeshAgent>
|
||||
{
|
||||
|
||||
[RequiredField, Tooltip("The target to flee from.")]
|
||||
public BBParameter<GameObject> target;
|
||||
[Tooltip("The speed to flee.")]
|
||||
public BBParameter<float> speed = 4f;
|
||||
[Tooltip("The distance to flee at.")]
|
||||
public BBParameter<float> fledDistance = 10f;
|
||||
[Tooltip("A distance to look away from the target for valid flee destination.")]
|
||||
public BBParameter<float> lookAhead = 2f;
|
||||
|
||||
protected override string info {
|
||||
get { return string.Format("Flee from {0}", target); }
|
||||
}
|
||||
|
||||
protected override void OnExecute() {
|
||||
if ( target.value == null ) { EndAction(false); return; }
|
||||
agent.speed = speed.value;
|
||||
if ( ( agent.transform.position - target.value.transform.position ).magnitude >= fledDistance.value ) {
|
||||
EndAction(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnUpdate() {
|
||||
if ( target.value == null ) { EndAction(false); return; }
|
||||
var targetPos = target.value.transform.position;
|
||||
if ( ( agent.transform.position - targetPos ).magnitude >= fledDistance.value ) {
|
||||
EndAction(true);
|
||||
return;
|
||||
}
|
||||
|
||||
var fleePos = targetPos + ( agent.transform.position - targetPos ).normalized * ( fledDistance.value + lookAhead.value + agent.stoppingDistance );
|
||||
if ( !agent.SetDestination(fleePos) ) {
|
||||
EndAction(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void OnPause() { OnStop(); }
|
||||
protected override void OnStop() {
|
||||
if ( agent.gameObject.activeSelf ) {
|
||||
agent.ResetPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 004335b421e457b4298f969c177b4497
|
||||
timeCreated: 1427360377
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/Movement/Pathfinding/Flee.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,65 @@
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
using UnityEngine;
|
||||
using NavMeshAgent = UnityEngine.AI.NavMeshAgent;
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Name("Seek (GameObject)")]
|
||||
[Category("Movement/Pathfinding")]
|
||||
public class MoveToGameObject : ActionTask<NavMeshAgent>
|
||||
{
|
||||
|
||||
[RequiredField]
|
||||
public BBParameter<GameObject> target;
|
||||
public BBParameter<float> speed = 4;
|
||||
public BBParameter<float> keepDistance = 0.1f;
|
||||
|
||||
private Vector3? lastRequest;
|
||||
|
||||
protected override string info {
|
||||
get { return "Seek " + target; }
|
||||
}
|
||||
|
||||
protected override void OnExecute() {
|
||||
if ( target.value == null ) { EndAction(false); return; }
|
||||
agent.speed = speed.value;
|
||||
if ( Vector3.Distance(agent.transform.position, target.value.transform.position) <= agent.stoppingDistance + keepDistance.value ) {
|
||||
EndAction(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnUpdate() {
|
||||
if ( target.value == null ) { EndAction(false); return; }
|
||||
var pos = target.value.transform.position;
|
||||
if ( lastRequest != pos ) {
|
||||
if ( !agent.SetDestination(pos) ) {
|
||||
EndAction(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
lastRequest = pos;
|
||||
|
||||
if ( !agent.pathPending && agent.remainingDistance <= agent.stoppingDistance + keepDistance.value ) {
|
||||
EndAction(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPause() { OnStop(); }
|
||||
protected override void OnStop() {
|
||||
if ( agent.gameObject.activeSelf ) {
|
||||
agent.ResetPath();
|
||||
}
|
||||
lastRequest = null;
|
||||
}
|
||||
|
||||
public override void OnDrawGizmosSelected() {
|
||||
if ( target.value != null ) {
|
||||
Gizmos.DrawWireSphere(target.value.transform.position, keepDistance.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a804aa6acf99524b8c50ce5d5e259ed
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/Movement/Pathfinding/MoveToGameObject.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,56 @@
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
using UnityEngine;
|
||||
|
||||
using NavMeshAgent = UnityEngine.AI.NavMeshAgent;
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Name("Seek (Vector3)")]
|
||||
[Category("Movement/Pathfinding")]
|
||||
public class MoveToPosition : ActionTask<NavMeshAgent>
|
||||
{
|
||||
|
||||
public BBParameter<Vector3> targetPosition;
|
||||
public BBParameter<float> speed = 4;
|
||||
public BBParameter<float> keepDistance = 0.1f;
|
||||
|
||||
private Vector3? lastRequest;
|
||||
|
||||
protected override string info {
|
||||
get { return "Seek " + targetPosition; }
|
||||
}
|
||||
|
||||
protected override void OnExecute() {
|
||||
agent.speed = speed.value;
|
||||
if ( Vector3.Distance(agent.transform.position, targetPosition.value) < agent.stoppingDistance + keepDistance.value ) {
|
||||
EndAction(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnUpdate() {
|
||||
if ( lastRequest != targetPosition.value ) {
|
||||
if ( !agent.SetDestination(targetPosition.value) ) {
|
||||
EndAction(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
lastRequest = targetPosition.value;
|
||||
|
||||
if ( !agent.pathPending && agent.remainingDistance <= agent.stoppingDistance + keepDistance.value ) {
|
||||
EndAction(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPause() { OnStop(); }
|
||||
protected override void OnStop() {
|
||||
if ( lastRequest != null && agent.gameObject.activeSelf ) {
|
||||
agent.ResetPath();
|
||||
}
|
||||
lastRequest = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f2b21c100f8a9e45849b27c9515e91c
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/Movement/Pathfinding/MoveToPosition.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,112 @@
|
||||
using System.Collections.Generic;
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
using UnityEngine;
|
||||
|
||||
using NavMeshAgent = UnityEngine.AI.NavMeshAgent;
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Category("Movement/Pathfinding")]
|
||||
[Description("Move Randomly or Progressively between various game object positions taken from the list provided")]
|
||||
public class Patrol : ActionTask<NavMeshAgent>
|
||||
{
|
||||
|
||||
public enum PatrolMode
|
||||
{
|
||||
Progressive,
|
||||
Random
|
||||
}
|
||||
|
||||
[RequiredField, Tooltip("A list of gameobjects patrol points.")]
|
||||
public BBParameter<List<GameObject>> targetList;
|
||||
[Tooltip("The mode to use for patrol (progressive or random)")]
|
||||
public BBParameter<PatrolMode> patrolMode = PatrolMode.Random;
|
||||
public BBParameter<float> speed = 4;
|
||||
public BBParameter<float> keepDistance = 0.1f;
|
||||
|
||||
private int index = -1;
|
||||
private Vector3? lastRequest;
|
||||
|
||||
protected override string info {
|
||||
get { return string.Format("{0} Patrol {1}", patrolMode, targetList); }
|
||||
}
|
||||
|
||||
protected override void OnExecute() {
|
||||
|
||||
if ( targetList.value.Count == 0 ) {
|
||||
EndAction(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( targetList.value.Count == 1 ) {
|
||||
|
||||
index = 0;
|
||||
|
||||
} else {
|
||||
|
||||
if ( patrolMode.value == PatrolMode.Random ) {
|
||||
var newIndex = index;
|
||||
while ( newIndex == index ) {
|
||||
newIndex = Random.Range(0, targetList.value.Count);
|
||||
}
|
||||
index = newIndex;
|
||||
}
|
||||
|
||||
if ( patrolMode.value == PatrolMode.Progressive ) {
|
||||
index = (int)Mathf.Repeat(index + 1, targetList.value.Count);
|
||||
}
|
||||
}
|
||||
|
||||
var targetGo = targetList.value[index];
|
||||
if ( targetGo == null ) {
|
||||
ParadoxNotion.Services.Logger.LogWarning("List game object is null on Patrol Action Task.", LogTag.EXECUTION, this);
|
||||
EndAction(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var targetPos = targetGo.transform.position;
|
||||
|
||||
agent.speed = speed.value;
|
||||
if ( ( agent.transform.position - targetPos ).magnitude < agent.stoppingDistance + keepDistance.value ) {
|
||||
EndAction(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnUpdate() {
|
||||
var targetPos = targetList.value[index].transform.position;
|
||||
if ( lastRequest != targetPos ) {
|
||||
if ( !agent.SetDestination(targetPos) ) {
|
||||
EndAction(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
lastRequest = targetPos;
|
||||
|
||||
if ( !agent.pathPending && agent.remainingDistance <= agent.stoppingDistance + keepDistance.value ) {
|
||||
EndAction(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPause() { OnStop(); }
|
||||
protected override void OnStop() {
|
||||
if ( lastRequest != null && agent.gameObject.activeSelf ) {
|
||||
agent.ResetPath();
|
||||
}
|
||||
lastRequest = null;
|
||||
}
|
||||
|
||||
public override void OnDrawGizmosSelected() {
|
||||
if ( agent && targetList.value != null ) {
|
||||
foreach ( var go in targetList.value ) {
|
||||
if ( go != null ) {
|
||||
Gizmos.DrawSphere(go.transform.position, 0.1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fc1b07b3887fbb4ca09601314fb700f
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/Movement/Pathfinding/Patrol.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,66 @@
|
||||
using UnityEngine;
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
|
||||
using NavMeshAgent = UnityEngine.AI.NavMeshAgent;
|
||||
using NavMesh = UnityEngine.AI.NavMesh;
|
||||
using NavMeshHit = UnityEngine.AI.NavMeshHit;
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Category("Movement/Pathfinding")]
|
||||
[Description("Makes the agent wander randomly within the navigation map")]
|
||||
public class Wander : ActionTask<NavMeshAgent>
|
||||
{
|
||||
|
||||
[Tooltip("The speed to wander with.")]
|
||||
public BBParameter<float> speed = 4;
|
||||
[Tooltip("The distance to keep from each wander point.")]
|
||||
public BBParameter<float> keepDistance = 0.1f;
|
||||
[Tooltip("A wander point can't be closer than this distance")]
|
||||
public BBParameter<float> minWanderDistance = 5;
|
||||
[Tooltip("A wander point can't be further than this distance")]
|
||||
public BBParameter<float> maxWanderDistance = 20;
|
||||
[Tooltip("If enabled, will keep wandering forever. If not, only one wander point will be performed.")]
|
||||
public bool repeat = true;
|
||||
|
||||
protected override void OnExecute() {
|
||||
agent.speed = speed.value;
|
||||
DoWander();
|
||||
}
|
||||
|
||||
protected override void OnUpdate() {
|
||||
if ( !agent.pathPending && agent.remainingDistance <= agent.stoppingDistance + keepDistance.value ) {
|
||||
if ( repeat ) {
|
||||
DoWander();
|
||||
} else {
|
||||
EndAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DoWander() {
|
||||
var min = minWanderDistance.value;
|
||||
var max = maxWanderDistance.value;
|
||||
min = Mathf.Clamp(min, 0.01f, max);
|
||||
max = Mathf.Clamp(max, min, max);
|
||||
var wanderPos = agent.transform.position;
|
||||
while ( ( wanderPos - agent.transform.position ).magnitude < min ) {
|
||||
wanderPos = ( Random.insideUnitSphere * max ) + agent.transform.position;
|
||||
}
|
||||
|
||||
NavMeshHit hit;
|
||||
if ( NavMesh.SamplePosition(wanderPos, out hit, agent.height * 2, NavMesh.AllAreas) ) {
|
||||
agent.SetDestination(hit.position);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPause() { OnStop(); }
|
||||
protected override void OnStop() {
|
||||
if ( agent.gameObject.activeSelf ) {
|
||||
agent.ResetPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7516e8832e25203438fd50fa07cd847c
|
||||
timeCreated: 1426570396
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/Movement/Pathfinding/Wander.cs
|
||||
uploadId: 704937
|
||||
Reference in New Issue
Block a user