示例#1
0
    // generates the color of the terrain depending on height. Will also create monument valley-like mountains/vulcanos
    // Additionaly, spawns the waypoints at the right pos, and give it the proper height value and make sure if its walkable
    void GenerateTerrain()
    {
        Texture2D _texture = new Texture2D(width, length);

        _texture.wrapMode = TextureWrapMode.Clamp;

        Color[] colors = new Color[width * length];
        for (int w = 0; w < width; w++)
        {
            for (int l = 0; l < length; l++)
            {
                GameObject WP = Instantiate(wayPoint, new Vector3(), Quaternion.identity) as GameObject;
                if (noise[l, w] < 0.1)
                {
                    colors[w * length + l] = Color.red; // vulcano
                    float lavaHeight = 0.1f;
                    noise[l, w] = lavaHeight;
                }
                else if (noise[l, w] < 0.2)
                {
                    colors[w * length + l] = Color.gray; //mountain
                    float reverseValue = 0.2f - noise[l, w];
                    noise[l, w] = reverseValue;
                }
                // this part is added to make sure the edge of the mountains is also unwalkable. prevents the character from moving through the base of the wall
                else if (noise[l, w] < 0.21)
                {
                    colors[w * length + l] = new Color(0.5f, 0.2f, 0.2f); // brownish desert like
                }
                else if (noise[l, w] < 0.7)
                {
                    colors[w * length + l] = new Color(0.5f, 0.2f, 0.2f); // brownish desert like
                    WP.GetComponent <Waypoint>().walkable = true;
                }
                else if (noise[l, w] <= 0.9)
                {
                    colors[w * length + l] = new Color(0.9f, 0.8f, 0.2f);  // sand
                    WP.GetComponent <Waypoint>().walkable = true;
                }
                else
                {
                    colors[w * length + l] = Color.blue; //water
                    noise[l, w]            = 0.9f;
                }
                WP.transform.position       = new Vector3(l, -noise[l, w] * heightScale, w);
                GameManager.waypoints[l, w] = WP; // add the waypoint to the waypoint array
            }
        }
        _texture.SetPixels(colors);
        _texture.Apply();

        DrawPolygon(MeshGeneration.Generate(noise, heightScale), _texture);

        SpawnObjects();
    }
示例#2
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        MeshGeneration myScript = (MeshGeneration)target;

        usingHeightMap = EditorGUILayout.Toggle("Using HeightMap", usingHeightMap);

        if (GUILayout.Button("Build Mesh"))
        {
            //myScript.CreateNewMesh();
            myScript.Generate(usingHeightMap);
        }
    }