示例#1
0
 public GraphNodeRange2D(GraphNodeRange2D parent, Node node)
 {
     Parent = parent;
     Node   = node;
     if (Parent != null)
     {
         Depth    = Parent.Depth + 1;
         Distance = Parent.Distance + Vector3.Distance(Node.Pos, Parent.Node.Pos);
     }
 }
示例#2
0
        public HashList <Node> GetDistanceRange(Vector3 pos, float distance, Func <Node, bool> filter = null)
        {
            BFSQueue.Clear();
            BFSResult.Clear();
            BFSRange.Clear();
            Node seed = GetNode(pos);
            Action <GraphNodeRange2D, Node> callback = (parent, node) =>
            {
                if (IsWalkable(node) && !BFSResult.Contains(node))
                {
                    if (filter != null && !filter(node))
                    {
                        return;
                    }
                    var nRangeItem = new GraphNodeRange2D(parent, node);
                    if (nRangeItem.Distance > distance)
                    {
                        return;
                    }

                    BFSResult.Add(node);
                    BFSQueue.Enqueue(node);
                    BFSRange.Add(node, nRangeItem);
                }
            };

            callback(null, seed);

            while (BFSQueue.Count > 0)
            {
                Node             n          = BFSQueue.Dequeue();
                GraphNodeRange2D nRangeItem = BFSRange[n];
                if (nRangeItem.Distance > distance)
                {
                    break;
                }
                n.GetConnections((x) =>
                {
                    callback(nRangeItem, x);
                });
            }
            return(BFSResult);
        }