本文整理汇总了C#中Pathfinding.Path类的典型用法代码示例。如果您正苦于以下问题:C# Path类的具体用法?C# Path怎么用?C# Path使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Path类属于Pathfinding命名空间,在下文中一共展示了Path类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculatePath
public void CalculatePath()
{
var pos = (target == null) ? targetPosition : (target.transform.position + targetPosition);
p = ABPath.Construct (go.transform.position , pos , OnPathComplete); // create path from current position to closest/first node
AstarPath.StartPath (p); //make the actual vector3 path which we'll use lateron.
pUpdate = 0;
}
示例2: Apply
public override void Apply (Path _p) {
var p = _p as ABPath;
// This modifier only supports ABPaths (doesn't make much sense for other paths anyway)
if (p == null || p.vectorPath.Count == 0) return;
if (p.vectorPath.Count == 1 && !addPoints) {
// Duplicate first point
p.vectorPath.Add(p.vectorPath[0]);
}
// Add instead of replacing points
bool forceAddStartPoint, forceAddEndPoint;
Vector3 pStart = Snap(p, exactStartPoint, true, out forceAddStartPoint);
Vector3 pEnd = Snap(p, exactEndPoint, false, out forceAddEndPoint);
// Add or replace the start point
// Disable adding of points if the mode is SnapToNode since then
// the first item in vectorPath will very likely be the same as the
// position of the first node
if ((forceAddStartPoint || addPoints) && exactStartPoint != Exactness.SnapToNode) {
p.vectorPath.Insert(0, pStart);
} else {
p.vectorPath[0] = pStart;
}
if ((forceAddEndPoint || addPoints) && exactEndPoint != Exactness.SnapToNode) {
p.vectorPath.Add(pEnd);
} else {
p.vectorPath[p.vectorPath.Count-1] = pEnd;
}
}
示例3: ApplyNow
private void ApplyNow(Path somePath)
{
object obj = this.lockObject;
lock (obj)
{
this.waitingForApply = false;
AstarPath.OnPathPreSearch = (OnPathDelegate)Delegate.Remove(AstarPath.OnPathPreSearch, new OnPathDelegate(this.ApplyNow));
this.InversePrevious();
if (!this.destroyed)
{
int seed = this.seedGenerator.Next();
this.rnd = new System.Random(seed);
if (this.toBeApplied != null)
{
int num = this.rnd.Next(this.randomStep);
for (int i = num; i < this.toBeApplied.Length; i += this.rnd.Next(1, this.randomStep))
{
this.toBeApplied[i].Penalty = (uint)((ulong)this.toBeApplied[i].Penalty + (ulong)((long)this.penalty));
}
}
this.prevPenalty = this.penalty;
this.prevSeed = seed;
this.prevNodes = this.toBeApplied;
}
}
}
示例4: ClearOnDestroy
void ClearOnDestroy (Path p) {
lock (lockObject) {
AstarPath.OnPathPreSearch -= ClearOnDestroy;
waitingForApply = false;
InversePrevious();
}
}
示例5: PathEndingCondition
public PathEndingCondition(Path p)
{
if (p == null)
{
throw new ArgumentNullException("p");
}
this.path = p;
}
示例6: OnPathComplete
public void OnPathComplete (Path p) {
// Debug.Log ("Yay, we got a path back. Did it have an error? "+p.error);
if (!p.error) {
path = p;
//Reset the waypoint counter
currentWaypoint = 0;
}
}
示例7: Initialize
/** Initializes the NodeRunData for calculation of the specified path.
* Called by core pathfinding functions just before starting to calculate a path.
*/
public void Initialize (Path p) {
path = p;
pathID = p.pathID;
//Resets the binary heap, don't clear everything because that takes an awful lot of time, instead we can just change the numberOfItems in it (which is just an int)
//Binary heaps are just like a standard array but are always sorted so the node with the lowest F value can be retrieved faster
open.Clear ();
}
示例8: CompletePath
void CompletePath(Pathfinding.Path p)
{
if (!p.error) {
path = p;
currentWayPoint = 1;
if (p.vectorPath.Count == 1) currentWayPoint = 0;
if (!animator.GetBool("Running")) animator.SetBool("Run",true);
}
}
示例9: InSearchTree
public static bool InSearchTree(GraphNode node, Path path)
{
if (path == null || path.pathHandler == null)
{
return true;
}
PathNode pathNode = path.pathHandler.GetPathNode(node);
return pathNode.pathID == path.pathID;
}
示例10: OnPathComplete
//当寻路结束后调用这个函数
public void OnPathComplete(Path p)
{
Debug.Log("FindThePath" + p.error);
//如果找到了一条路径,保存下来,并且把第一个路点设置为当前路点
if (!p.error)
{
path = p;
currentWaypoint = 0;
}
}
示例11: GetTotalDistanceOfPath
private float GetTotalDistanceOfPath(Path path)
{
var totalDistance = 0.0f;
for (var i = 1; i < path.vectorPath.Count; i++)
{
var previousPosition = path.vectorPath[i - 1];
var nextPosition = path.vectorPath[i];
totalDistance = Vector3.Distance(previousPosition, nextPosition);
}
return totalDistance;
}
示例12: PathFinishedDelegate
private void PathFinishedDelegate(Path path)
{
if (path.error)
{
Error = path.errorLog;
PathFailed();
return;
}
GeneratedPath = (ConstantPath) path;
PathGenerated();
}
示例13: Apply
public override void Apply (Path p) {
if (this == null) return;
lock (lockObject) {
toBeApplied = p.path.ToArray();
if (!waitingForApply) {
waitingForApply = true;
AstarPath.OnPathPreSearch += ApplyNow;
}
}
}
示例14: ChooseWaypoint
void ChooseWaypoint()
{
if (waypoints.Length <= 2) {
return;
}
destinationWaypoint = waypoints [UnityEngine.Random.Range (0, waypoints.Length - 1)];
path = null;
currentDirection = Vector3.zero;
currentWaypointIndex = 0;
seeker.StartPath (transform.position, destinationWaypoint.position, OnPathComplete);
}
示例15: Apply
public override void Apply (Path p) {
List<GraphNode> path = p.path;
List<Vector3> vectorPath = p.vectorPath;
if (path == null || path.Count == 0 || vectorPath == null || vectorPath.Count != path.Count) {
return;
}
List<Vector3> funnelPath = ListPool<Vector3>.Claim();
// Claim temporary lists and try to find lists with a high capacity
List<Vector3> left = ListPool<Vector3>.Claim(path.Count+1);
List<Vector3> right = ListPool<Vector3>.Claim(path.Count+1);
AstarProfiler.StartProfile("Construct Funnel");
// Add start point
left.Add(vectorPath[0]);
right.Add(vectorPath[0]);
// Loop through all nodes in the path (except the last one)
for (int i = 0; i < path.Count-1; i++) {
// Get the portal between path[i] and path[i+1] and add it to the left and right lists
bool portalWasAdded = path[i].GetPortal(path[i+1], left, right, false);
if (!portalWasAdded) {
// Fallback, just use the positions of the nodes
left.Add((Vector3)path[i].position);
right.Add((Vector3)path[i].position);
left.Add((Vector3)path[i+1].position);
right.Add((Vector3)path[i+1].position);
}
}
// Add end point
left.Add(vectorPath[vectorPath.Count-1]);
right.Add(vectorPath[vectorPath.Count-1]);
if (!RunFunnel(left, right, funnelPath)) {
// If funnel algorithm failed, degrade to simple line
funnelPath.Add(vectorPath[0]);
funnelPath.Add(vectorPath[vectorPath.Count-1]);
}
// Release lists back to the pool
ListPool<Vector3>.Release(p.vectorPath);
p.vectorPath = funnelPath;
ListPool<Vector3>.Release(left);
ListPool<Vector3>.Release(right);
}