Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected override List<GraphNode> GetNodesInRegion (Bounds b, GraphUpdateShape shape) {
- var rect = GetRectFromBounds(b);
- if (nodes == null || !rect.IsValid() || nodes.Length != width*depth*layerCount) {
- return Pathfinding.Util.ListPool<GraphNode>.Claim();
- }
- // Get a buffer we can use
- var inArea = Pathfinding.Util.ListPool<GraphNode>.Claim(rect.Width*rect.Height*layerCount);
- // Loop through all nodes in the rectangle
- for (int l = 0; l < layerCount; l++) {
- var lwd = l * width * depth;
- for (int x = rect.xmin; x <= rect.xmax; x++) {
- for (int z = rect.ymin; z <= rect.ymax; z++) {
- int index = lwd + z*width + x;
- GraphNode node = nodes[index];
- // If it is contained in the bounds (and optionally the shape)
- // then add it to the buffer
- if (node != null && b.Contains((Vector3)node.position) && (shape == null || shape.Contains((Vector3)node.position))) {
- inArea.Add(node);
- }
- }
- }
- }
- return inArea;
- }
- public override List<GraphNode> GetNodesInRegion (IntRect rect) {
- // Get a buffer we can use
- var inArea = Pathfinding.Util.ListPool<GraphNode>.Claim();
- // Rect which covers the whole grid
- var gridRect = new IntRect(0, 0, width-1, depth-1);
- // Clamp the rect to the grid
- rect = IntRect.Intersection(rect, gridRect);
- if (nodes == null || !rect.IsValid() || nodes.Length != width*depth*layerCount) return inArea;
- for (int l = 0; l < layerCount; l++) {
- var lwd = l * Width * Depth;
- for (int z = rect.ymin; z <= rect.ymax; z++) {
- var offset = lwd + z*Width;
- for (int x = rect.xmin; x <= rect.xmax; x++) {
- var node = nodes[offset + x];
- if (node != null) {
- inArea.Add(node);
- }
- }
- }
- }
- return inArea;
- }
- /** Get all nodes in a rectangle.
- * \param rect Region in which to return nodes. It will be clamped to the grid.
- * \param buffer Buffer in which the nodes will be stored. Should be at least as large as the number of nodes that can exist in that region.
- * \returns The number of nodes written to the buffer.
- */
- public override int GetNodesInRegion (IntRect rect, GridNodeBase[] buffer) {
- // Clamp the rect to the grid
- // Rect which covers the whole grid
- var gridRect = new IntRect(0, 0, width-1, depth-1);
- rect = IntRect.Intersection(rect, gridRect);
- if (nodes == null || !rect.IsValid() || nodes.Length != width*depth*layerCount) return 0;
- int counter = 0;
- try {
- for (int l = 0; l < layerCount; l++) {
- var lwd = l * Width * Depth;
- for (int z = rect.ymin; z <= rect.ymax; z++) {
- var offset = lwd + z*Width;
- for (int x = rect.xmin; x <= rect.xmax; x++) {
- var node = nodes[offset + x];
- if (node != null) {
- buffer[counter] = node;
- counter++;
- }
- }
- }
- }
- } catch (System.IndexOutOfRangeException) {
- // Catch the exception which 'buffer[counter] = node' would throw if the buffer was too small
- throw new System.ArgumentException("Buffer is too small");
- }
- return counter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement