Example #1
0
    /// <summary>
    /// Call througt coroutine because of need for initialization of other objects before placing objects of class building.
    /// </summary>
    /// <returns></returns>
    IEnumerator InstantiateBuildings()
    {
        yield return(new WaitForEndOfFrame());

        for (int row = 0; row < height; row++)
        {
            for (int column = 0; column < widht; column++)
            {
                Cell       cell;
                Vector2Int dimension;

                switch (buildingsMap[column, row])
                {
                case 100:
                    cell      = getCell(column, row);
                    dimension = _base.GetComponent <Building>().getDimensions();
                    constructor.placeBuilding(cell, cell.CalculateConstructionPlace(dimension), _base, _base.transform.rotation, orientation.South);
                    break;

                case 200:
                    cell      = getCell(column, row);
                    dimension = _base.GetComponent <Building>().getDimensions();
                    AIconstructor.placeBuilding(cell, cell.CalculateConstructionPlace(dimension), _base, _base.transform.rotation, orientation.South);
                    break;

                case 101:
                    cell      = getCell(column, row);
                    dimension = forest.GetComponent <Building>().getDimensions();
                    constructor.placeBuilding(cell, cell.CalculateConstructionPlace(dimension), forest, forest.transform.rotation, orientation.South);
                    break;

                case 201:
                    cell      = getCell(column, row);
                    dimension = forest.GetComponent <Building>().getDimensions();
                    AIconstructor.placeBuilding(cell, cell.CalculateConstructionPlace(dimension), forest, forest.transform.rotation, orientation.South);
                    break;

                case 102:
                    cell      = getCell(column, row);
                    dimension = quarry.GetComponent <Building>().getDimensions();
                    constructor.placeBuilding(cell, cell.CalculateConstructionPlace(dimension), quarry, quarry.transform.rotation, orientation.South);
                    break;

                case 202:
                    cell      = getCell(column, row);
                    dimension = quarry.GetComponent <Building>().getDimensions();
                    AIconstructor.placeBuilding(cell, cell.CalculateConstructionPlace(dimension), quarry, quarry.transform.rotation, orientation.South);
                    break;
                }
            }
        }

        InitBases();
    }
    /// <summary>
    /// Calls the construction mode for placeing a new building based on this building params such as cell, dimension, orientation and rotation.
    /// </summary>
    public void placeBuilding()
    {
        ConstructionMode mode = gameMode.getConstructionMode() as ConstructionMode;

        mode.placeBuilding(this.cell, transform.position, prefab, transform.rotation, _orientation);
    }