public bool isPlaceableTile(Vector3Int tileIndex) { if (m_tileMap) { TDTileBase tile = m_tileMap.GetTile <TDTileBase>(tileIndex); if (tile) { return(tile.TileType == TDTileType.Placeable); } } return(false); }
/// <summary> /// Finds the goal tile of a tile map /// </summary> /// <param name="tileMap">Tile map to query</param> /// <returns>Location of goal</returns> static private Vector3Int getGoal(Tilemap tileMap) { foreach (Vector3Int tileIndex in tileMap.cellBounds.allPositionsWithin) { TDTileBase tile = tileMap.GetTile <TDTileBase>(tileIndex); if (!tile) { continue; } if (tile.TileType == TDTileType.Goal) { return(tileIndex); } } return(Vector3Int.zero); }
/// <summary> /// Checks if paths can be generated and will intialize itself if allowed it /// </summary> /// <param name="tileMap">Tile map to base off</param> /// <returns>If intiializing completed</returns> private bool initForGeneration(Tilemap tileMap) { // Check this first, we don't want to overwrite anything if already generating if (Generating) { return(false); } m_paths = null; if (!tileMap) { return(false); } // Need a goal tile to act as source for flow field m_goal = getGoal(tileMap); if (!tileMap.HasTile(m_goal)) { return(false); } // Grab all tiles and put them into our own dictionary. We need // to do this as we can't access tiles on a separate thread m_tileMap = new Dictionary <Vector3Int, TDTileType>(); { foreach (Vector3Int tileIndex in tileMap.cellBounds.allPositionsWithin) { TDTileBase tile = tileMap.GetTile <TDTileBase>(tileIndex); if (!tile) { continue; } m_tileMap.Add(tileIndex, tile.TileType); } } m_paths = new List <Path>(); return(true); }