private bool IsFarEnough(Vector2 sample)
    {
        GridPos pos = new GridPos(sample, cellSize);

        int xmin = Mathf.Max(pos.x - 2, 0);
        int ymin = Mathf.Max(pos.y - 2, 0);
        int xmax = Mathf.Min(pos.x + 2, grid.GetLength(0) - 1);
        int ymax = Mathf.Min(pos.y + 2, grid.GetLength(1) - 1);

        //randomly modify the radius to cluster the samples
        float modRad2 = radius2 * CustomMathf.RemapValue(Mathf.PerlinNoise(sample.x + Random.seed, sample.y + Random.seed), clusterRange.x, clusterRange.y);

        for (int y = ymin; y <= ymax; y++)
        {
            for (int x = xmin; x <= xmax; x++)
            {
                Vector2 s = grid[x, y];
                if (s != Vector2.zero)
                {
                    Vector2 d = s - sample;
                    if (d.x * d.x + d.y * d.y < modRad2)
                    {
                        return(false);
                    }
                }
            }
        }

        return(true);

        // Note: we use the zero vector to denote an unfilled cell in the grid. This means that if we were
        // to randomly pick (0, 0) as a sample, it would be ignored for the purposes of proximity-testing
        // and we might end up with another sample too close from (0, 0). This is a very minor issue.
    }
    public void AttemptSpawn(Vector3 samplePoint, TerrainObjectType terrainObjectSettings, bool randomAge, bool checkSurroundings)
    {
        float viability = terrainObjectSettings.TestViability(ref samplePoint, checkSurroundings);

        if (viability <= terrainObjectSettings.viabilitySettings.minViability)
        {
            return;
        }

        float viabilityPercentage = CustomMathf.RemapValue(viability, terrainObjectSettings.viabilitySettings.minViability, 1f, true);
        float num       = !randomAge ? 0.0f : initialAgeDistribution.GetValue(Random.value) * terrainObjectSettings.dna.lifetime.minOutputValue * LevelController.Instance.yearLength;
        var   newObject = terrainObjectSettings.SpawnFoliageObject(samplePoint, Time.time - num, viabilityPercentage, reproduceAnnually);

        if (newObject.GetType() == typeof(FoliageObject))
        {
            AddFoliageObject((FoliageObject)newObject);
        }
        else
        {
            AddTerrainObject(newObject);
        }
    }
Пример #3
0
 private static float GetRandomRange(AnimationCurve smoothingCurve, float min, float max)
 {
     return(CustomMathf.RemapValue(smoothingCurve.Evaluate(Random.value), min, max, false));
 }