コード例 #1
0
    void ChangeLandscape()
    {
        Color color = Color.gray;

        for (int j = 0; j < blocks.Count; j++)
        {
            int y     = CalculateHeight(j, Offset, WidthScale, HeightScale);
            int biome = CalculateHeight(j, BiomeOffset, BiomeScale, BiomeOffset1);
            blocks[j].transform.position = new Vector2(0.64f * (float)j, y * 0.64f);

            if (OqupiedBlocksCount > 0)
            {
                OqupiedBlocksCount--;
            }

            // Biomes
            if (biome <= 10)
            {
                // Standart Forest
                color = Color.magenta;
                if (j % 4 == 0)
                {
                    BlocksFunctions.MakeTree("Oak Tree", new Vector2(0.64f * (float)j, (y + 1) * 0.64f));
                }
            }
            else if (biome <= 20)
            {
                // After-forest
                if (Random.Range(0, 4) == 2 && OqupiedBlocksCount == 0)
                {
                    BlocksFunctions.CreateBlock("Grass", new Vector2(0.64f * (float)j, (y + 1) * 0.64f));
                }
                color = Color.yellow;
            }
            else if (biome <= 30)
            {
                // City
                color = Color.blue;
                if (OqupiedBlocksCount == 0 && GetPlainBlocksCount(j) >= 10)
                {
                    GameObject       Building             = Instantiate(BuildingsPrefabs[Random.Range(0, BuildingsPrefabs.Count)], new Vector2(0.64f * (float)j, (y + 1) * 0.64f), Quaternion.identity);
                    BuildingsManager BuildingInteractions = Building.GetComponent <BuildingsManager>();
                    BuildingInteractions.ChangeBlocks();
                    OqupiedBlocksCount = BuildingInteractions.Width + SpaceBetweenBuildings;
                }
            }
            else
            {
                // Roads
                color = Color.green;
                if (Random.Range(0, 5) == 2 && OqupiedBlocksCount == 0)
                {
                    BlocksFunctions.CreateBlock("Torch", new Vector2(0.64f * (float)j, (y + 1) * 0.64f));
                }
            }

            blocks[j].GetComponent <SpriteRenderer>().color = color;
        }
    }