コード例 #1
0
        private void btnGenerateForest_Click(object sender, EventArgs e)
        {
            var fs = GetForestSpecification();

            if (fs == null)
            {
                return;
            }

            forest = ForestGenerator.Generate(fs, "^");

            var sfd = new SaveFileDialog
            {
                Filter   = "txt files (*.txt)|*.txt",
                FileName = "forest.txt"
            };

            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (string.IsNullOrEmpty(sfd.FileName))
            {
                return;
            }

            ForestGenerator.SaveForestToFile(forest, sfd.FileName, false);
        }
コード例 #2
0
    GameObject CreateForest(float[,] heightMap, Vector3[] terrainNormals)
    {
        forestGenerator.Clear();
        GameObject forestGameObject = forestGenerator.Generate(heightMap, terrainNormals, waterLevel, seed);

        forestGameObject.isStatic = true;

        return(forestGameObject);
    }
コード例 #3
0
    private void Start()
    {
        meshRenderer = gameObject.AddComponent <MeshRenderer>();
        meshFilter   = gameObject.AddComponent <MeshFilter>();
        material     = new Material(Shader.Find("Standard"));

        // Validation check to ensure terrainSize is not smaller than forestSize, as this will create an indexOutOfBounds exception.
        if (terrainSize < Forest.forestSize)
        {
            terrainSize = Forest.forestSize;
        }

        heightMap = new float[terrainSize, terrainSize];

        GenerateHeightMap();
        Generate();
        Forest.Generate(heightMap);
    }