コード例 #1
0
        public static FloodPath Construct(Vector3 start, OnPathDelegate callback = null)
        {
            FloodPath path = PathPool.GetPath <FloodPath>();

            path.Setup(start, callback);
            return(path);
        }
コード例 #2
0
        // Token: 0x06002741 RID: 10049 RVA: 0x001B035C File Offset: 0x001AE55C
        public static FloodPathTracer Construct(Vector3 start, FloodPath flood, OnPathDelegate callback = null)
        {
            FloodPathTracer path = PathPool.GetPath <FloodPathTracer>();

            path.Setup(start, flood, callback);
            return(path);
        }
コード例 #3
0
ファイル: FloodPath.cs プロジェクト: oliverxu1/InkFighter
        public static FloodPath Construct(Vector3 start, OnPathDelegate callback = null)
        {
            FloodPath p = PathPool <FloodPath> .GetPath();

            p.Setup(start, callback);
            return(p);
        }
コード例 #4
0
        public static FloodPath Construct(Vector3 start, [Optional, DefaultParameterValue(null)] OnPathDelegate callback)
        {
            FloodPath path = PathPool.GetPath <FloodPath>();

            path.Setup(start, callback);
            return(path);
        }
コード例 #5
0
        //Good Game
        //public static FloodPathTracer Construct (Vector3 start, FloodPath flood, OnPathDelegate callback = null) {
        public static FloodPathTracer Construct(VInt3 start, FloodPath flood, OnPathDelegate callback = null)
        {
            var p = PathPool.GetPath <FloodPathTracer>();

            p.Setup(start, flood, callback);
            return(p);
        }
コード例 #6
0
 public FloodPathConstraint(FloodPath path)
 {
     if (path == null)
     {
         Debug.LogWarning("FloodPathConstraint should not be used with a NULL path");
     }
     this.path = path;
 }
コード例 #7
0
ファイル: FloodPathTracer.cs プロジェクト: Anaryu/aetherion
 public FloodPathTracer(Vector3 start, FloodPath flood, OnPathDelegate callbackDelegate)
     : base(start,flood.originalStartPoint,callbackDelegate)
 {
     this.flood = flood;
     if (flood == null || !flood.processed)
         throw new System.ArgumentNullException ("You must supply a calculated FloodPath to the 'flood' argument");
     hasEndPoint = false;
     nnConstraint = new PathIDConstraint ();
 }
コード例 #8
0
ファイル: FloodPathTracer.cs プロジェクト: artbane/aetherion
 public FloodPathTracer(Vector3 start, FloodPath flood, OnPathDelegate callbackDelegate) : base(start, flood.originalStartPoint, callbackDelegate)
 {
     this.flood = flood;
     if (flood == null || !flood.processed)
     {
         throw new System.ArgumentNullException("You must supply a calculated FloodPath to the 'flood' argument");
     }
     hasEndPoint  = false;
     nnConstraint = new PathIDConstraint();
 }
コード例 #9
0
 // Token: 0x06002742 RID: 10050 RVA: 0x001B036C File Offset: 0x001AE56C
 protected void Setup(Vector3 start, FloodPath flood, OnPathDelegate callback)
 {
     this.flood = flood;
     if (flood == null || flood.PipelineState < PathState.Returned)
     {
         throw new ArgumentException("You must supply a calculated FloodPath to the 'flood' argument");
     }
     base.Setup(start, flood.originalStartPoint, callback);
     this.nnConstraint = new FloodPathConstraint(flood);
 }
コード例 #10
0
		protected void Setup (Vector3 start, FloodPath flood, OnPathDelegate callback) {
			this.flood = flood;

			if (flood == null || flood.GetState () < 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);
		}
コード例 #11
0
 protected void Setup(Vector3 start, FloodPath flood, OnPathDelegate callback)
 {
     this.flood = flood;
     if (flood == null || flood.GetState() < PathState.Returned)
     {
         throw new System.ArgumentNullException("You must supply a calculated FloodPath to the 'flood' argument");
     }
     base.Setup(start, flood.originalStartPoint, callback);
     nnConstraint = new FloodPathConstraint(flood);
     hasEndPoint  = false;
 }
