-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5,906 changed files
with
1,011,136 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"version": "1.0", | ||
"components": [ | ||
"Microsoft.VisualStudio.Workload.ManagedGame" | ||
] | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
Assets/AstarPathfindingProject/AstarPathfindingProject.asmdef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "AstarPathfindingProject", | ||
"references": [], | ||
"optionalUnityReferences": [], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false | ||
} |
39 changes: 39 additions & 0 deletions
39
Assets/AstarPathfindingProject/Behaviors/AIDestinationSetter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
namespace Pathfinding { | ||
/// <summary> | ||
/// Sets the destination of an AI to the position of a specified object. | ||
/// This component should be attached to a GameObject together with a movement script such as AIPath, RichAI or AILerp. | ||
/// This component will then make the AI move towards the <see cref="target"/> set on this component. | ||
/// | ||
/// See: <see cref="Pathfinding.IAstarAI.destination"/> | ||
/// | ||
/// [Open online documentation to see images] | ||
/// </summary> | ||
[UniqueComponent(tag = "ai.destination")] | ||
[HelpURL("http://arongranberg.com/astar/docs/class_pathfinding_1_1_a_i_destination_setter.php")] | ||
public class AIDestinationSetter : VersionedMonoBehaviour { | ||
/// <summary>The object that the AI should move to</summary> | ||
public Transform target; | ||
IAstarAI ai; | ||
|
||
void OnEnable () { | ||
ai = GetComponent<IAstarAI>(); | ||
// Update the destination right before searching for a path as well. | ||
// This is enough in theory, but this script will also update the destination every | ||
// frame as the destination is used for debugging and may be used for other things by other | ||
// scripts as well. So it makes sense that it is up to date every frame. | ||
if (ai != null) ai.onSearchPath += Update; | ||
} | ||
|
||
void OnDisable () { | ||
if (ai != null) ai.onSearchPath -= Update; | ||
} | ||
|
||
/// <summary>Updates the AI's destination every frame</summary> | ||
void Update () { | ||
if (target != null && ai != null) ai.destination = target.position; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
namespace Pathfinding { | ||
/// <summary> | ||
/// Simple patrol behavior. | ||
/// This will set the destination on the agent so that it moves through the sequence of objects in the <see cref="targets"/> array. | ||
/// Upon reaching a target it will wait for <see cref="delay"/> seconds. | ||
/// | ||
/// See: <see cref="Pathfinding.AIDestinationSetter"/> | ||
/// See: <see cref="Pathfinding.AIPath"/> | ||
/// See: <see cref="Pathfinding.RichAI"/> | ||
/// See: <see cref="Pathfinding.AILerp"/> | ||
/// </summary> | ||
[UniqueComponent(tag = "ai.destination")] | ||
[HelpURL("http://arongranberg.com/astar/docs/class_pathfinding_1_1_patrol.php")] | ||
public class Patrol : VersionedMonoBehaviour { | ||
/// <summary>Target points to move to in order</summary> | ||
public Transform[] targets; | ||
|
||
/// <summary>Time in seconds to wait at each target</summary> | ||
public float delay = 0; | ||
|
||
/// <summary>Current target index</summary> | ||
int index; | ||
|
||
IAstarAI agent; | ||
float switchTime = float.PositiveInfinity; | ||
|
||
protected override void Awake () { | ||
base.Awake(); | ||
agent = GetComponent<IAstarAI>(); | ||
} | ||
|
||
/// <summary>Update is called once per frame</summary> | ||
void Update () { | ||
if (targets.Length == 0) return; | ||
|
||
bool search = false; | ||
|
||
// Note: using reachedEndOfPath and pathPending instead of reachedDestination here because | ||
// if the destination cannot be reached by the agent, we don't want it to get stuck, we just want it to get as close as possible and then move on. | ||
if (agent.reachedEndOfPath && !agent.pathPending && float.IsPositiveInfinity(switchTime)) { | ||
switchTime = Time.time + delay; | ||
} | ||
|
||
if (Time.time >= switchTime) { | ||
index = index + 1; | ||
search = true; | ||
switchTime = float.PositiveInfinity; | ||
} | ||
|
||
index = index % targets.Length; | ||
agent.destination = targets[index].position; | ||
|
||
if (search) agent.SearchPath(); | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.