/// <summary> /// Check if the added block is connected to the main robot path (no fully functional) /// </summary> /// <param name="block">The block to validate</param> /// <param name="grid">The voxelgrid</param> /// <returns>Can the block be added or not</returns> private bool ConnectedPath(Block block, Grid3D grid) { var pathFinding = grid.PFinding; var index = block.BlockVoxels.Where(v => v.Type == VoxelType.Block).Select(v => v.Index); var prevVoxels = index.Select(v => grid.GetVoxelAt(v)); foreach (var vox in block.BlockVoxels.Where(v => v.Type == VoxelType.Block)) { //place the block within the voxelgrid grid.AddVoxel(vox); foreach (var face in grid.GetVoxelAt(vox.Index).Faces.Where(f => f.Climable)) { int test = pathFinding.GetPathCount(pathFinding.CreateGraph(), face); if (test != pathFinding.RidiculousHighNumber) { return(true); } } } //restore the original state of the voxelgrid foreach (var v in prevVoxels) { grid.AddVoxel(v); } return(false); }
/// <summary> /// Instantiate or switch the blockvoxels gameobjects to their new state /// </summary> /// <param name="grid">The global grid</param> public void DrawBlock(Grid3D grid) { InstantiateGoParrentBlock(); foreach (var vox in BlockVoxels) { if (!(vox.Index.x < 0 || vox.Index.y < 0 || vox.Index.z < 0 || vox.Index.x >= Controller.Size.x || vox.Index.y >= Controller.Size.y || vox.Index.z >= Controller.Size.z)) { var gridVox = grid.GetVoxelAt(vox.Index); if ((vox.Type == VoxelType.Block || vox.Type == VoxelType.Connection) && gridVox.Type != VoxelType.Block) { if (gridVox.Go == null) { gridVox.Go = GameObject.Instantiate(Controller.GoVoxel, vox.Index, Quaternion.identity, vox.ParentBlock.goBlockParent.transform); gridVox.Go.name = vox.Name; } if (vox.Type == VoxelType.Connection) { GameObject go = gridVox.Go; var rend = go.GetComponentInChildren <Renderer>(); go.transform.SetParent(vox.ParentBlock.goBlockParent.transform); rend.material = Controller.MatConnection; } else if (vox.Type == VoxelType.Block) { GameObject go = gridVox.Go; var rend = go.GetComponentInChildren <Renderer>(); go.transform.SetParent(vox.ParentBlock.goBlockParent.transform); rend.material = Controller.MatBlock; } } } } }