コード例 #12
0
        public static FloodPath Construct(GraphNode start, [Optional, DefaultParameterValue(null)] OnPathDelegate callback)
        {
            if (start == null)
            {
                throw new ArgumentNullException("start");
            }
            FloodPath path = PathPool.GetPath <FloodPath>();

            path.Setup(start, callback);
            return(path);
        }
コード例 #13
0
        public static FloodPath Construct(GraphNode start, OnPathDelegate callback = null)
        {
            if (start == null)
            {
                throw new ArgumentNullException("start");
            }
            FloodPath path = PathPool <FloodPath> .GetPath();

            path.Setup(start, callback);
            return(path);
        }
コード例 #14
0
ファイル: PathTypesDemo.cs プロジェクト: sonygod/ESPUnity
    /** Starts a path specified by PathTypesDemo.activeDemo */
    public void DemoPath()
    {
        Path p = null;

        if (activeDemo == 0) {
            p = ABPath.Construct (start.position,end.position, OnPathComplete);
        } else if (activeDemo == 1) {
            MultiTargetPath mp = MultiTargetPath.Construct (multipoints.ToArray (), end.position, null, OnPathComplete);
            p = mp;
        } else if (activeDemo == 2) {
            RandomPath rp = RandomPath.Construct (start.position,searchLength, OnPathComplete);
            rp.spread = spread;
            rp.aimStrength = aimStrength;
            rp.aim = end.position;
            rp.replaceChance = replaceChance;

            p = rp;
        } else if (activeDemo == 3) {
            FleePath fp = FleePath.Construct (start.position, end.position, searchLength, OnPathComplete);
            fp.aimStrength = aimStrength;
            fp.replaceChance = replaceChance;
            fp.spread = spread;

            p = fp;
        } else if (activeDemo == 4) {
            ConstantPath constPath = ConstantPath.Construct (end.position, searchLength, OnPathComplete);

            p = constPath;
        } else if (activeDemo == 5) {
            FloodPath fp = FloodPath.Construct (end.position, null);
            lastFlood = fp;
            p = fp;
        } else if (activeDemo == 6 && lastFlood != null) {
            FloodPathTracer fp = FloodPathTracer.Construct (end.position, lastFlood, OnPathComplete);

            p = fp;
        }

        if (p != null) {
            AstarPath.StartPath (p);
            lastPath = p;
        }
    }
