123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using UnityEngine;
- namespace Pathfinding {
-
-
-
-
-
-
-
- public class FloodPathConstraint : NNConstraint {
- readonly FloodPath path;
- public FloodPathConstraint (FloodPath path) {
- if (path == null) { Debug.LogWarning("FloodPathConstraint should not be used with a NULL path"); }
- this.path = path;
- }
- public override bool Suitable (GraphNode node) {
- return base.Suitable(node) && path.HasPathTo(node);
- }
- }
-
-
-
-
-
-
-
- public class FloodPathTracer : ABPath {
-
- protected FloodPath flood;
- protected override bool hasEndPoint {
- get {
- return false;
- }
- }
-
-
-
-
- public FloodPathTracer () {}
- public static FloodPathTracer Construct (Vector3 start, FloodPath flood, OnPathDelegate callback = null) {
- var p = PathPool.GetPath<FloodPathTracer>();
- p.Setup(start, flood, callback);
- return p;
- }
- protected void Setup (Vector3 start, FloodPath flood, OnPathDelegate callback) {
- this.flood = flood;
- if (flood == null || flood.PipelineState < PathState.Returned) {
- throw new System.ArgumentException("You must supply a calculated FloodPath to the 'flood' argument");
- }
- base.Setup(start, flood.originalStartPoint, callback);
- nnConstraint = new FloodPathConstraint(flood);
- }
- protected override void Reset () {
- base.Reset();
- flood = null;
- }
-
-
-
-
- protected override void Initialize () {
- if (startNode != null && flood.HasPathTo(startNode)) {
- Trace(startNode);
- CompleteState = PathCompleteState.Complete;
- } else {
- FailWithError("Could not find valid start node");
- }
- }
- protected override void CalculateStep (long targetTick) {
- if (CompleteState != PathCompleteState.Complete) throw new System.Exception("Something went wrong. At this point the path should be completed");
- }
-
-
-
-
-
- public void Trace (GraphNode from) {
- GraphNode c = from;
- int count = 0;
- while (c != null) {
- path.Add(c);
- vectorPath.Add((Vector3)c.position);
- c = flood.GetParent(c);
- count++;
- if (count > 1024) {
- Debug.LogWarning("Inifinity loop? >1024 node path. Remove this message if you really have that long paths (FloodPathTracer.cs, Trace function)");
- break;
- }
- }
- }
- }
- }
|