SetStart() public method

public SetStart ( Node node ) : void
node Node
return void
Exemplo n.º 1
0
        /** Prepares the path. Searches for start and end nodes and does some simple checking if a path is at all possible */
        public virtual void Prepare()
        {
            //@pathStartTime = startTime;

            //maxAngle = NmaxAngle;
            //angleCost = NangleCost;
            //stepByStep = NstepByStep;
            //unitRadius = 0;//BETA, Not used
            nnConstraint.tags = enabledTags;
            NNInfo startNNInfo = AstarPath.active.GetNearest(startPoint, nnConstraint, startHint);

            //Tell the NNConstraint which node was found as the start node if it is a PathNNConstraint and not a normal NNConstraint
            PathNNConstraint pathNNConstraint = nnConstraint as PathNNConstraint;

            if (pathNNConstraint != null)
            {
                pathNNConstraint.SetStart(startNNInfo.node);
            }

            startPoint    = startNNInfo.clampedPosition;
            startIntPoint = (Int3)startPoint;
            startNode     = startNNInfo.node;

            if (hasEndPoint)
            {
                NNInfo endNNInfo = AstarPath.active.GetNearest(endPoint, nnConstraint, endHint);
                endPoint = endNNInfo.clampedPosition;
                hTarget  = (Int3)endPoint;
                endNode  = endNNInfo.node;
            }



            if (startNode == null || (hasEndPoint == true && endNode == null))
            {
                LogError("Couldn't find close nodes to either the start or the end (start = " + (startNode != null) + " end = " + (endNode != null) + ")");
                return;
            }

            if (!startNode.walkable)
            {
                Debug.DrawRay(startPoint, Vector3.up, Color.red);
                Debug.DrawLine(startPoint, (Vector3)startNode.position, Color.red);
                Debug.Break();
                LogError("The node closest to the start point is not walkable");
                return;
            }

            if (hasEndPoint && !endNode.walkable)
            {
                LogError("The node closest to the end point is not walkable");
                return;
            }

            if (hasEndPoint && startNode.area != endNode.area)
            {
                LogError("There is no valid path to the target (start area: " + startNode.area + ", target area: " + endNode.area + ")");
                return;
            }
        }
Exemplo n.º 2
0
        public override void Prepare()
        {
            this.nnConstraint.tags = this.enabledTags;
            NNInfo           nearest          = AstarPath.active.GetNearest(this.startPoint, this.nnConstraint, this.startHint);
            PathNNConstraint pathNNConstraint = this.nnConstraint as PathNNConstraint;

            if (pathNNConstraint != null)
            {
                pathNNConstraint.SetStart(nearest.node);
            }
            this.startPoint    = nearest.position;
            this.startIntPoint = (Int3)this.startPoint;
            this.startNode     = nearest.node;
            if (this.startNode == null)
            {
                base.Error();
                return;
            }
            if (!this.startNode.Walkable)
            {
                base.Error();
                return;
            }
            if (this.hasEndPoint)
            {
                NNInfo nearest2 = AstarPath.active.GetNearest(this.endPoint, this.nnConstraint, this.endHint);
                this.endPoint = nearest2.position;
                this.endNode  = nearest2.node;
                if (this.startNode == null && this.endNode == null)
                {
                    base.Error();
                    return;
                }
                if (this.endNode == null)
                {
                    base.Error();
                    return;
                }
                if (!this.endNode.Walkable)
                {
                    base.Error();
                    return;
                }
                if (this.startNode.Area != this.endNode.Area)
                {
                    base.Error();
                    return;
                }
                if (!this.EndPointGridGraphSpecialCase(nearest2.node))
                {
                    this.hTarget     = (Int3)this.endPoint;
                    this.hTargetNode = this.endNode;
                    base.pathHandler.GetPathNode(this.endNode).flag1 = true;
                }
            }
        }
