Exemple #1
0
    void Initialize()
    {
        shapeGenerator.updateSettings(shapeSettings);
        colourGenerator.updateSettings(colorSettings);

        Vector3[] direcciones = new Vector3[] {
            Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back
        };

        if (meshFilters == null || meshFilters.Length == 0)
        {
            meshFilters = new MeshFilter[6];
        }


        caras = new Terrain[6];
        for (int i = 0; i < 6; i++)
        {
            if (meshFilters[i] == null)
            {
                GameObject meshObject = new GameObject("mesh");
                meshObject.transform.parent = this.transform;

                MeshRenderer meshrenderer = meshObject.AddComponent <MeshRenderer>();
                meshrenderer.sharedMaterial = colorSettings.material;
                meshFilters[i] = meshObject.AddComponent <MeshFilter>();
                Mesh mesh = new Mesh();
                meshFilters[i].sharedMesh = mesh;
                meshObject.AddComponent <MeshCollider>().sharedMesh = mesh;
            }

            TerrainConfig config = new TerrainConfig();
            config.meshBuilder    = new MeshBuilder(meshFilters[i].sharedMesh);
            config.detalle        = this.cantVertices;
            config.localUp        = direcciones[i];
            config.shapeGenerator = shapeGenerator;

            caras[i] = new Terrain(config);
        }
    }