コード例 #15
0
ファイル: PathTypesDemo.cs プロジェクト: GameDiffs/TheForest
 private void DemoPath()
 {
     Path path = null;
     if (this.activeDemo == PathTypesDemo.DemoMode.ABPath)
     {
         path = ABPath.Construct(this.start.position, this.end.position, new OnPathDelegate(this.OnPathComplete));
         if (this.agents != null && this.agents.Length > 0)
         {
             List<Vector3> list = ListPool<Vector3>.Claim(this.agents.Length);
             Vector3 vector = Vector3.zero;
             for (int i = 0; i < this.agents.Length; i++)
             {
                 list.Add(this.agents[i].transform.position);
                 vector += list[i];
             }
             vector /= (float)list.Count;
             for (int j = 0; j < this.agents.Length; j++)
             {
                 List<Vector3> list2;
                 List<Vector3> expr_B8 = list2 = list;
                 int index;
                 int expr_BD = index = j;
                 Vector3 a = list2[index];
                 expr_B8[expr_BD] = a - vector;
             }
             PathUtilities.GetPointsAroundPoint(this.end.position, AstarPath.active.graphs[0] as IRaycastableGraph, list, 0f, 0.2f);
             for (int k = 0; k < this.agents.Length; k++)
             {
                 if (!(this.agents[k] == null))
                 {
                     this.agents[k].target.position = list[k];
                     this.agents[k].UpdatePath();
                 }
             }
         }
     }
     else if (this.activeDemo == PathTypesDemo.DemoMode.MultiTargetPath)
     {
         MultiTargetPath multiTargetPath = MultiTargetPath.Construct(this.multipoints.ToArray(), this.end.position, null, new OnPathDelegate(this.OnPathComplete));
         path = multiTargetPath;
     }
     else if (this.activeDemo == PathTypesDemo.DemoMode.RandomPath)
     {
         RandomPath randomPath = RandomPath.Construct(this.start.position, this.searchLength, new OnPathDelegate(this.OnPathComplete));
         randomPath.spread = this.spread;
         randomPath.aimStrength = this.aimStrength;
         randomPath.aim = this.end.position;
         path = randomPath;
     }
     else if (this.activeDemo == PathTypesDemo.DemoMode.FleePath)
     {
         FleePath fleePath = FleePath.Construct(this.start.position, this.end.position, this.searchLength, new OnPathDelegate(this.OnPathComplete));
         fleePath.aimStrength = this.aimStrength;
         fleePath.spread = this.spread;
         path = fleePath;
     }
     else if (this.activeDemo == PathTypesDemo.DemoMode.ConstantPath)
     {
         base.StartCoroutine(this.CalculateConstantPath());
         path = null;
     }
     else if (this.activeDemo == PathTypesDemo.DemoMode.FloodPath)
     {
         FloodPath floodPath = FloodPath.Construct(this.end.position, null);
         this.lastFlood = floodPath;
         path = floodPath;
     }
     else if (this.activeDemo == PathTypesDemo.DemoMode.FloodPathTracer && this.lastFlood != null)
     {
         FloodPathTracer floodPathTracer = FloodPathTracer.Construct(this.end.position, this.lastFlood, new OnPathDelegate(this.OnPathComplete));
         path = floodPathTracer;
     }
     if (path != null)
     {
         AstarPath.StartPath(path, false);
         this.lastPath = path;
     }
 }
コード例 #16
0
 public FloodPathTracer(Vector3 start, FloodPath flood, OnPathDelegate callbackDelegate)
 {
     throw new Exception("This constructor is obsolete");
 }