Exemplo n.º 3
0
        // Token: 0x0600271A RID: 10010 RVA: 0x001AF4E8 File Offset: 0x001AD6E8
        protected override void Prepare()
        {
            this.nnConstraint.tags = this.enabledTags;
            NNInfo           nearest          = AstarPath.active.GetNearest(this.startPoint, this.nnConstraint);
            PathNNConstraint pathNNConstraint = this.nnConstraint as PathNNConstraint;

            if (pathNNConstraint != null)
            {
                pathNNConstraint.SetStart(nearest.node);
            }
            this.startPoint    = nearest.position;
            this.startIntPoint = (Int3)this.startPoint;
            this.startNode     = nearest.node;
            if (this.startNode == null)
            {
                base.FailWithError("Couldn't find a node close to the start point");
                return;
            }
            if (!base.CanTraverse(this.startNode))
            {
                base.FailWithError("The node closest to the start point could not be traversed");
                return;
            }
            if (this.hasEndPoint)
            {
                NNInfo nearest2 = AstarPath.active.GetNearest(this.endPoint, this.nnConstraint);
                this.endPoint = nearest2.position;
                this.endNode  = nearest2.node;
                if (this.endNode == null)
                {
                    base.FailWithError("Couldn't find a node close to the end point");
                    return;
                }
                if (!base.CanTraverse(this.endNode))
                {
                    base.FailWithError("The node closest to the end point could not be traversed");
                    return;
                }
                if (this.startNode.Area != this.endNode.Area)
                {
                    base.FailWithError("There is no valid path to the target");
                    return;
                }
                if (!this.EndPointGridGraphSpecialCase(nearest2.node))
                {
                    this.hTarget     = (Int3)this.endPoint;
                    this.hTargetNode = this.endNode;
                    this.pathHandler.GetPathNode(this.endNode).flag1 = true;
                }
            }
        }
Exemplo n.º 4
0
        public override void Prepare()
        {
            base.nnConstraint.tags = base.enabledTags;
            NNInfo           info         = AstarPath.active.GetNearest(this.startPoint, base.nnConstraint, this.startHint);
            PathNNConstraint nnConstraint = base.nnConstraint as PathNNConstraint;

            if (nnConstraint != null)
            {
                nnConstraint.SetStart(info.node);
            }
            this.startPoint    = info.position;
            this.startIntPoint = (Int3)this.startPoint;
            this.startNode     = info.node;
            if (this.startNode == null)
            {
                base.Error();
            }
            else if (!this.startNode.Walkable)
            {
                base.Error();
            }
            else if (this.hasEndPoint)
            {
                NNInfo info2 = AstarPath.active.GetNearest(this.endPoint, base.nnConstraint, this.endHint);
                this.endPoint = info2.position;
                this.endNode  = info2.node;
                if ((this.startNode == null) && (this.endNode == null))
                {
                    base.Error();
                }
                else if (this.endNode == null)
                {
                    base.Error();
                }
                else if (!this.endNode.Walkable)
                {
                    base.Error();
                }
                else if (this.startNode.Area != this.endNode.Area)
                {
                    base.Error();
                }
                else if (!this.EndPointGridGraphSpecialCase(info2.node))
                {
                    base.hTarget     = (Int3)this.endPoint;
                    base.hTargetNode = this.endNode;
                    base.pathHandler.GetPathNode(this.endNode).flag1 = true;
                }
            }
        }
