コード例 #1
0
    void BuildNow(GridTile plantGrid, Vector3 plantPos)
    {
        if (isTurbine) // If we want to build a turbine...
        {
            curInstantiated.GetComponent <TurbineController>().enabled = true;
            world.AddTurbine(curInstantiated, plantPos, curInstantiated.transform.rotation, curInstantiated.GetComponent <SizeController>().desiredScale, GridTileOccupant.OccupantType.Turbine, TurbineManager.GetInstance().transform); // Let the world controller know we want to build this thing
            Renderer[] rens       = curInstantiated.GetComponentsInChildren <Renderer>();
            Renderer[] rensPrefab = curSelected.GetComponentsInChildren <Renderer>();
            int        count      = 0;
            foreach (Renderer ren in curInstantiated.GetComponentsInChildren <Renderer>())
            {
                foreach (Material mat in ren.materials)
                {
                    mat.shader = Shader.Find("Standard");
                    mat.color  = originalMaterial[count];
                    count++;
                }
            }
        }
        else
        {
            world.AddOther(curSelected, plantPos, curInstantiated.transform.rotation, curInstantiated.GetComponent <SizeController>().desiredScale, GridTileOccupant.OccupantType.Other, TerrainController.thisTerrainController.transform);
            Destroy(curInstantiated);
            WindVaneController windVaneController = curInstantiated.GetComponent <WindVaneController>();

            if (windVaneController != null)
            {
                windVaneController.enabled = true;
            }
        }
        GameResources.Buy(curInstantiated.GetComponent <PriceController>().price);
        curInstantiated = null;

        GameObject newObject = new GameObject();

        newObject.transform.parent = Camera.main.transform;
        AudioSource doefAudioSource = newObject.AddComponent <AudioSource>();

        doefAudioSource.clip = doef;
        doefAudioSource.Play();
        inBuildMode = false;
    }
コード例 #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++;
        }
    }