コード例 #17
0
        public void RecalculateCosts()
        {
            if (this.pivots == null)
            {
                this.RecalculatePivots();
            }
            if (this.mode == HeuristicOptimizationMode.None)
            {
                return;
            }
            this.pivotCount = 0;
            for (int i = 0; i < this.pivots.Length; i++)
            {
                if (this.pivots[i] != null && (this.pivots[i].Destroyed || !this.pivots[i].Walkable))
                {
                    throw new Exception("Invalid pivot nodes (destroyed or unwalkable)");
                }
            }
            if (this.mode != HeuristicOptimizationMode.RandomSpreadOut)
            {
                for (int j = 0; j < this.pivots.Length; j++)
                {
                    if (this.pivots[j] == null)
                    {
                        throw new Exception("Invalid pivot nodes (null)");
                    }
                }
            }
            Debug.Log("Recalculating costs...");
            this.pivotCount = this.pivots.Length;
            Action <int>   startCostCalculation = null;
            int            numComplete          = 0;
            OnPathDelegate onComplete           = delegate(Path path)
            {
                numComplete++;
                if (numComplete == this.pivotCount)
                {
                    Debug.Log("Grid graph special case!");
                    this.ApplyGridGraphEndpointSpecialCase();
                }
            };

            startCostCalculation = delegate(int pivotIndex)
            {
                GraphNode pivot     = this.pivots[pivotIndex];
                FloodPath floodPath = null;
                floodPath = FloodPath.Construct(pivot, onComplete);
                floodPath.immediateCallback = delegate(Path _p)
                {
                    _p.Claim(this);
                    MeshNode meshNode   = pivot as MeshNode;
                    uint     costOffset = 0u;
                    if (meshNode != null && meshNode.connections != null)
                    {
                        for (int l = 0; l < meshNode.connections.Length; l++)
                        {
                            costOffset = Math.Max(costOffset, meshNode.connections[l].cost);
                        }
                    }
                    NavGraph[] graphs = AstarPath.active.graphs;
                    for (int m = graphs.Length - 1; m >= 0; m--)
                    {
                        graphs[m].GetNodes(delegate(GraphNode node)
                        {
                            int num6 = node.NodeIndex * this.pivotCount + pivotIndex;
                            this.EnsureCapacity(num6);
                            PathNode pathNode = ((IPathInternals)floodPath).PathHandler.GetPathNode(node);
                            if (costOffset > 0u)
                            {
                                this.costs[num6] = ((pathNode.pathID != floodPath.pathID || pathNode.parent == null) ? 0u : Math.Max(pathNode.parent.G - costOffset, 0u));
                            }
                            else
                            {
                                this.costs[num6] = ((pathNode.pathID != floodPath.pathID) ? 0u : pathNode.G);
                            }
                        });
                    }
                    if (this.mode == HeuristicOptimizationMode.RandomSpreadOut && pivotIndex < this.pivots.Length - 1)
                    {
                        if (this.pivots[pivotIndex + 1] == null)
                        {
                            int  num  = -1;
                            uint num2 = 0u;
                            int  num3 = this.maxNodeIndex / this.pivotCount;
                            for (int n = 1; n < num3; n++)
                            {
                                uint num4 = 1073741824u;
                                for (int num5 = 0; num5 <= pivotIndex; num5++)
                                {
                                    num4 = Math.Min(num4, this.costs[n * this.pivotCount + num5]);
                                }
                                GraphNode node2 = ((IPathInternals)floodPath).PathHandler.GetPathNode(n).node;
                                if ((num4 > num2 || num == -1) && node2 != null && !node2.Destroyed && node2.Walkable)
                                {
                                    num  = n;
                                    num2 = num4;
                                }
                            }
                            if (num == -1)
                            {
                                Debug.LogError("Failed generating random pivot points for heuristic optimizations");
                                return;
                            }
                            this.pivots[pivotIndex + 1] = ((IPathInternals)floodPath).PathHandler.GetPathNode(num).node;
                        }
                        startCostCalculation(pivotIndex + 1);
                    }
                    _p.Release(this, false);
                };
                AstarPath.StartPath(floodPath, true);
            };
            if (this.mode != HeuristicOptimizationMode.RandomSpreadOut)
            {
                for (int k = 0; k < this.pivots.Length; k++)
                {
                    startCostCalculation(k);
                }
            }
            else
            {
                startCostCalculation(0);
            }
            this.dirty = false;
        }
コード例 #18
0
 public static FloodPathTracer Construct(Vector3 start, FloodPath flood, OnPathDelegate callback = null)
 {
     FloodPathTracer path = PathPool<FloodPathTracer>.GetPath();
     path.Setup(start, flood, callback);
     return path;
 }
