/*private void Update()
     * {
     *  if (Input.GetKeyDown("space"))
     *  {
     *      DeleteCity();
     *      LoadBuildingsWithRectanglePlots();
     *      UpdateHeight();
     *  }
     * }*/
    public void LoadBuildingsWithRectanglePlots()
    {
        GameObject baseSpawnPoint = new GameObject("CitySpawn");

        baseSpawnPoint.transform.SetParent(citySpawnPoint.transform);
        baseSpawnPoint.transform.localPosition = Vector3.zero;
        List <RectInt> plots = GetComponent <CityPlotGenerator>().createPlots();

        foreach (RectInt plot in plots)
        {
            GameObject buildingSpawnPoint = new GameObject("BuildingSpawn");
            buildingSpawnPoint.transform.SetParent(baseSpawnPoint.transform);
            BuildingSettings s = buildingSettings[Random.Range(0, buildingSettings.Length)];
            int width          = Mathf.Min(Mathf.Clamp(plot.width / pieceSize - siteOffset, 1, 1000), maxDim);
            int height         = Mathf.Min(Mathf.Clamp(plot.height / pieceSize - siteOffset, 1, 1000), maxDim);

            s.SetSize(new Vector2Int(width, height));
            LoadBuilding(buildingSpawnPoint, s);
            int xpos = plot.x + plot.width - Random.Range(0, siteOffset) * pieceSize;
            int zpos = plot.y + plot.height - Random.Range(0, siteOffset) * pieceSize;


            buildingSpawnPoint.transform.localPosition = new Vector3(xpos, 0, zpos);
            buildingSpawnPoint.transform.rotation      = Quaternion.Euler(0, Random.Range(0f, RotationJitter), 0);
        }
    }
Beispiel #2
0
 public void SetSize(Vector2Int size)
 {
     settings.SetSize(size);
 }