Ejemplo n.º 1
0
        public TerrainChunk(TerrainChunkSettings settings, INoiseProvider noiseProvider, float seed, List <IFeatureGenerator> featureGenerator, Material material)
        {
            this.settings         = settings;
            this.noiseProvider    = noiseProvider;
            this.seed             = seed;
            this.featureGenerator = featureGenerator;
            this.material         = material;

            cube = (GameObject)Resources.Load("Cube", typeof(GameObject));
        }
        private void Awake()
        {
            settings         = new TerrainChunkSettings(129, 200, 0.1f);
            noiseProvider1   = new SeussNoise0(true);
            noiseProvider2   = new SeussNoise0(false);
            featureGenerator = new List <IFeatureGenerator>();

            seed = Random.Range(0.0f, 100000.0f);

            featureGenerator.Add(new TreePlacer(settings.length));

            CreateTerrainChunk();
        }
Ejemplo n.º 3
0
        // Use this for initialization
        public void Generate(float seed, INoiseProvider noiseProvider, TerrainChunkSettings settings)
        {
            trees = new GameObject("Trees");

            for (float i = -length / 2; i < length / 2; i += spacing)
            {
                for (float j = -length / 2; j < length / 2; j += spacing)
                {
                    if (Random.value > noiseThreshold)
                    {
                        // calculate tree position
                        float xOffset   = Random.Range(0, maxDiplacement);
                        float zOffset   = Random.Range(0, maxDiplacement);
                        float xPosition = i + xOffset;
                        float zPosition = j + zOffset;

                        if (noiseProvider.GetValue(xPosition, zPosition, seed) < 0.2f)
                        {
                            continue;
                        }

                        // find y position by choosing lowest point from 4 nearest heightmap points
                        float radius        = 0.45f;
                        float minHeight     = noiseProvider.GetValue(xPosition - radius, zPosition - radius, seed);
                        float compareHeight = noiseProvider.GetValue(xPosition - radius, zPosition + radius, seed);
                        if (compareHeight < minHeight)
                        {
                            minHeight = compareHeight;
                        }
                        compareHeight = noiseProvider.GetValue(xPosition + radius, zPosition - radius, seed);
                        if (compareHeight < minHeight)
                        {
                            minHeight = compareHeight;
                        }
                        compareHeight = noiseProvider.GetValue(xPosition + radius, zPosition + radius, seed);
                        if (compareHeight < minHeight)
                        {
                            minHeight = compareHeight;
                        }

                        // create and place tree
                        Vector3 treePosition = new Vector3(xPosition, minHeight, zPosition);
                        MonoBehaviour.Instantiate(tree, treePosition, Quaternion.identity, trees.transform);
                    }
                }
            }
        }