public HashList <GraphNode> GetDistanceRange(Vector3 pos, float distance, Func <GraphNode, bool> filter = null) { BFSQueue.Clear(); BFSResult.Clear(); BFSRange.Clear(); var depth = distance / NodeSize; GraphNode seed = GetNode(pos); Action <GraphNodeRange, GraphNode> callback = (parent, node) => { if (node.Walkable && !BFSResult.Contains(node)) { if (filter != null && !filter(node)) { return; } var nRangeItem = new GraphNodeRange(parent, node); if (nRangeItem.Distance > distance) { return; } if (nRangeItem.Depth > depth) { return; } BFSResult.Add(node); BFSQueue.Enqueue(node); BFSRange.Add(node, nRangeItem); } }; callback(null, seed); while (BFSQueue.Count > 0) { GraphNode n = BFSQueue.Dequeue(); GraphNodeRange nRangeItem = BFSRange[n]; if (nRangeItem.Distance > distance) { break; } if (nRangeItem.Depth > depth) { break; } n.GetConnections((x) => { callback(nRangeItem, x); }); } return(BFSResult); }
public bool IsRope(string id) { if (Rope.Contains(id)) { return(true); } return(false); }
public bool IsBlocker(TNode node) { if (node == null) { return(false); } if (AllBlockers.Contains(node)) { return(true); } return(false); }
//移动范围是否可以链接到目标 public bool IsCanConstantConnection(BaseUnit unit) { if (ConstantNodesMove == null || ConstantNodesMove.Count == 0) { return(false); } HashList <GraphNode> links = AStarMgr.GetConnectionsBlocker(unit); foreach (var item in links) { if (ConstantNodesMove.Contains(item)) { return(true); } } return(false); }
//当前Unit的node是否可以连接到目标Unit的Blocker范围内,一般可以用来做攻击检测 public bool IsInBlockerRange(BaseUnit unit) { HashList <GraphNode> connection = new HashList <GraphNode>(); CurNode.GetConnections(connection.Add); HashList <GraphNode> targetUnitBlocker = AStarMgr.GetBlocker(unit); if (targetUnitBlocker != null) { foreach (var item in targetUnitBlocker) { if (connection.Contains(item)) { return(true); } } } else { CLog.Error("{0}:目标单位没有Blocker", unit.BaseConfig.GetName()); } return(false); }