private TileBase HasTwoOrMoreSort(Tilemap tilemap, int x, int y) { List <TileBase> auxListTileBase = new List <TileBase>(); TileBase repeatedTileBase = null; auxListTileBase.Add(tilemap.GetTile(new Vector3Int(x, y + 1, 0))); auxListTileBase.Add(tilemap.GetTile(new Vector3Int(x, y - 1, 0))); auxListTileBase.Add(tilemap.GetTile(new Vector3Int(x + 1, y, 0))); auxListTileBase.Add(tilemap.GetTile(new Vector3Int(x - 1, y, 0))); for (int i = 0; i < auxListTileBase.Count; i++) { List <TileBase> auxListCount = auxListTileBase.FindAll((tile) => { if (tile != null && auxListTileBase[i] != null) { TileBaseGroup auxTileDefaultGroup = listTileBase.Find((tileAux) => tileAux.tileDefault.Equals(tile) || tileAux.tileTop.Equals(tile)); if (auxTileDefaultGroup != null) { TileBase auxTileDefault = auxTileDefaultGroup.tileDefault; TileBase auxTileTop = auxTileDefaultGroup.tileTop; return(auxListTileBase[i].Equals(auxTileDefault) || auxListTileBase[i].Equals(auxTileTop)); } } return(false); }); if (auxListCount != null) { if (auxListCount.Count >= 2) { repeatedTileBase = auxListTileBase[i]; break; } } } int sort = Random.Range(0, 100); if (sort >= 99) { return(repeatedTileBase); } return(null); }
public void Smooth() { for (int i = startPosition; i < height; i++) { for (int j = startPosition; j < width; j++) { if (IsAroundVoid(tilemapBase, j, i)) { tilemapAux.SetTile(new Vector3Int(j, i, 0), null); } else if (HasThreeOrMore(tilemapBase, j, i) != null) { tilemapAux.SetTile(new Vector3Int(j, i, 0), HasThreeOrMore(tilemapBase, j, i)); } else if (HasTwoOrMore(tilemapBase, j, i)) { TileBase auxSort = HasTwoOrMoreSort(tilemapBase, j, i); if (auxSort != null) { tilemapAux.SetTile(new Vector3Int(j, i, 0), auxSort); } else { tilemapAux.SetTile(new Vector3Int(j, i, 0), tilemapBase.GetTile(new Vector3Int(j, i, 0))); } } else { tilemapAux.SetTile(new Vector3Int(j, i, 0), tilemapBase.GetTile(new Vector3Int(j, i, 0))); } } } for (int i = startPosition; i < height; i++) { for (int j = startPosition; j < width; j++) { if (tilemapAux.HasTile(new Vector3Int(j, i, 0))) { if (IsTop(tilemapAux, j, i)) { TileBaseGroup auxTileSetTopGroup = listTileBase.Find((tile) => tile.tileDefault.Equals(tilemapAux.GetTile(new Vector3Int(j, i, 0))) || tile.tileTop.Equals(tilemapAux.GetTile(new Vector3Int(j, i, 0)))); if (auxTileSetTopGroup != null) { TileBase auxTileSetTop = auxTileSetTopGroup.tileTop; tilemapAux.SetTile(new Vector3Int(j, i, 0), auxTileSetTop); } } else { TileBaseGroup auxTileSetTopGroup = listTileBase.Find((tile) => tile.tileDefault.Equals(tilemapAux.GetTile(new Vector3Int(j, i, 0))) || tile.tileTop.Equals(tilemapAux.GetTile(new Vector3Int(j, i, 0)))); if (auxTileSetTopGroup != null) { TileBase auxTileSetDefault = auxTileSetTopGroup.tileDefault; tilemapAux.SetTile(new Vector3Int(j, i, 0), auxTileSetDefault); } } } tilemapBase.SetTile(new Vector3Int(j, i, 0), tilemapAux.GetTile(new Vector3Int(j, i, 0))); tilemapAux.SetTile(new Vector3Int(j, i, 0), null); } } }