示例#1
0
    private void DrawLine(int resolution, Action <Vector3[]> Align)
    {
        GameObject line = new GameObject("Line");

        line.transform.SetParent(transform, false);

        LineRenderer lineRenderer = line.AddComponent <LineRenderer>();

        lineRenderer.useWorldSpace  = false;
        lineRenderer.startWidth     = lineWidth;
        lineRenderer.endWidth       = lineWidth;
        lineRenderer.positionCount  = resolution;
        lineRenderer.material       = material;
        lineRenderer.numCapVertices = 5;

        int pointCount = resolution;

        Vector3[] points = new Vector3[pointCount];

        PerlinNoise noise = new PerlinNoise(initialAmplitude, amplitudeScalingFactor, initialFrequency, frequencyScalingFactor, numberOfOctaves);

        for (int i = 0; i < pointCount; i++)
        {
            float x = i * width / (pointCount - 1);
            float y = noise.GenerateNoise(x);

            points[i] = new Vector3(x, y);
        }

        Align(points);

        lineRenderer.SetPositions(points);
    }
示例#2
0
    public void GenerateMap()
    {
        float[,] noiseMap = PerlinNoise.GenerateNoise(mapChankSize, seed, Scale, octaves, persistance, lacunarity, offset);
        Color[] colorMap = new Color[mapChankSize * mapChankSize];
        for (int y = 0; y < mapChankSize; y++)
        {
            for (int x = 0; x < mapChankSize; x++)
            {
                float currentHeight = noiseMap[x, y];
                for (int i = 0; i < Regions.Length; i++)
                {
                    if (currentHeight <= Regions[i].height)
                    {
                        colorMap[y * mapChankSize + x] = Regions[i].color;
                        break;
                    }
                }
            }
        }
        MapDisplay mapDisplay = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.PerlinNoise)
        {
            mapDisplay.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap));
        }
        else if (drawMode == DrawMode.ColorMap)
        {
            mapDisplay.DrawTexture(TextureGenerator.TextureFromColorMap(colorMap, mapChankSize));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            mapDisplay.DrawMesh(MeshGeneration.GenerareTerrainMesh(noiseMap, heightMultipler, curve), TextureGenerator.TextureFromColorMap(colorMap, mapChankSize), !GenerationAllTime);
        }
    }
示例#3
0
    private void DrawCurvedSide(int resolution, Action <Vector3[]> Align)
    {
        GameObject curve = new GameObject("Curve");

        curve.transform.SetParent(transform, false);

        LineRenderer lineRenderer = curve.AddComponent <LineRenderer>();

        lineRenderer.useWorldSpace  = false;
        lineRenderer.startWidth     = lineWidth;
        lineRenderer.endWidth       = lineWidth;
        lineRenderer.positionCount  = resolution;
        lineRenderer.material       = material;
        lineRenderer.numCapVertices = 5;

        int pointCount = resolution;

        Vector3[] points = new Vector3[pointCount];

        float angle = Mathf.PI;

        PerlinNoise noise = new PerlinNoise(initialAmplitude, amplitudeScalingFactor, initialFrequency, frequencyScalingFactor, numberOfOctaves);

        for (int i = 0; i < pointCount; i++)
        {
            float section = i * angle / pointCount;
            float n       = noise.GenerateNoise(section * radius);
            float x       = Mathf.Cos(section) * (radius + n);
            float y       = Mathf.Sin(section) * (radius + n);

            points[i] = new Vector3(x, y);

            if (i == pointCount - 1)
            {
                points[i] = new Vector3(x, 0);
            }
        }

        Align(points);

        lineRenderer.SetPositions(points);
    }