public void CreateTiles(GameObject newCreator, Vector2 startLocation, Card.CastShape shape, int range, Color color, string[] avoidTag, int layer = 0) { //if (!committed) //{ creator = newCreator; InstantiateTiles(startLocation, shape, range, color, avoidTag, layer); RefreshTiles(layer); //} }
private void InstantiateTiles(Vector2 startLocation, Card.CastShape shape, int range, Color color, string[] avoidTag, int layer) { if (range >= 0) { //if there is an object that needs to be avoided, don't create a tile here if (!GridController.gridController.CheckIfOutOfBounds(startLocation) && !Array.Exists(avoidTag, element => element == "None") && GridController.gridController.GetObjectAtLocation(startLocation).Count != 0) { if (GridController.gridController.GetObjectAtLocation(startLocation).Any(x => avoidTag.Contains(x.tag)) && !creator.GetComponent <HealthController>().GetOccupiedSpaces().Any(x => x + (Vector2)creator.transform.position == startLocation)) //Always ignore creator for blocking { return; } } if (shape == Card.CastShape.Circle) { // if this location doesn't have a tile yet or this is a better rout and it's still in bounds, create tile and recurse if ((!tilePositions[layer].ContainsKey(startLocation) || range > tilePositions[layer][startLocation]) && !GridController.gridController.CheckIfOutOfBounds(startLocation)) { Tile tile = ScriptableObject.CreateInstance <Tile>(); tiles[layer][startLocation] = tile; tilePositions[layer][startLocation] = range; tile.color = color; tileMap[layer].SetTile(Vector3Int.RoundToInt(startLocation), tile); int x = (int)startLocation.x; int y = (int)startLocation.y; InstantiateTiles(new Vector2(x - 1, y), shape, range - 1, color, avoidTag, layer); InstantiateTiles(new Vector2(x + 1, y), shape, range - 1, color, avoidTag, layer); InstantiateTiles(new Vector2(x, y - 1), shape, range - 1, color, avoidTag, layer); InstantiateTiles(new Vector2(x, y + 1), shape, range - 1, color, avoidTag, layer); } } else if (shape == Card.CastShape.Plus) { for (int i = 1; i < range + 1; i++) { if (!GridController.gridController.CheckIfOutOfBounds(startLocation + Vector2.right * i)) { Tile tile1 = ScriptableObject.CreateInstance <Tile>(); tiles[layer][startLocation + Vector2.right * i] = tile1; tilePositions[layer][startLocation + Vector2.right * i] = range; tile1.color = color; tileMap[layer].SetTile(Vector3Int.RoundToInt(startLocation + Vector2.right * i), tile1); } if (!GridController.gridController.CheckIfOutOfBounds(startLocation + Vector2.left * i)) { Tile tile2 = ScriptableObject.CreateInstance <Tile>(); tiles[layer][startLocation + Vector2.left * i] = tile2; tilePositions[layer][startLocation + Vector2.left * i] = range; tile2.color = color; tileMap[layer].SetTile(Vector3Int.RoundToInt(startLocation + Vector2.left * i), tile2); } if (!GridController.gridController.CheckIfOutOfBounds(startLocation + Vector2.up * i)) { Tile tile3 = ScriptableObject.CreateInstance <Tile>(); tiles[layer][startLocation + Vector2.up * i] = tile3; tilePositions[layer][startLocation + Vector2.up * i] = range; tile3.color = color; tileMap[layer].SetTile(Vector3Int.RoundToInt(startLocation + Vector2.up * i), tile3); } if (!GridController.gridController.CheckIfOutOfBounds(startLocation + Vector2.down * i)) { Tile tile4 = ScriptableObject.CreateInstance <Tile>(); tiles[layer][startLocation + Vector2.down * i] = tile4; tilePositions[layer][startLocation + Vector2.down * i] = range; tile4.color = color; tileMap[layer].SetTile(Vector3Int.RoundToInt(startLocation + Vector2.down * i), tile4); } } } } }
public void CreateTiles(GameObject newCreator, Vector2 startLocation, Card.CastShape shape, int range, Color color, int layer = 0) { CreateTiles(newCreator, startLocation, shape, range, color, new string[] { "None" }, layer); }