/// <summary> /// Rasterize the obstacles into the grid. /// </summary> public void Rasterize() { // Clear the path grid from all blockages for (int i = 0; i < m_pathGrid.NumberOfCells; i++) { Vector3 cellPos = m_pathGrid.GetCellCenter(i); Vector3 start = cellPos + Vector3.up; Vector3 end = cellPos - Vector3.up; bool hit = Physics.CheckCapsule(start, end, m_pathGrid.CellSize * 0.5f, m_obstructedLayerMask.value); m_pathGrid.SetSolidity(i, hit); } // Render all of the footprints into the path grid as blocked // FootprintComponent[] footprintArray = (FootprintComponent[])GameObject.FindObjectsOfType(typeof(FootprintComponent)); // foreach (FootprintComponent footprint in footprintArray) // { // int numObstructedCells = 0; // int[] obstructedCells = footprint.GetObstructedCells(m_pathGrid, out numObstructedCells); // // for ( int i = 0; i < numObstructedCells; i++ ) // { // int obstructedCellIndex = obstructedCells[i]; // if ( m_pathGrid.IsInBounds(obstructedCellIndex) ) // { // m_pathGrid.SetSolidity(obstructedCellIndex, true); // } // } // } }
private Vector3 ChooseRandomDestination() { // Pick a random grid cell. int randomGridCell = Random.Range(0, m_pathGrid.NumberOfCells - 1); // Choose the center of that grid cell Vector3 dest = m_pathGrid.GetCellCenter(randomGridCell); return(dest); }
void OnDrawGizmos() { //Debug show in Scene if (m_debugShowPath) { if (swipeIndexList != null && swipeIndexList.Count > 0) { Gizmos.color = Color.red; for (int i = 1; i < swipeIndexList.Count; i++) { Vector3 start = m_pathGrid.GetCellCenter(swipeIndexList [i - 1]); Vector3 end = m_pathGrid.GetCellCenter(swipeIndexList [i]); Gizmos.DrawLine(start, end); if (swipeIndexList [i - 1] == swipeIndexList [i]) { Debug.LogError("i =" + i + " swipeIndexList [i - 1] =" + swipeIndexList [i - 1] + " swipeIndexList [i ] " + swipeIndexList [i] + " is the same"); } Gizmos.DrawCube(start, new Vector3(0.2f, 0.2f, 0.2f)); } } } }
void OnDrawGizmos() { Gizmos.color = m_obstructedCellColor; if (m_show && m_pathGrid != null) { for (int i = 0; i < m_pathGrid.NumberOfCells; i++) { if (m_pathGrid.IsBlocked(i)) { Vector3 cellPos = m_pathGrid.GetCellCenter(i); Vector3 cellSize3 = new Vector3(m_pathGrid.CellSize, 0.5f, m_pathGrid.CellSize); Gizmos.DrawCube(cellPos, cellSize3); } } } }