private BasicTile CreateNewTile(Object tile, TeamsInfo.Colour colour, int col, int row) { //Create the new tile, give it proper name and position. GameObject newTileGO = Instantiate(tile) as GameObject; BasicTile newTile = newTileGO.GetComponent("BasicTile") as BasicTile; newTile.transform.position = GetWorldPosition(col, row); newTile.transform.parent = gameObject.transform; newTile.gameObject.name = "Tile(" + col + "," + row + ")" + newTile.tag; newTile.Collumn = col; newTile.Row = row; newTile.Colour = colour; return(newTile); }
private void ChangeTileToType(TileInfo newTileInfo, TeamsInfo.Colour newColour, int col, int row) { TileInfo oldTileInfo = TileTypes.GetTileInfo(_boardScript.BoardTiles[col, row].tag); TeamsInfo.Colour oldColour = _boardScript.BoardTiles[col, row].Colour; if (oldTileInfo.Number == newTileInfo.Number && oldColour == newColour) { return; } else if (oldTileInfo.Number == newTileInfo.Number && oldColour != newColour) { _boardScript.BoardTiles[col, row].Colour = newColour; } else { Destroy(_boardScript.BoardTiles[col, row].gameObject); _boardScript.BoardTiles[col, row] = CreateNewTileOfType(newTileInfo, newColour, col, row); //Play Sound SoundManager.PlayEditorTileChange(); } }
private void SetRenderersFor(TeamsInfo.Colour colour) { switch (colour) { case TeamsInfo.Colour.Neutral: EnableRenderers(_neutralRenderers); DisableRenderers(_blackRenderers); DisableRenderers(_blueRenderers); DisableRenderers(_greenRenderers); DisableRenderers(_redRenderers); DisableRenderers(_whiteRenderers); DisableRenderers(_yellowRenderers); break; case TeamsInfo.Colour.Black: DisableRenderers(_neutralRenderers); EnableRenderers(_blackRenderers); DisableRenderers(_blueRenderers); DisableRenderers(_greenRenderers); DisableRenderers(_redRenderers); DisableRenderers(_whiteRenderers); DisableRenderers(_yellowRenderers); break; case TeamsInfo.Colour.Blue: DisableRenderers(_neutralRenderers); DisableRenderers(_blackRenderers); EnableRenderers(_blueRenderers); DisableRenderers(_greenRenderers); DisableRenderers(_redRenderers); DisableRenderers(_whiteRenderers); DisableRenderers(_yellowRenderers); break; case TeamsInfo.Colour.Green: DisableRenderers(_neutralRenderers); DisableRenderers(_blackRenderers); DisableRenderers(_blueRenderers); EnableRenderers(_greenRenderers); DisableRenderers(_redRenderers); DisableRenderers(_whiteRenderers); DisableRenderers(_yellowRenderers); break; case TeamsInfo.Colour.Red: DisableRenderers(_neutralRenderers); DisableRenderers(_blackRenderers); DisableRenderers(_blueRenderers); DisableRenderers(_greenRenderers); EnableRenderers(_redRenderers); DisableRenderers(_whiteRenderers); DisableRenderers(_yellowRenderers); break; case TeamsInfo.Colour.White: DisableRenderers(_neutralRenderers); DisableRenderers(_blackRenderers); DisableRenderers(_blueRenderers); DisableRenderers(_greenRenderers); DisableRenderers(_redRenderers); EnableRenderers(_whiteRenderers); DisableRenderers(_yellowRenderers); break; case TeamsInfo.Colour.Yellow: DisableRenderers(_neutralRenderers); DisableRenderers(_blackRenderers); DisableRenderers(_blueRenderers); DisableRenderers(_greenRenderers); DisableRenderers(_redRenderers); DisableRenderers(_whiteRenderers); EnableRenderers(_yellowRenderers); break; } }
private BasicTile CreateNewTileOfType(TileInfo tileinfo, TeamsInfo.Colour colour, int col, int row) { Object tile = LoadTileOfType(tileinfo); return(CreateNewTile(tile, colour, col, row)); }
void ChangeBoardSize(int newNumCols, int newNumRows, int dir, TileInfo tileInfo) { // 0=UL 1=UM 2=UR // 3=L 4=M 5=R // 6=LL 7=LM 8=LR //Check if there is a resizing if (newNumCols == _boardScript.GetNumberOfColumns() && newNumRows == _boardScript.GetNumberOfRows()) { return; } //Backup the old array BasicTile[,] backupArr = (BasicTile[, ])_boardScript.BoardTiles.Clone(); //Set begin position for copy depending on the direction // COLUMNS // int beginColNew; int beginColBackup; if (newNumCols == _boardScript.GetNumberOfColumns()) { beginColNew = 0; beginColBackup = 0; } else if (newNumCols > _boardScript.GetNumberOfColumns()) { if (dir == 0 || dir == 3 || dir == 6) { beginColNew = 0; } else if (dir == 1 || dir == 4 || dir == 7) { beginColNew = (newNumCols - _boardScript.GetNumberOfColumns()) / 2; } else { beginColNew = newNumCols - _boardScript.GetNumberOfColumns(); } beginColBackup = 0; } else { if (dir == 0 || dir == 3 || dir == 6) { beginColBackup = 0; } else if (dir == 1 || dir == 4 || dir == 7) { beginColBackup = (_boardScript.GetNumberOfColumns() - newNumCols) / 2; } else { beginColBackup = _boardScript.GetNumberOfColumns() - newNumCols; } beginColNew = 0; } // ROWS // int beginRowNew; int beginRowBackup; if (newNumRows == _boardScript.GetNumberOfRows()) { beginRowNew = 0; beginRowBackup = 0; } else if (newNumRows > _boardScript.GetNumberOfRows()) { if (dir == 6 || dir == 7 || dir == 8) // || newNumRows <= _boardScript.GetNumberOfRows()) { beginRowNew = 0; } else if (dir == 3 || dir == 4 || dir == 5) { beginRowNew = (newNumRows - _boardScript.GetNumberOfRows()) / 2; } else { beginRowNew = newNumRows - _boardScript.GetNumberOfRows(); } beginRowBackup = 0; } else { if (dir == 6 || dir == 7 || dir == 8) // || newNumRows <= _boardScript.GetNumberOfRows()) { beginRowBackup = 0; } else if (dir == 3 || dir == 4 || dir == 5) { beginRowBackup = (_boardScript.GetNumberOfRows() - newNumRows) / 2; } else { beginRowBackup = _boardScript.GetNumberOfRows() - newNumRows; } beginRowNew = 0; } //Create the new board CreateNewBoard(newNumCols, newNumRows, tileInfo); //To copy (when reducing size) int colsToCopy = Mathf.Min(backupArr.GetLength(0), newNumCols); int rowsToCopy = Mathf.Min(backupArr.GetLength(1), newNumRows);; //Copy backup into new with proper begin position for (int col = 0; col < colsToCopy; ++col) { for (int row = 0; row < rowsToCopy; ++row) { TileInfo oldTileInfo = TileTypes.GetTileInfo(backupArr[beginColBackup + col, beginRowBackup + row].tag); TeamsInfo.Colour oldColour = backupArr[beginColBackup + col, beginRowBackup + row].Colour; ChangeTileToType(oldTileInfo, oldColour, beginColNew + col, beginRowNew + row); } } }
void DrawTerrainAndBuildingsGUI(int WindowID) { // //Draw Buttons and catch the button on which is pressed in these new ints int terrainListEntry = -1; int buildingsListEntry = -1; //Terrain GUI.Label(new Rect(10, 20, 200, 20), "Terrain"); terrainListEntry = GUI.SelectionGrid(new Rect(10, 40, 200, 160), -1, TileTypes.TerrainGUIContentList, 3); //Buildings GUI.Label(new Rect(10, 210, 200, 20), "Buildings"); _selectedBuildingsColour = (TeamsInfo.Colour)GUI.SelectionGrid(new Rect(10, 230, 200, 20), (int)_selectedBuildingsColour, TeamsInfo.ColourGUIContentList, 7); buildingsListEntry = GUI.SelectionGrid(new Rect(10, 260, 200, 80), -1, TileTypes.BuildingsGUIContentList, 3); // //See if any button was hit this time if (terrainListEntry != -1 || buildingsListEntry != -1) { //If left button was pressed if (Event.current.button == 0) //LEFT { //Convert terrain id to list id int id = TileTypes.TerrainIDToListID(terrainListEntry); //See if it is a proper ListID if (id >= 0) { //Set the left type _leftType = TileTypes.GetTileInfo(id); } //If it is not a proper listID try the same for buildingsListEntry else { id = TileTypes.BuildingsIDToListID(buildingsListEntry); if (id >= 0) { _leftType = TileTypes.GetTileInfo(id); } } //Remember id to be able to draw the mouse icons. _leftListEntry = id; } //And the same for the right button else if (Event.current.button == 1) //RIGHT { int id = TileTypes.TerrainIDToListID(terrainListEntry); if (id >= 0) { _rightType = TileTypes.GetTileInfo(id); } else { id = TileTypes.BuildingsIDToListID(buildingsListEntry); if (id >= 0) { _rightType = TileTypes.GetTileInfo(id); } } //Remember id to be able to draw the mouse icons. _rightListEntry = id; } } // //Draw the mouse icons on the correct button //------------------------------------------------------------------------------------ Rect leftPos = new Rect(0, 0, 11, 14), rightPos = new Rect(0, 0, 11, 14); //Calculate the x-positions int step = 68; int offset = -6; if (_leftListEntry < TileTypes.NumberOfTerrainTypes()) { leftPos.x = (_leftListEntry % 3 + 1) * step + offset; } else { leftPos.x = ((_leftListEntry - TileTypes.NumberOfTerrainTypes()) % 3 + 1) * step + offset; } if (_rightListEntry < TileTypes.NumberOfTerrainTypes()) { rightPos.x = (_rightListEntry % 3 + 1) * step + offset; } else { rightPos.x = ((_rightListEntry - TileTypes.NumberOfTerrainTypes()) % 3 + 1) * step + offset; } //Now calculate the y-positions int stepY = 41; int buildingsY = 220; int extraY = 3; int rightExtraY = 16; if (_leftListEntry < TileTypes.NumberOfTerrainTypes()) { leftPos.y = (_leftListEntry / 3 + 1) * stepY + extraY; } else { leftPos.y = ((_leftListEntry - TileTypes.NumberOfTerrainTypes()) / 3 + 1) * stepY + buildingsY + extraY; } if (_rightListEntry < TileTypes.NumberOfTerrainTypes()) { rightPos.y = (_rightListEntry / 3 + 1) * stepY + rightExtraY + extraY; } else { rightPos.y = ((_rightListEntry - TileTypes.NumberOfTerrainTypes()) / 3 + 1) * stepY + buildingsY + rightExtraY + extraY; } //Draw Left GUI.DrawTexture(leftPos, _mouseLeft); //Draw Right GUI.DrawTexture(rightPos, _mouseRight); DrawGUIWindowCloseButton(ref _drawTerrainAndBuildingsWindow); GUI.DragWindow(new Rect(0, 0, 10000, 20)); }