コード例 #19
0
        public void RecalculateCosts()
        {
            if (pivots == null)
            {
                RecalculatePivots();
            }
            if (mode == HeuristicOptimizationMode.None)
            {
                return;
            }

            pivotCount = 0;

            for (int i = 0; i < pivots.Length; i++)
            {
                if (pivots[i] != null && (pivots[i].Destroyed || !pivots[i].Walkable))
                {
                    throw new System.Exception("Invalid pivot nodes (destroyed or unwalkable)");
                }
            }

            if (mode != HeuristicOptimizationMode.RandomSpreadOut)
            {
                for (int i = 0; i < pivots.Length; i++)
                {
                    if (pivots[i] == null)
                    {
                        throw new System.Exception("Invalid pivot nodes (null)");
                    }
                }
            }

            Debug.Log("Recalculating costs...");
            pivotCount = pivots.Length;

            System.Action <int> startCostCalculation = null;

            startCostCalculation = delegate(int k) {
                GraphNode pivot = pivots[k];

                FloodPath fp = null;
                fp = FloodPath.Construct(pivot);
                fp.immediateCallback = delegate(Path _p) {
                    // Handle path pooling
                    _p.Claim(this);

                    // When paths are calculated on navmesh based graphs
                    // the costs are slightly modified to match the actual target and start points
                    // instead of the node centers
                    // so we have to remove the cost for the first and last connection
                    // in each path
                    var  mn         = pivot as MeshNode;
                    uint costOffset = 0;
                    if (mn != null && mn.connectionCosts != null)
                    {
                        for (int i = 0; i < mn.connectionCosts.Length; i++)
                        {
                            costOffset = System.Math.Max(costOffset, mn.connectionCosts[i]);
                        }
                    }


                    var graphs = AstarPath.active.graphs;
                    // Process graphs in reverse order to raise probability that we encounter large NodeIndex values quicker
                    // to avoid resizing the internal array too often
                    for (int j = graphs.Length - 1; j >= 0; j--)
                    {
                        graphs[j].GetNodes(delegate(GraphNode node) {
                            int idx = node.NodeIndex * pivotCount + k;
                            EnsureCapacity(idx);
                            PathNode pn = fp.pathHandler.GetPathNode(node);
                            if (costOffset > 0)
                            {
                                costs[idx] = pn.pathID == fp.pathID && pn.parent != null ? System.Math.Max(pn.parent.G - costOffset, 0) : 0;
                            }
                            else
                            {
                                costs[idx] = pn.pathID == fp.pathID ? pn.G : 0;
                            }
                            return(true);
                        });
                    }

                    if (mode == HeuristicOptimizationMode.RandomSpreadOut && k < pivots.Length - 1)
                    {
                        int  best      = -1;
                        uint bestScore = 0;

                        // Actual number of nodes
                        int totCount = maxNodeIndex / pivotCount;

                        // Loop through all nodes
                        for (int j = 1; j < totCount; j++)
                        {
                            // Find the minimum distance from the node to all existing pivot points
                            uint mx = 1 << 30;
                            for (int p = 0; p <= k; p++)
                            {
                                mx = System.Math.Min(mx, costs[j * pivotCount + p]);
                            }

                            // Pick the node which has the largest minimum distance to the existing pivot points
                            // (i.e pick the one furthest away from the existing ones)
                            GraphNode node = fp.pathHandler.GetPathNode(j).node;
                            if ((mx > bestScore || best == -1) && node != null && !node.Destroyed && node.Walkable)
                            {
                                best      = j;
                                bestScore = mx;
                            }
                        }

                        if (best == -1)
                        {
                            Debug.LogError("Failed generating random pivot points for heuristic optimizations");
                            return;
                        }

                        pivots[k + 1] = fp.pathHandler.GetPathNode(best).node;

                        Debug.Log("Found node at " + pivots[k + 1].position + " with score " + bestScore);

                        startCostCalculation(k + 1);
                    }

                    // Handle path pooling
                    _p.Release(this);
                };

                AstarPath.StartPath(fp, true);
            };

            if (mode != HeuristicOptimizationMode.RandomSpreadOut)
            {
                // All calculated in paralell
                for (int i = 0; i < pivots.Length; i++)
                {
                    startCostCalculation(i);
                }
            }
            else
            {
                // Recursive and serial
                startCostCalculation(0);
            }


            dirty = false;
        }
コード例 #20
0
 public override void Reset()
 {
     base.Reset();
     flood = null;
 }
コード例 #21
0
		public static FloodPathTracer Construct (Vector3 start, FloodPath flood, OnPathDelegate callback = null) {
			var p = PathPool.GetPath<FloodPathTracer>();

			p.Setup(start, flood, callback);
			return p;
		}
コード例 #22
0
 protected override void Reset()
 {
     base.Reset();
     flood = null;
 }
