public static NavigationGrid CreateEmpty(int sizeX, int sizeY, int sizeZ, Vector3 position, Quaternion rotation, Vector3 scale, float boxSize = 1f) { var len = boxSize / 2; var off = new Vector3(len, 0, len); var min = new Vector3(0, 0, 0); Max = new Vector3(sizeX, sizeY, sizeZ); var grid = new NavigationGrid(); grid.InnerGrid = new NativeArray3D <GridNode>(sizeX, sizeY, sizeZ, Allocator.Persistent); grid.Transform.Set(position, rotation, scale); grid.BoxOffset = off; grid.BoxOffsetLength = len; grid.NodeBoxSize = boxSize; grid.GridMaxX = grid.InnerGrid.GetLength(0) - 1; grid.GridMaxY = grid.InnerGrid.GetLength(1) - 1; grid.GridMaxZ = grid.InnerGrid.GetLength(2) - 1; grid.MinX = 0; grid.MaxX = grid.GridMaxX; grid.MinY = 0; grid.MaxY = grid.GridMaxY; grid.MinZ = 0; grid.MaxZ = grid.GridMaxZ; return(grid); }
public static NavigationGrid Create(int sizeX, int sizeY, int sizeZ, Vector3 position, Quaternion rotation, Vector3 scale, float boxSize = 1f) { var len = boxSize / 2; var off = new Vector3(len, 0, len); var min = new Vector3(0, 0, 0); Max = new Vector3(sizeX, sizeY, sizeZ); var nodes = new List <GridNode>(); for (var x = min.x + len; x < Max.x; x = x + boxSize) { for (var y = min.y + len; y < Max.y; y = y + boxSize) { for (var z = min.z + len; z < Max.z; z = z + boxSize) { var navNode = new GridNode(); var center = new Vector3(x, y, z); navNode.Center = center; navNode.X = center.x; navNode.Y = center.y; navNode.Z = center.z; navNode.Size = new Vector3(boxSize, boxSize, boxSize); navNode.Bounds = new SimpleBounds(center, navNode.Size); navNode.NavigableCenter = center; nodes.Add(navNode); } } } var grid = new NavigationGrid(); grid.InnerGrid = new NativeArray3D <GridNode>(sizeX, sizeY, sizeZ, Allocator.Persistent); grid.Transform.Set(position, rotation, scale); grid.BoxOffset = off; grid.BoxOffsetLength = len; grid.NodeBoxSize = boxSize; grid.Update(nodes); grid.Data = new GridViewData { BoxSize = boxSize, Min = new int3(grid.MinX, grid.MinY, grid.MinZ), Max = new int3(grid.MaxX, grid.MaxY, grid.MaxZ), }; return(grid); }