Exemple #1
0
    // ********************************************************************** //

    void Initialize(bool reset = false)
    {
        shapeGenerator.UpdateSettings(shapeSettings, reset, shapeSampleStats);
        colourGenerator.UpdateSettings(colourSettings, reset, colourSampleStats);
        tintColor   = colourGenerator.GetTintColor();
        colourLevel = colourGenerator.GetColourLevel();
        saturation  = colourGenerator.GetSaturation();
        particleLauncher.UpdateSettings(tintColor, reset, particleSampleStats);

        // only create new meshFilters when you need them
        if (meshFilters == null || meshFilters.Length == 0)
        {
            meshFilters = new MeshFilter[cubeFaces];
        }
        terrainFaces = new TerrainFace[cubeFaces];

        Vector3[] directions = { Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back };  // one for each of the cube faces

        for (int i = 0; i < cubeFaces; i++)
        {
            if (meshFilters[i] == null)
            {
                GameObject meshObj = new GameObject("mesh");
                meshObj.transform.parent = transform;

                meshObj.AddComponent <MeshRenderer>();
                meshFilters[i]            = meshObj.AddComponent <MeshFilter>();
                meshFilters[i].sharedMesh = new Mesh();
            }

            meshFilters[i].GetComponent <MeshRenderer>().sharedMaterial = colourSettings.planetMaterial;

            terrainFaces[i] = new TerrainFace(shapeGenerator, meshFilters[i].sharedMesh, resolution, directions[i]);
        }
    }