コード例 #23
0
		public FloodPathConstraint (FloodPath path) {
			if (path == null) { Debug.LogWarning ("FloodPathConstraint should not be used with a NULL path"); }
			this.path = path;
		}
        public void RecalculateCosts()
        {
#if !AstarFree && !ASTAR_NO_EUCLIDEAN_EMBEDDING
            if (pivots == null)
            {
                RecalculatePivots();
            }
            if (mode == HeuristicOptimizationMode.None)
            {
                return;
            }

            pivotCount = 0;

            for (int i = 0; i < pivots.Length; i++)
            {
                if (pivots[i] != null && (pivots[i].Destroyed || !pivots[i].Walkable))
                {
                    throw new System.Exception("Invalid pivot nodes (destroyed or unwalkable)");
                }
            }

            if (mode != HeuristicOptimizationMode.RandomSpreadOut)
            {
                for (int i = 0; i < pivots.Length; i++)
                {
                    if (pivots[i] == null)
                    {
                        throw new System.Exception("Invalid pivot nodes (null)");
                    }
                }
            }

            Debug.Log("Recalculating costs...");
            pivotCount = pivots.Length;

            System.Action <int> startCostCalculation = null;

            int            numComplete = 0;
            OnPathDelegate onComplete  = (Path path) => {
                numComplete++;
                if (numComplete == pivotCount)
                {
                    // Last completed path
                    ApplyGridGraphEndpointSpecialCase();
                }
            };

            startCostCalculation = (int pivotIndex) => {
                GraphNode pivot = pivots[pivotIndex];

                FloodPath floodPath = null;
                floodPath = FloodPath.Construct(pivot, onComplete);
                floodPath.immediateCallback = (Path _p) => {
                    // Handle path pooling
                    _p.Claim(this);

                    // When paths are calculated on navmesh based graphs
                    // the costs are slightly modified to match the actual target and start points
                    // instead of the node centers
                    // so we have to remove the cost for the first and last connection
                    // in each path
                    var  meshNode   = pivot as MeshNode;
                    uint costOffset = 0;
                    if (meshNode != null && meshNode.connections != null)
                    {
                        for (int i = 0; i < meshNode.connections.Length; i++)
                        {
                            costOffset = System.Math.Max(costOffset, meshNode.connections[i].cost);
                        }
                    }


                    var graphs = AstarPath.active.graphs;
                    // Process graphs in reverse order to raise probability that we encounter large NodeIndex values quicker
                    // to avoid resizing the internal array too often
                    for (int j = graphs.Length - 1; j >= 0; j--)
                    {
                        graphs[j].GetNodes(node => {
                            int idx = node.NodeIndex * pivotCount + pivotIndex;
                            EnsureCapacity(idx);
                            PathNode pn = ((IPathInternals)floodPath).PathHandler.GetPathNode(node);
                            if (costOffset > 0)
                            {
                                costs[idx] = pn.pathID == floodPath.pathID && pn.parent != null ? System.Math.Max(pn.parent.G - costOffset, 0) : 0;
                            }
                            else
                            {
                                costs[idx] = pn.pathID == floodPath.pathID ? pn.G : 0;
                            }
                        });
                    }

                    if (mode == HeuristicOptimizationMode.RandomSpreadOut && pivotIndex < pivots.Length - 1)
                    {
                        // If the next pivot is null
                        // then find the node which is furthest away from the earlier
                        // pivot points
                        if (pivots[pivotIndex + 1] == null)
                        {
                            int  best      = -1;
                            uint bestScore = 0;

                            // Actual number of nodes
                            int totCount = maxNodeIndex / pivotCount;

                            // Loop through all nodes
                            for (int j = 1; j < totCount; j++)
                            {
                                // Find the minimum distance from the node to all existing pivot points
                                uint mx = 1 << 30;
                                for (int p = 0; p <= pivotIndex; p++)
                                {
                                    mx = System.Math.Min(mx, costs[j * pivotCount + p]);
                                }

                                // Pick the node which has the largest minimum distance to the existing pivot points
                                // (i.e pick the one furthest away from the existing ones)
                                GraphNode node = ((IPathInternals)floodPath).PathHandler.GetPathNode(j).node;
                                if ((mx > bestScore || best == -1) && node != null && !node.Destroyed && node.Walkable)
                                {
                                    best      = j;
                                    bestScore = mx;
                                }
                            }

                            if (best == -1)
                            {
                                Debug.LogError("Failed generating random pivot points for heuristic optimizations");
                                return;
                            }

                            pivots[pivotIndex + 1] = ((IPathInternals)floodPath).PathHandler.GetPathNode(best).node;
                        }

                        // Start next path
                        startCostCalculation(pivotIndex + 1);
                    }

                    // Handle path pooling
                    _p.Release(this);
                };

                AstarPath.StartPath(floodPath, true);
            };

            if (mode != HeuristicOptimizationMode.RandomSpreadOut)
            {
                // All calculated in parallel
                for (int i = 0; i < pivots.Length; i++)
                {
                    startCostCalculation(i);
                }
            }
            else
            {
                // Recursive and serial
                startCostCalculation(0);
            }
#endif
            dirty = false;
        }
