// Creates a new Grid public void CreateGrid() { // Sync with Settings gridSize = Settings.GridSize; missingTilesPercent = Settings.MissingPercent; // Check if Settings were NULL/Zero (Mainly so that scene starts) if (gridSize < 2) { Settings.ShowAIMovement = true; } gridSize = (gridSize < 2) ? 5 : gridSize; missingTilesPercent = (missingTilesPercent < 0) ? 30 : missingTilesPercent; if (tiles != null) { // Deleting the old Grid for (int y = 0; y < tiles.GetLength(1); y++) { for (int x = 0; x < tiles.GetLength(0); x++) { // Destroying the Gameobject DestroyImmediate(tiles[x, y].gameObject); } } } // Create a new Array with new Dimensions tiles = new HexTileDisplay[gridSize, gridSize]; // Creating the new Grid for (int y = 0; y < gridSize; y++) { for (int x = 0; x < gridSize; x++) { // Calculating the Position float hexHeight = 3 * 0.5f / Mathf.Sqrt(3); Vector3 yOffset = Vector3.forward * hexHeight; Vector3 offset = Vector3.right * (y % 2) / 2; Vector3 position = transform.position + Vector3.right * x + (yOffset) * y + offset; // Creating a new Instance GameObject newInstance = Instantiate(HexTile, position, Quaternion.identity, transform); // Renaming newInstance.name = "HexTile " + x + "/" + y; // Reference to HexTile Script HexTileDisplay newHexTile = newInstance.GetComponent <HexTileDisplay>(); // Putting it into the Array tiles[x, y] = newHexTile; } } // Adding Neighbours for (int y = 0; y < gridSize; y++) { for (int x = 0; x < gridSize; x++) { AddNeighboursToTile(tiles[x, y], x, y); } } }
public Color SetFontColor(HexTileDisplay tile) { if (!tile.isVisible()) { return(emptyFont); } if (tile.selected || tile.highlighted) { switch (tile.team) { case GameManager.Teams.Gold: return(goldSelectedFont); case GameManager.Teams.Blue: return(blueSelectedFont); default: return(emptyFont); } } else { switch (tile.team) { case GameManager.Teams.Gold: return(goldFont); case GameManager.Teams.Blue: return(blueFont); default: return(emptyFont); } } }
// Adds all the neighbour Tiles to a new Tile public void AddNeighboursToTile(HexTileDisplay tile, int x, int y) { if (y % 2 == 0) { if (x - 1 >= 0) { tile.neighbourTiles.Add(tiles[x - 1, y]); } if (x + 1 < gridSize) { tile.neighbourTiles.Add(tiles[x + 1, y]); } if (x - 1 >= 0 && y + 1 < gridSize) { tile.neighbourTiles.Add(tiles[x - 1, y + 1]); } if (x - 1 >= 0 && y - 1 >= 0) { tile.neighbourTiles.Add(tiles[x - 1, y - 1]); } if (y + 1 < gridSize) { tile.neighbourTiles.Add(tiles[x, y + 1]); } if (y - 1 >= 0) { tile.neighbourTiles.Add(tiles[x, y - 1]); } } else { if (x - 1 >= 0) { tile.neighbourTiles.Add(tiles[x - 1, y]); } if (x + 1 < gridSize) { tile.neighbourTiles.Add(tiles[x + 1, y]); } if (x + 1 < gridSize && y + 1 < gridSize) { tile.neighbourTiles.Add(tiles[x + 1, y + 1]); } if (x + 1 < gridSize && y - 1 >= 0) { tile.neighbourTiles.Add(tiles[x + 1, y - 1]); } if (y + 1 < gridSize) { tile.neighbourTiles.Add(tiles[x, y + 1]); } if (y - 1 >= 0) { tile.neighbourTiles.Add(tiles[x, y - 1]); } } }
public Color SetColor(HexTileDisplay tile) { if (!tile.isVisible()) { if (tile.selected) { return(emptySelected); } if (tile.highlighted) { return(emptyHighlighted); } return(emptyNormal); } switch (tile.team) { case GameManager.Teams.Gold: if (tile.selected) { return(goldSelected); } if (tile.highlighted) { return(goldHighlighted); } return(goldNormal); case GameManager.Teams.Blue: if (tile.selected) { return(blueSelected); } if (tile.highlighted) { return(blueHighlighted); } return(blueNormal); default: if (tile.selected) { return(emptySelected); } if (tile.highlighted) { return(emptyHighlighted); } return(emptyNormal); } }
// Use this for initialization void Start() { hexDisplay = GetComponent <HexTileDisplay>(); movementsFromTile = new List <Movement>(); }