Exemplo n.º 5
0
        protected override void Prepare()
        {
            this.nnConstraint.tags = this.enabledTags;
            NNInfo nearest = AstarPath.active.GetNearest(this.startPoint, this.nnConstraint);

            this.startNode = nearest.node;
            if (this.startNode == null)
            {
                base.LogError("Could not find start node for multi target path");
                base.Error();
                return;
            }
            if (!base.CanTraverse(this.startNode))
            {
                base.Error();
                base.LogError("The node closest to the start point could not be traversed");
                return;
            }
            PathNNConstraint pathNNConstraint = this.nnConstraint as PathNNConstraint;

            if (pathNNConstraint != null)
            {
                pathNNConstraint.SetStart(nearest.node);
            }
            this.vectorPaths     = new List <Vector3> [this.targetPoints.Length];
            this.nodePaths       = new List <GraphNode> [this.targetPoints.Length];
            this.targetNodes     = new GraphNode[this.targetPoints.Length];
            this.targetsFound    = new bool[this.targetPoints.Length];
            this.targetNodeCount = this.targetPoints.Length;
            bool flag  = false;
            bool flag2 = false;
            bool flag3 = false;

            for (int i = 0; i < this.targetPoints.Length; i++)
            {
                NNInfo nearest2 = AstarPath.active.GetNearest(this.targetPoints[i], this.nnConstraint);
                this.targetNodes[i]  = nearest2.node;
                this.targetPoints[i] = nearest2.position;
                if (this.targetNodes[i] != null)
                {
                    flag3        = true;
                    this.endNode = this.targetNodes[i];
                }
                bool flag4 = false;
                if (nearest2.node != null && base.CanTraverse(nearest2.node))
                {
                    flag = true;
                }
                else
                {
                    flag4 = true;
                }
                if (nearest2.node != null && nearest2.node.Area == this.startNode.Area)
                {
                    flag2 = true;
                }
                else
                {
                    flag4 = true;
                }
                if (flag4)
                {
                    this.targetsFound[i] = true;
                    this.targetNodeCount--;
                }
            }
            this.startPoint    = nearest.position;
            this.startIntPoint = (Int3)this.startPoint;
            if (this.startNode == null || !flag3)
            {
                base.LogError(string.Concat(new string[]
                {
                    "Couldn't find close nodes to either the start or the end (start = ",
                    (this.startNode != null) ? "found" : "not found",
                    " end = ",
                    flag3 ? "at least one found" : "none found",
                    ")"
                }));
                base.Error();
                return;
            }
            if (!this.startNode.Walkable)
            {
                base.LogError("The node closest to the start point is not walkable");
                base.Error();
                return;
            }
            if (!flag)
            {
                base.Error();
                base.LogError("No target nodes could be traversed");
                return;
            }
            if (!flag2)
            {
                base.LogError("There are no valid paths to the targets");
                base.Error();
                return;
            }
            this.RecalculateHTarget(true);
        }
Exemplo n.º 6
0
        public override void Prepare()
        {
            this.nnConstraint.tags = this.enabledTags;
            NNInfo           nearest          = AstarPath.active.GetNearest(this.startPoint, this.nnConstraint, this.startHint);
            PathNNConstraint pathNNConstraint = this.nnConstraint as PathNNConstraint;

            if (pathNNConstraint != null)
            {
                pathNNConstraint.SetStart(nearest.node);
            }
            this.startPoint    = nearest.clampedPosition;
            this.startIntPoint = (Int3)this.startPoint;
            this.startNode     = nearest.node;
            if (this.hasEndPoint)
            {
                NNInfo nearest2 = AstarPath.active.GetNearest(this.endPoint, this.nnConstraint, this.endHint);
                this.endPoint    = nearest2.clampedPosition;
                this.hTarget     = (Int3)this.endPoint;
                this.endNode     = nearest2.node;
                this.hTargetNode = this.endNode;
            }
            if (this.startNode == null && this.hasEndPoint && this.endNode == null)
            {
                base.Error();
                base.LogError("Couldn't find close nodes to the start point or the end point");
                return;
            }
            if (this.startNode == null)
            {
                base.Error();
                base.LogError("Couldn't find a close node to the start point");
                return;
            }
            if (this.endNode == null && this.hasEndPoint)
            {
                base.Error();
                base.LogError("Couldn't find a close node to the end point");
                return;
            }
            if (!this.startNode.Walkable)
            {
                base.Error();
                base.LogError("The node closest to the start point is not walkable");
                return;
            }
            if (this.hasEndPoint && !this.endNode.Walkable)
            {
                base.Error();
                base.LogError("The node closest to the end point is not walkable");
                return;
            }
            if (this.hasEndPoint && this.startNode.Area != this.endNode.Area)
            {
                base.Error();
                base.LogError(string.Concat(new object[]
                {
                    "There is no valid path to the target (start area: ",
                    this.startNode.Area,
                    ", target area: ",
                    this.endNode.Area,
                    ")"
                }));
                return;
            }
        }