コード例 #25
0
        public void RecalculateCosts()
        {
            if (this.pivots == null)
            {
                this.RecalculatePivots();
            }
            if (this.mode == HeuristicOptimizationMode.None)
            {
                return;
            }
            this.pivotCount = 0;
            for (int i = 0; i < this.pivots.Length; i++)
            {
                if (this.pivots[i] != null && (this.pivots[i].Destroyed || !this.pivots[i].Walkable))
                {
                    throw new Exception("Invalid pivot nodes (destroyed or unwalkable)");
                }
            }
            if (this.mode != HeuristicOptimizationMode.RandomSpreadOut)
            {
                for (int j = 0; j < this.pivots.Length; j++)
                {
                    if (this.pivots[j] == null)
                    {
                        throw new Exception("Invalid pivot nodes (null)");
                    }
                }
            }
            Debug.Log("Recalculating costs...");
            this.pivotCount = this.pivots.Length;
            Action <int> startCostCalculation = null;

            startCostCalculation = delegate(int k)
            {
                GraphNode pivot = this.pivots[k];
                FloodPath fp    = null;
                fp = FloodPath.Construct(pivot, null);
                fp.immediateCallback = delegate(Path _p)
                {
                    _p.Claim(this);
                    MeshNode meshNode   = pivot as MeshNode;
                    uint     costOffset = 0u;
                    int      k;
                    if (meshNode != null && meshNode.connectionCosts != null)
                    {
                        for (k = 0; k < meshNode.connectionCosts.Length; k++)
                        {
                            costOffset = Math.Max(costOffset, meshNode.connectionCosts[k]);
                        }
                    }
                    NavGraph[] graphs = AstarPath.active.graphs;
                    for (int m = graphs.Length - 1; m >= 0; m--)
                    {
                        graphs[m].GetNodes(delegate(GraphNode node)
                        {
                            int num6 = node.NodeIndex * this.pivotCount + k;
                            this.EnsureCapacity(num6);
                            PathNode pathNode = fp.pathHandler.GetPathNode(node);
                            if (costOffset > 0u)
                            {
                                this.costs[num6] = ((pathNode.pathID != fp.pathID || pathNode.parent == null) ? 0u : Math.Max(pathNode.parent.G - costOffset, 0u));
                            }
                            else
                            {
                                this.costs[num6] = ((pathNode.pathID != fp.pathID) ? 0u : pathNode.G);
                            }
                            return(true);
                        });
                    }
                    if (this.mode == HeuristicOptimizationMode.RandomSpreadOut && k < this.pivots.Length - 1)
                    {
                        int  num  = -1;
                        uint num2 = 0u;
                        int  num3 = this.maxNodeIndex / this.pivotCount;
                        for (int n = 1; n < num3; n++)
                        {
                            uint num4 = 1073741824u;
                            for (int num5 = 0; num5 <= k; num5++)
                            {
                                num4 = Math.Min(num4, this.costs[n * this.pivotCount + num5]);
                            }
                            GraphNode node2 = fp.pathHandler.GetPathNode(n).node;
                            if ((num4 > num2 || num == -1) && node2 != null && !node2.Destroyed && node2.Walkable)
                            {
                                num  = n;
                                num2 = num4;
                            }
                        }
                        if (num == -1)
                        {
                            Debug.LogError("Failed generating random pivot points for heuristic optimizations");
                            return;
                        }
                        this.pivots[k + 1] = fp.pathHandler.GetPathNode(num).node;
                        Debug.Log(string.Concat(new object[]
                        {
                            "Found node at ",
                            this.pivots[k + 1].position,
                            " with score ",
                            num2
                        }));
                        startCostCalculation(k + 1);
                    }
                    _p.Release(this);
                };
                AstarPath.StartPath(fp, true);
            };
            if (this.mode != HeuristicOptimizationMode.RandomSpreadOut)
            {
                for (int l = 0; l < this.pivots.Length; l++)
                {
                    startCostCalculation(l);
                }
            }
            else
            {
                startCostCalculation(0);
            }
            this.dirty = false;
        }
