示例#1
0
        internal NavNode FindNode(Vector2 pos)
        {
            NavNode node = nodes
                           .Where(i => pos.CastNav(i.pos))
                           .OrderBy(i => (pos - i.pos).sqrMagnitude)
                           .FirstOrDefault();

            if (node == null)
            {
                Debug.Log("find node null");
            }
            return(node);
        }
示例#2
0
 void WeaveBranches(NavNode pivot, HashSet <Bezite> branches)
 {
     foreach (Bezite branch in branches)
     {
         bezite = branch;
         List <NavNode> nodes = new List <NavNode>(new Linker <NavNode>(InitNode, Eval).result);
         this.nodes.Remove(nodes[0]);
         nodes.RemoveAt(0);
         pivot.Link(nodes[0]);
         for (int i = 0; i < nodes.Count - 1; i++)
         {
             nodes[i].Link(nodes[i + 1]);
         }
     }
 }
示例#3
0
 public void createDownNodeAt(int x, int y, int depth, float cost)
 {
     if (grid [x, y] != null)
     {
         if (grid [x, y].getDownNode() != null)
         {
             NavNode temp = grid [x, y].getDownNode();
             while (temp.getDownNode() != null)
             {
                 temp = temp.getDownNode();
             }
             NavNode newNode = new NavNode(cost, depth);
             temp.setDownNode(newNode);
         }
         else
         {
             NavNode newNode = new NavNode(cost, depth);
             grid [x, y].getDownNode().setDownNode(newNode);
         }
     }
 }
示例#4
0
 void FindPathRec()
 {
     if (current == target)
     {
         return;
     }
     foreach (KeyValuePair <NavNode, float> link in current.links)
     {
         NavNode node = link.Key;
         if (node.closed)
         {
             continue;
         }
         node.Calibrate(current, target.pos);
         openNodes.Add(node);
     }
     openNodes.Remove(current);
     current.closed = true;
     current        = openNodes.OrderBy(i => i.TotalDist).FirstOrDefault();
     FindPathRec();
 }
示例#5
0
        internal void Optimize()
        {
            List <NavNode> nodes = this.nodes
                                   .OrderByDescending(i => i.links.Count)
                                   .Where(i => i.links.Count > 1).ToList();

            for (int i = 0; i < nodes.Count; i++)
            {
                NavNode   node  = nodes[i];
                NavNode[] links = node.links.Keys
                                  .OrderBy(j => (j.pos - node.pos).Angle())
                                  .ToArray();
                if (Removable(links))
                {
                    LinkAround(node, links);
                    this.nodes.Remove(node);
                }
            }
            foreach (NavNode node in this.nodes)
            {
                node.GenWeights();
            }
        }
示例#6
0
 public void setDownNode(NavNode node)
 {
     down = node;
 }
示例#7
0
 public void updateNavNodeDepth(NavNode node, int depth)
 {
     node.setDepth(depth);
 }
示例#8
0
 public void updateNavNodeCost(NavNode node, float Cost)
 {
     node.setCost(Cost);
 }