Exemplo n.º 1
0
        public virtual void Apply()
        {
            if (Start == null || End == null || AstarPath.active == null)
            {
                return;
            }

            GraphNode startNode = AstarPath.active.GetNearest(Start.position).node;
            GraphNode endNode   = AstarPath.active.GetNearest(End.position).node;

            if (startNode == null || endNode == null)
            {
                return;
            }

            if (deleteConnection)
            {
                startNode.RemoveConnection(endNode);
                if (!oneWay)
                {
                    endNode.RemoveConnection(startNode);
                }
            }
            else
            {
                uint cost = (uint)System.Math.Round((startNode.position - endNode.position).costMagnitude * costFactor);

                startNode.AddConnection(endNode, cost);
                if (!oneWay)
                {
                    endNode.AddConnection(startNode, cost);
                }
            }
        }
Exemplo n.º 2
0
 public virtual void Apply()
 {
     if (((this.Start != null) && (this.End != null)) && (AstarPath.active != null))
     {
         GraphNode node  = AstarPath.active.GetNearest(this.Start.position).node;
         GraphNode node2 = AstarPath.active.GetNearest(this.End.position).node;
         if ((node != null) && (node2 != null))
         {
             if (this.deleteConnection)
             {
                 node.RemoveConnection(node2);
                 if (!this.oneWay)
                 {
                     node2.RemoveConnection(node);
                 }
             }
             else
             {
                 Int3 num2 = node.position - node2.position;
                 uint cost = (uint)Math.Round((double)(num2.costMagnitude * this.costFactor));
                 node.AddConnection(node2, cost);
                 if (!this.oneWay)
                 {
                     node2.AddConnection(node, cost);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        public virtual void Apply()
        {
            if (this.Start == null || this.End == null || AstarPath.active == null)
            {
                return;
            }
            GraphNode node  = AstarPath.active.GetNearest(this.Start.position).node;
            GraphNode node2 = AstarPath.active.GetNearest(this.End.position).node;

            if (node == null || node2 == null)
            {
                return;
            }
            if (this.deleteConnection)
            {
                node.RemoveConnection(node2);
                if (!this.oneWay)
                {
                    node2.RemoveConnection(node);
                }
            }
            else
            {
                uint cost = (uint)Math.Round((double)((float)(node.position - node2.position).costMagnitude * this.costFactor));
                node.AddConnection(node2, cost);
                if (!this.oneWay)
                {
                    node2.AddConnection(node, cost);
                }
            }
        }
Exemplo n.º 4
0
        public void Apply(bool forceNewCheck)
        {
            //TODO
            //This function assumes that connections from the n1,n2 nodes never need to be removed in the future (e.g because the nodes move or something)
            var nn    = NNConstraint.None;
            var graph = (int)startNode.GraphIndex;

            //Search all graphs but the one which start and end nodes are on
            nn.graphMask = ~(1 << graph);

            startNode.SetPosition((Int3)StartTransform.position);
            endNode.SetPosition((Int3)EndTransform.position);

            RemoveConnections(startNode);
            RemoveConnections(endNode);

            var cost = (uint)Mathf.RoundToInt(
                ((Int3)(StartTransform.position - EndTransform.position)).costMagnitude * costFactor);

            startNode.AddConnection(endNode, cost);
            endNode.AddConnection(startNode, cost);

            if (connectedNode1 == null || forceNewCheck)
            {
                var info = AstarPath.active.GetNearest(StartTransform.position, nn);
                connectedNode1 = info.node;
                clamped1       = info.position;
            }

            if (connectedNode2 == null || forceNewCheck)
            {
                var info = AstarPath.active.GetNearest(EndTransform.position, nn);
                connectedNode2 = info.node;
                clamped2       = info.position;
            }

            if (connectedNode2 == null || connectedNode1 == null)
            {
                return;
            }

            //Add connections between nodes, or replace old connections if existing
            connectedNode1.AddConnection(startNode,
                                         (uint)Mathf.RoundToInt(((Int3)(clamped1 - StartTransform.position)).costMagnitude * costFactor));
            if (!oneWay)
            {
                connectedNode2.AddConnection(endNode,
                                             (uint)Mathf.RoundToInt(((Int3)(clamped2 - EndTransform.position)).costMagnitude * costFactor));
            }

            if (!oneWay)
            {
                startNode.AddConnection(connectedNode1,
                                        (uint)Mathf.RoundToInt(((Int3)(clamped1 - StartTransform.position)).costMagnitude * costFactor));
            }
            endNode.AddConnection(connectedNode2,
                                  (uint)Mathf.RoundToInt(((Int3)(clamped2 - EndTransform.position)).costMagnitude * costFactor));
        }