void CreateTile(CellGrid.Cell cell, TILE_TYPE tileType, TileConnector parentConnector = null) { ZUtils.RandomizeList <Tile>(ref _baseTileSet); Tile newTile = null; if (tileType == TILE_TYPE.START) { newTile = FindStartTile(); } else if (tileType == TILE_TYPE.CONNECTION) { newTile = FindConnectionTile(cell); } else if (tileType == TILE_TYPE.CONNECTION_FILLER) { newTile = FindConnectionTileToFill(cell); } else if (tileType == TILE_TYPE.END) { newTile = FindEndTile(parentConnector); _endTile = _endTile; } else if (tileType == TILE_TYPE.DEAD_END) { newTile = FindDeadEndTile(parentConnector); } if (newTile == null) { // No valid option right now, move to next step return; } GameObject newTileGO = Instantiate(newTile.gameObject); Transform newTileT = newTileGO.transform; newTileT.SetParent(_dungeonT); newTileT.position = cell.Position; newTile = newTileGO.GetComponent <Tile>(); if (parentConnector != null) { TileConnector childConnector = newTile.GetOppositeConnector(parentConnector.direction); if (childConnector != null) { TileConnector.Connect(childConnector, parentConnector); } else { Debug.Log("Error: Unable to find a connector so skipping"); return; } } newTile.Init(cell, _cellGrid); if (AllowNewConnections(tileType)) { // Add free connections List <TileConnector> freeConnectionList = newTile.GetFreeConnections(); for (int i = 0; i < freeConnectionList.Count; ++i) { _listOfFreeConnections.Add(freeConnectionList[i]); } } // Reiterate free connection list for new blockers for (int i = 0; i < _listOfFreeConnections.Count; ++i) { _listOfFreeConnections[i].UpdateBasedOnGrd(_cellGrid); if (!_listOfFreeConnections[i].IsFree()) { _listOfFreeConnections[i].SetToInvalid(); _listOfFreeConnections.RemoveAt(i); --i; } } _dungeonTiles.Add(newTile); _cellObjectList.Add(newTileGO); _numTilesCreated++; if (tileType == TILE_TYPE.START) { _startTile = newTile; } else if (tileType == TILE_TYPE.END) { _endTile = newTile; } //Debug.Log("GenNextTile: " + _numCellsCreated.ToString() + " " + _listOfFreeConnections.Count.ToString()); }
public List <TileConnector> GetFreeConnections() { ZUtils.RandomizeList <TileConnector>(ref _listOfFreeConnections); return(_listOfFreeConnections); }