Exemplo n.º 1
0
    void UpgradeBuilding()
    {
        if (curBuildings.Count == 0)
        {
            return;
        }

        int index = RouletteSelection();
        CityBuildingManager upgBuilding = curBuildings[index];

        curBuildings.RemoveAt(index);
        upgBuilding.Upgrade();
        curBuildings.Add(upgBuilding);
    }
Exemplo n.º 2
0
    void BuildBuilding(GridTile tile)
    {
        // Pick a type of building randomly
        CityObject buildObject = buildings[rand.Next(0, buildings.Length)];


        float diameter = buildObject.prefabs[0].GetComponent <SizeController>().diameter;

        // Rotation quaternion for the building orientation
        Quaternion rotation;

        // List of possible orientations
        float[] possibleOrientations = { 0, 90, 180, 270 };

        // Get an angle from the possible orientation
        float angle = possibleOrientations[rand.Next(0, possibleOrientations.Length)];

        // Make a maximum of 10 degrees offset from the cardinal direction (purely for making it more visibly appealing)
        //angle += (float)rand.NextDouble() * 10;

        // Create the rotation quaternion
        rotation = Quaternion.AngleAxis(angle, Vector3.up);
        if (world.CanBuild(tile.position, diameter, buildObject.prefabs[0], buildObject.scale, rotation, true))
        {
            GameObject parentObj = new GameObject();
            parentObj.transform.parent = transform;
            CityBuildingManager parentController = parentObj.AddComponent <CityBuildingManager>();
            parentController.cityObject = buildObject;
            // Place the building
            GameObject cityObj = world.AddOther(buildObject.prefabs[0], tile.position + Vector3.down * 0.1f, rotation, buildObject.scale, GridTileOccupant.OccupantType.City, parentObj.transform);
            parentController.curObject = cityObj;

            curBuildings.Add(parentController);

            currentPlacedHouses++;
        }
    }