コード例 #26
0
		public FloodPathTracer (Vector3 start, FloodPath flood, OnPathDelegate callbackDelegate) {
			throw new System.Exception ("This constructor is obsolete");
		}
コード例 #27
0
 public override void Reset()
 {
     base.Reset();
     this.flood = null;
 }
コード例 #28
0
ファイル: PathTypesDemo.cs プロジェクト: Gapti/ClashOfClanRIP
	/** Starts a path specified by PathTypesDemo.activeDemo */
	public void DemoPath () {
		
		Path p = null;
		
		if (activeDemo == 0) {
			p = ABPath.Construct (start.position,end.position, OnPathComplete);
			
			if (agents != null && agents.Length > 0) {
				List<Vector3> pts = Pathfinding.Util.ListPool<Vector3>.Claim(agents.Length);
				Vector3 avg = Vector3.zero;
				for (int i=0;i<agents.Length;i++) {
					pts.Add (agents[i].transform.position);
					avg += pts[i];
				}
				avg /= pts.Count;
				for (int i=0;i<agents.Length;i++) pts[i] -= avg;
				//List<Vector3> pts = Pathfinding.PathUtilities.GetSpiralPoints (agents.Length, 0.2f);
				
				Pathfinding.PathUtilities.GetPointsAroundPoint (end.position, AstarPath.active.graphs[0] as IRaycastableGraph, pts, 0, 0.2f);
				//for (int i=0;i<pts.Count;i++) pts[i] += end.position;
				for (int i=0;i<agents.Length;i++) {
					if (agents[i] == null) continue;
					
					agents[i].target.position = pts[i];
					agents[i].UpdatePath();
				}
			}
		} else if (activeDemo == 1) {
			MultiTargetPath mp = MultiTargetPath.Construct (multipoints.ToArray (), end.position, null, OnPathComplete);
			p = mp;
		} else if (activeDemo == 2) {
			RandomPath rp = RandomPath.Construct (start.position,searchLength, OnPathComplete);
			rp.spread = spread;
			rp.aimStrength = aimStrength;
			rp.aim = end.position;
			
			p = rp;
		} else if (activeDemo == 3) {
			FleePath fp = FleePath.Construct (start.position, end.position, searchLength, OnPathComplete);
			fp.aimStrength = aimStrength;
			fp.spread = spread;
			
			p = fp;
		} else if (activeDemo == 4) {
			StartCoroutine(Constant());
			p = null;
		} else if (activeDemo == 5) {
			FloodPath fp = FloodPath.Construct (end.position, null);
			lastFlood = fp;
			p = fp;
		} else if (activeDemo == 6 && lastFlood != null) {
			FloodPathTracer fp = FloodPathTracer.Construct (end.position, lastFlood, OnPathComplete);
			
			
			p = fp;
		}
		
		if (p != null) {
			AstarPath.StartPath (p);
			lastPath = p;
		}
	}