Exemplo n.º 7
0
        /** Prepares the path. Searches for start and end nodes and does some simple checking if a path is at all possible */
        public override void Prepare()
        {
            AstarProfiler.StartProfile("Get Nearest");

            //Initialize the NNConstraint
            nnConstraint.tags = enabledTags;
            NNInfo startNNInfo = AstarPath.active.GetNearest(startPoint, nnConstraint, startHint);

            //Tell the NNConstraint which node was found as the start node if it is a PathNNConstraint and not a normal NNConstraint
            PathNNConstraint pathNNConstraint = nnConstraint as PathNNConstraint;

            if (pathNNConstraint != null)
            {
                pathNNConstraint.SetStart(startNNInfo.node);
            }

            startPoint = startNNInfo.clampedPosition;

            startIntPoint = (Int3)startPoint;
            startNode     = startNNInfo.node;

            //If it is declared that this path type has an end point
            //Some path types might want to use most of the ABPath code, but will not have an explicit end point at this stage
            if (hasEndPoint)
            {
                NNInfo endNNInfo = AstarPath.active.GetNearest(endPoint, nnConstraint, endHint);
                endPoint = endNNInfo.clampedPosition;

                // Note, other methods assume hTarget is (Int3)endPoint
                hTarget     = (Int3)endPoint;
                endNode     = endNNInfo.node;
                hTargetNode = endNode;
            }

            AstarProfiler.EndProfile();


            if (startNode == null && (hasEndPoint && endNode == null))
            {
                Error();
                LogError("Couldn't find close nodes to the start point or the end point");
                return;
            }

            if (startNode == null)
            {
                Error();
                LogError("Couldn't find a close node to the start point");
                return;
            }

            if (endNode == null && hasEndPoint)
            {
                Error();
                LogError("Couldn't find a close node to the end point");
                return;
            }

            if (!startNode.Walkable)
            {
                Error();
                LogError("The node closest to the start point is not walkable");
                return;
            }

            if (hasEndPoint && !endNode.Walkable)
            {
                Error();
                LogError("The node closest to the end point is not walkable");
                return;
            }

            if (hasEndPoint && startNode.Area != endNode.Area)
            {
                Error();
                LogError("There is no valid path to the target (start area: " + startNode.Area + ", target area: " + endNode.Area + ")");
                return;
            }
        }
