Пример #1
0
        private void Generate()
        {
            _max  = QuadRegion.localScale.ToVector2XY() * .5f;
            _min  = -_max;
            _size = _max - _min;

            // Inner distance is only used if DistanceFilter delegate is set (by sampling the texture distance is
            // changed from inner to outer using r channel of the texture).
            // Otherwise it's always outerDistance.
            PoissonDiskSampler sampler = new PoissonDiskSampler(Rand.Instance, _min, _max, DistOuter, DistInner);

            if (UseDistanceMap)
            {
                sampler.DistanceFilter = DistanceFactor;
                sampler.MaxPoints      = MaxPoints;
            }
            Vector2[] points = sampler.Sample().ToArray();
            Logger.LogInfo(points.Length + " points were generated");

            ParticleSystem.Particle[] particles = new ParticleSystem.Particle[points.Length];
            for (int i = 0; i < points.Length; ++i)
            {
                particles[i] = new ParticleSystem.Particle()
                {
                    position = points[i].ToVector3XY(),
                    color    = Color.blue,
                    size     = ParticleScale,
                };
            }
            Particles.SetParticles(particles, particles.Length);
        }
Пример #2
0
        /// <summary>
        /// Generate special resources on the world map
        /// </summary>
        protected void GenerateResources()
        {
            var sampler   = new PoissonDiskSampler(this.Dimensions, 6.5f);
            var rng       = new Random(this.Seed + 9118);
            var positions = sampler.Sample(rng);

            foreach (var position in positions)
            {
                if (rng.NextDouble() <= this.Parameters.ResourceSpawnChance)
                {
                    var biome = this.Biomes[position.X, position.Y];

                    if (this.HasResources(biome))
                    {
                        this.Resources.Add(position, this.SelectResource(rng, biome));
                    }
                }
            }
        }
Пример #3
0
	private void GeneratePlants(PlantBehaviour[] selectedPrefabs, List<Vector2> externalSamples) {
        PoissonDiskSampler sampler = new PoissonDiskSampler(radius, minDist);
        int sampleCount = sampler.generateSamples(delegate(Vector2 s) { return PlacePlant(s, selectedPrefabs); }, externalSamples);

        if (extraLogging) { Debug.Log("Sample count: " + sampleCount); }

        // force a single plant
        if (sampleCount == 0) {
            if (minOnePlant) {
                PlacePlant(Vector2.zero, selectedPrefabs);
            } else {
                Debug.LogError("Failed to create plants: " + name + " in " + transform.parent.name);
            }
        }
	}