示例#1
0
    private void CreateTexture(bool isPreview)
    {
        if (isPreview)
        {
            DestroyPreviewTexture();
        }

        Texture2D texture = new Texture2D(noiseSettings.resolution.x, noiseSettings.resolution.y, TextureFormat.Alpha8, false);

        texture.wrapMode = TextureWrapMode.Clamp;

        Stopwatch sw = new Stopwatch();

        sw.Start();

        PerlinNoise.FillTextureWithPerlin2D(texture, noiseSettings);

        sw.Stop();

        if (!isPreview)
        {
            string prefix = "Noise texture created in Assets folder.";
            Debug.LogFormat("{0} Texture filling took: {1} milliseconds", prefix, sw.ElapsedMilliseconds);
        }

        if (isPreview)
        {
            previewTexture = texture;
        }
        else
        {
            bool removed = AssetDatabase.DeleteAsset("Assets/PerlinNoise.asset");
            if (removed)
            {
                Debug.Log("Asset deleted at: Assets/PerlinNoise.asset. A new asset has been created. Rename or move it if you wish to keep several perlin noise texture assets.");
            }

            AssetDatabase.CreateAsset(texture, "Assets/PerlinNoise.asset");
        }
    }