private HexPathTileBase CreateTile(Vector3Int coords, byte pathcode, bool selected, bool visited, bool goal) { HexPathTileBase tile = m_Tilemap.GetTile <HexPathTileBase>(coords); //if ( tile != null && tile.Visited ) return false; if (tile != null) { tile.Selected = !tile.Visited; return(tile); } tile = Instantiate(m_HexPathTileBase); tile.PathCode = pathcode; tile.Selected = selected; tile.Visited = visited; tile.Goal = goal; tile.Coords = coords; tile.Grid = this; m_Tilemap.SetTile(coords, tile); m_Tilemap.RefreshTile(coords); if (!goal && !visited) { m_TileCount++; } m_TilesCounterTMPro.text = string.Format("{0}\nTILE{1}", m_TileCount, m_TileCount == 1 ? "" : "S"); return(tile); }
public void MovedToCoords(Vector3Int coords, byte fromDir) { HexPathTileBase tile = m_Tilemap.GetTile <HexPathTileBase>(coords); if (tile.Goal) { CompleteLevel(); return; } tile.Selected = false; tile.Visited = true; Player.CurrentCode = tile.PathCode; //byte[] bytes = GetBytes( tile.PathCode ); //int fd = HexPathTile.PathDirs.ToList().IndexOf( fromDir ); //int fail = 0; //for ( int i = 0; i < bytes.Length; i++ ) //{ // if ( bytes[i] == fromDir ) continue; // byte d = HexPathTile.PathDirs[(int)Mathf.Repeat( fd + 3, 6 )]; // byte p1 = d; while ( p1 == d ) p1 = HexPathTile.PathDirs.Random(); // byte p2 = d; while ( p2 == d || p2 == p1 ) p2 = HexPathTile.PathDirs.Random(); // byte p3 = 0; // if ( Random.Range( 0, 2 ) == 0 ) // p3 = d; while ( p3 == d || p3 == p2 || p3 == p1 ) p3 = HexPathTile.PathDirs.Random(); // HexPathTileBase nbor = CreateTile( oddq_offset_neighbor( coords, HexPathTile.PathDirs.ToList().IndexOf( bytes[i] ) ), (byte)( p1 + p2 + p3 ), true, false, false ); // if ( nbor.Visited && !nbor.PathCode.HasByte( d ) ) // { // fail++; // //FailLevel(); // } //} //if ( fail >= bytes.Length ) FailLevel(); int dir = HexPathTile.PathDirs.ToList().IndexOf((byte)(tile.PathCode - HexPathTile.PathDirs[fromDir])); if (dir >= 0) { byte d = HexPathTile.PathDirs[(int)Mathf.Repeat(dir + 3, 6)]; byte p1 = d; while (p1 == d) { p1 = HexPathTile.PathDirs.Random(); } byte p2 = d; while (p2 == d || p2 == p1) { p2 = HexPathTile.PathDirs.Random(); } HexPathTileBase nbor = CreateTile(oddq_offset_neighbor(coords, dir), (byte)(p1 + p2), true, false, false); if (nbor.Visited && !nbor.PathCode.HasByte(d)) { FailLevel(); } } }
public bool CheckNeighborPaths(Vector3Int coords, int direction) { HexPathTileBase tile = m_Tilemap.GetTile <HexPathTileBase>(oddq_offset_neighbor(coords, direction)); if (tile) { return(tile.PathCode.HasByte(HexPathTile.PathDirs[(int)Mathf.Repeat(direction + 3, 6)])); } return(false); }
public HexPathTile GetNeighbor(Vector3Int coords, int direction) { HexPathTileBase tile = m_Tilemap.GetTile <HexPathTileBase>(oddq_offset_neighbor(coords, direction)); if (tile) { return(tile.Tile); } return(null); }
private void ClearTilemap() { foreach (Vector3Int pos in m_Tilemap.cellBounds.allPositionsWithin) { HexPathTileBase tile = m_Tilemap.GetTile <HexPathTileBase>(pos); if (tile) { if (tile.Tile.gameObject) { Destroy(tile.Tile.gameObject); } } } m_Tilemap.ClearAllTiles(); }