Exemplo n.º 8
0
        public override void Prepare()
        {
            System.DateTime startTime = System.DateTime.Now;

            maxFrameTime = AstarPath.active.maxFrameTime;

            if (AstarPath.NumParallelThreads > 1)
            {
                LogError("MultiTargetPath can only be used with at most 1 concurrent pathfinder. Please use no multithreading or only 1 thread.");
                return;
            }

            nnConstraint.tags = enabledTags;
            NNInfo startNNInfo = AstarPath.active.GetNearest(startPoint, nnConstraint, startHint);

            startNode = startNNInfo.node;

            if (startNode == null)
            {
                LogError("Could not find start node for multi target path");
                return;
            }

            if (!startNode.walkable)
            {
                LogError("Nearest node to the start point is not walkable");
                return;
            }

            //Tell the NNConstraint which node was found as the start node if it is a PathNNConstraint and not a normal NNConstraint
            PathNNConstraint pathNNConstraint = nnConstraint as PathNNConstraint;

            if (pathNNConstraint != null)
            {
                pathNNConstraint.SetStart(startNNInfo.node);
            }

            vectorPaths     = new Vector3[targetPoints.Length][];
            nodePaths       = new Node[targetPoints.Length][];
            targetNodes     = new Node[targetPoints.Length];
            targetsFound    = new bool[targetPoints.Length];
            targetNodeCount = targetPoints.Length;

            bool anyWalkable = false;
            bool anySameArea = false;
            bool anyNotNull  = false;

            for (int i = 0; i < targetPoints.Length; i++)
            {
                NNInfo endNNInfo = AstarPath.active.GetNearest(targetPoints[i], nnConstraint);


                targetNodes[i] = endNNInfo.node;
                //Debug.DrawLine (targetPoints[i],targetNodes[i].position,Color.red);
                targetPoints[i] = endNNInfo.clampedPosition;
                if (targetNodes[i] != null)
                {
                    anyNotNull = true;
                    endNode    = targetNodes[i];
                }

                bool notReachable = false;

                if (endNNInfo.node.walkable)
                {
                    anyWalkable = true;
                }
                else
                {
                    notReachable = true;
                }

                if (endNNInfo.node.area == startNode.area)
                {
                    anySameArea = true;
                }
                else
                {
                    notReachable = true;
                }

                if (notReachable)
                {
                    targetsFound[i] = true;                     //Signal that the pathfinder should not look for this node
                    targetNodeCount--;
                }
            }

            startPoint = startNNInfo.clampedPosition;


            startIntPoint = (Int3)startPoint;
            //hTarget = (Int3)endPoint;

                        #if DEBUGGING
            Debug.DrawLine(startNode.position, startPoint, Color.blue);
            //Debug.DrawLine (endNode.position,endPoint,Color.blue);
                        #endif

            if (startNode == null || !anyNotNull)
            {
                LogError("Couldn't find close nodes to either the start or the end (start = " + (startNode != null) + " end = " + (anyNotNull) + ")");
                duration += (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
                return;
            }

            if (!startNode.walkable)
            {
                LogError("The node closest to the start point is not walkable");

                duration += (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
                return;
            }

            if (!anyWalkable)
            {
                LogError("No target nodes were walkable");

                duration += (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
                return;
            }

            if (!anySameArea)
            {
                LogError("There are no valid paths to the targets");
                //Debug.DrawLine (startNode.position,endNode.position,Color.cyan);
                duration += (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
                return;
            }


            //=== Calcuate hTarget ===

            if (pathsForAll)
            {
                if (heuristicMode == HeuristicMode.None)
                {
                    heuristic      = Heuristic.None;
                    heuristicScale = 0F;
                }
                else if (heuristicMode == HeuristicMode.Average || heuristicMode == HeuristicMode.MovingAverage)
                {
                    heuristic      = AstarPath.active.heuristic;
                    heuristicScale = AstarPath.active.heuristicScale;

                    Vector3 avg = Vector3.zero;

                    for (int i = 0; i < targetNodes.Length; i++)
                    {
                        avg += (Vector3)targetNodes[i].position;
                    }
                    avg    /= targetNodes.Length;
                    hTarget = (Int3)avg;
                }
                else if (heuristicMode == HeuristicMode.Midpoint || heuristicMode == HeuristicMode.MovingMidpoint)
                {
                    heuristic      = AstarPath.active.heuristic;
                    heuristicScale = AstarPath.active.heuristicScale;

                    Vector3 min = Vector3.zero;
                    Vector3 max = Vector3.zero;
                    bool    set = false;

                    for (int j = 0; j < targetPoints.Length; j++)
                    {
                        if (!targetsFound[j])
                        {
                            if (!set)
                            {
                                min = (Vector3)targetNodes[j].position;
                                max = (Vector3)targetNodes[j].position;
                                set = true;
                            }
                            else
                            {
                                min = Vector3.Min((Vector3)targetNodes[j].position, min);
                                max = Vector3.Max((Vector3)targetNodes[j].position, max);
                            }
                        }
                    }

                    Vector3 midpoint = (min + max) * 0.5F;
                    hTarget = (Int3)midpoint;
                }
                else if (heuristicMode == HeuristicMode.Sequential)
                {
                    heuristic      = AstarPath.active.heuristic;
                    heuristicScale = AstarPath.active.heuristicScale;

                    float dist = 0;

                    for (int j = 0; j < targetNodes.Length; j++)
                    {
                        if (!targetsFound[j])
                        {
                            float d = (targetNodes[j].position - startNode.position).sqrMagnitude;
                            if (d > dist)
                            {
                                dist             = d;
                                hTarget          = (Int3)targetPoints[j];
                                sequentialTarget = j;
                            }
                        }
                    }
                }
            }
            else
            {
                heuristic      = Heuristic.None;
                heuristicScale = 0.0F;
            }

            //=======

            duration += (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
        }
Exemplo n.º 9
0
        public virtual void Prepare()
        {
            System.DateTime startTime = System.DateTime.Now;



            //@pathStartTime = startTime;

            maxFrameTime = AstarPath.active.maxFrameTime;

            //maxAngle = NmaxAngle;
            //angleCost = NangleCost;
            //stepByStep = NstepByStep;
            //unitRadius = 0;//BETA, Not used
            NNInfo startNNInfo = AstarPath.active.GetNearest(startPoint, nnConstraint, startHint);

            //Tell the NNConstraint which node was found as the start node if it is a PathNNConstraint and not a normal NNConstraint
            PathNNConstraint pathNNConstraint = nnConstraint as PathNNConstraint;

            if (pathNNConstraint != null)
            {
                pathNNConstraint.SetStart(startNNInfo.node);
            }

            NNInfo endNNInfo = AstarPath.active.GetNearest(endPoint, nnConstraint, endHint);

            startPoint = startNNInfo.clampedPosition;
            endPoint   = endNNInfo.clampedPosition;

            startIntPoint = (Int3)startPoint;
            hTarget       = (Int3)endPoint;

            startNode = startNNInfo.node;
            endNode   = endNNInfo.node;


            if (startNode == null || endNode == null)
            {
                LogError("Couldn't find close nodes to either the start or the end (start = " + (startNode != null) + " end = " + (endNode != null) + ")");
                duration += (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
                return;
            }

            if (!startNode.walkable)
            {
                LogError("The node closest to the start point is not walkable");

                duration += (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
                return;
            }

            if (!endNode.walkable)
            {
                LogError("The node closest to the start point is not walkable");

                duration += (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
                return;
            }

            if (startNode.area != endNode.area)
            {
                LogError("There is no valid path to the target (start area: " + startNode.area + ", target area: " + endNode.area + ")");
                //Debug.DrawLine (startNode.position,endNode.position,Color.cyan);
                duration += (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
                return;
            }

            duration += (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
        }
Exemplo n.º 10
0
        public override void Prepare()
        {
            this.nnConstraint.tags = this.enabledTags;
            NNInfo nearest = AstarPath.active.GetNearest(this.startPoint, this.nnConstraint, this.startHint);

            this.startNode = nearest.node;
            if (this.startNode == null)
            {
                base.LogError("Could not find start node for multi target path");
                base.Error();
                return;
            }
            if (!this.startNode.Walkable)
            {
                base.LogError("Nearest node to the start point is not walkable");
                base.Error();
                return;
            }
            PathNNConstraint pathNNConstraint = this.nnConstraint as PathNNConstraint;

            if (pathNNConstraint != null)
            {
                pathNNConstraint.SetStart(nearest.node);
            }
            this.vectorPaths     = new List <Vector3> [this.targetPoints.Length];
            this.nodePaths       = new List <GraphNode> [this.targetPoints.Length];
            this.targetNodes     = new GraphNode[this.targetPoints.Length];
            this.targetsFound    = new bool[this.targetPoints.Length];
            this.targetNodeCount = this.targetPoints.Length;
            bool flag  = false;
            bool flag2 = false;
            bool flag3 = false;

            for (int i = 0; i < this.targetPoints.Length; i++)
            {
                NNInfo nearest2 = AstarPath.active.GetNearest(this.targetPoints[i], this.nnConstraint);
                this.targetNodes[i]  = nearest2.node;
                this.targetPoints[i] = nearest2.clampedPosition;
                if (this.targetNodes[i] != null)
                {
                    flag3        = true;
                    this.endNode = this.targetNodes[i];
                }
                bool flag4 = false;
                if (nearest2.node != null && nearest2.node.Walkable)
                {
                    flag = true;
                }
                else
                {
                    flag4 = true;
                }
                if (nearest2.node != null && nearest2.node.Area == this.startNode.Area)
                {
                    flag2 = true;
                }
                else
                {
                    flag4 = true;
                }
                if (flag4)
                {
                    this.targetsFound[i] = true;
                    this.targetNodeCount--;
                }
            }
            this.startPoint    = nearest.clampedPosition;
            this.startIntPoint = (Int3)this.startPoint;
            if (this.startNode == null || !flag3)
            {
                base.LogError(string.Concat(new string[]
                {
                    "Couldn't find close nodes to either the start or the end (start = ",
                    (this.startNode == null) ? "not found" : "found",
                    " end = ",
                    (!flag3) ? "none found" : "at least one found",
                    ")"
                }));
                base.Error();
                return;
            }
            if (!this.startNode.Walkable)
            {
                base.LogError("The node closest to the start point is not walkable");
                base.Error();
                return;
            }
            if (!flag)
            {
                base.LogError("No target nodes were walkable");
                base.Error();
                return;
            }
            if (!flag2)
            {
                base.LogError("There are no valid paths to the targets");
                base.Error();
                return;
            }
            if (this.pathsForAll)
            {
                if (this.heuristicMode == MultiTargetPath.HeuristicMode.None)
                {
                    this.heuristic      = Heuristic.None;
                    this.heuristicScale = 0f;
                }
                else if (this.heuristicMode == MultiTargetPath.HeuristicMode.Average || this.heuristicMode == MultiTargetPath.HeuristicMode.MovingAverage)
                {
                    Vector3 vector = Vector3.zero;
                    for (int j = 0; j < this.targetNodes.Length; j++)
                    {
                        vector += (Vector3)this.targetNodes[j].position;
                    }
                    vector      /= (float)this.targetNodes.Length;
                    this.hTarget = (Int3)vector;
                }
                else if (this.heuristicMode == MultiTargetPath.HeuristicMode.Midpoint || this.heuristicMode == MultiTargetPath.HeuristicMode.MovingMidpoint)
                {
                    Vector3 vector2 = Vector3.zero;
                    Vector3 vector3 = Vector3.zero;
                    bool    flag5   = false;
                    for (int k = 0; k < this.targetPoints.Length; k++)
                    {
                        if (!this.targetsFound[k])
                        {
                            if (!flag5)
                            {
                                vector2 = (Vector3)this.targetNodes[k].position;
                                vector3 = (Vector3)this.targetNodes[k].position;
                                flag5   = true;
                            }
                            else
                            {
                                vector2 = Vector3.Min((Vector3)this.targetNodes[k].position, vector2);
                                vector3 = Vector3.Max((Vector3)this.targetNodes[k].position, vector3);
                            }
                        }
                    }
                    Vector3 ob = (vector2 + vector3) * 0.5f;
                    this.hTarget = (Int3)ob;
                }
                else if (this.heuristicMode == MultiTargetPath.HeuristicMode.Sequential)
                {
                    float num = 0f;
                    for (int l = 0; l < this.targetNodes.Length; l++)
                    {
                        if (!this.targetsFound[l])
                        {
                            float sqrMagnitude = (this.targetNodes[l].position - this.startNode.position).sqrMagnitude;
                            if (sqrMagnitude > num)
                            {
                                num                   = sqrMagnitude;
                                this.hTarget          = (Int3)this.targetPoints[l];
                                this.sequentialTarget = l;
                            }
                        }
                    }
                }
            }
            else
            {
                this.heuristic      = Heuristic.None;
                this.heuristicScale = 0f;
            }
        }
Exemplo n.º 11
0
        public override void Prepare()
        {
            this.nnConstraint.tags = this.enabledTags;
            NNInfo nearest = AstarPath.active.GetNearest(this.startPoint, this.nnConstraint, this.startHint);

            this.startNode = nearest.node;
            if (this.startNode == null)
            {
                base.Error();
                return;
            }
            if (!this.startNode.Walkable)
            {
                base.Error();
                return;
            }
            PathNNConstraint pathNNConstraint = this.nnConstraint as PathNNConstraint;

            if (pathNNConstraint != null)
            {
                pathNNConstraint.SetStart(nearest.node);
            }
            this.vectorPaths     = new List <Vector3> [this.targetPoints.Length];
            this.nodePaths       = new List <GraphNode> [this.targetPoints.Length];
            this.targetNodes     = new GraphNode[this.targetPoints.Length];
            this.targetsFound    = new bool[this.targetPoints.Length];
            this.targetNodeCount = this.targetPoints.Length;
            bool flag  = false;
            bool flag2 = false;
            bool flag3 = false;

            for (int i = 0; i < this.targetPoints.Length; i++)
            {
                NNInfo nearest2 = AstarPath.active.GetNearest(this.targetPoints[i], this.nnConstraint);
                this.targetNodes[i]  = nearest2.node;
                this.targetPoints[i] = nearest2.position;
                if (this.targetNodes[i] != null)
                {
                    flag3        = true;
                    this.endNode = this.targetNodes[i];
                }
                bool flag4 = false;
                if (nearest2.node != null && nearest2.node.Walkable)
                {
                    flag = true;
                }
                else
                {
                    flag4 = true;
                }
                if (nearest2.node != null && nearest2.node.Area == this.startNode.Area)
                {
                    flag2 = true;
                }
                else
                {
                    flag4 = true;
                }
                if (flag4)
                {
                    this.targetsFound[i] = true;
                    this.targetNodeCount--;
                }
            }
            this.startPoint    = nearest.position;
            this.startIntPoint = (Int3)this.startPoint;
            if (this.startNode == null || !flag3)
            {
                base.Error();
                return;
            }
            if (!this.startNode.Walkable)
            {
                base.Error();
                return;
            }
            if (!flag)
            {
                base.Error();
                return;
            }
            if (!flag2)
            {
                base.Error();
                return;
            }
            this.RecalculateHTarget(true);
        }