Example #1
0
        private void Export3D()
        {
            Texture3D texture = null;

            try
            {
                string path = EditorUtility.SaveFilePanel("Export Noise To Texture3D",
                                                          Application.dataPath,
                                                          "New Noise Texture3D.asset",
                                                          "asset");

                if (!path.StartsWith(Application.dataPath))
                {
                    Debug.LogError("You must specificy a path in your project's Assets folder to export a Noise Texture");
                }

                if (!string.IsNullOrEmpty(path) && path.StartsWith(Application.dataPath))
                {
                    EditorUtility.DisplayProgressBar("Exporting Noise to Texture3D", "Making some noise...", 0.1f);

                    texture = NoiseUtils.BakeToTexture3D(m_noise, dims3D.x, dims3D.y, dims3D.z, m_format, TextureCreationFlags.None);

                    AssetDatabase.CreateAsset(texture, path.Remove(0, Application.dataPath.Length - "Assets".Length));

                    AssetDatabase.Refresh();

                    EditorUtility.ClearProgressBar();

                    EditorGUIUtility.PingObject(texture);
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);

                if (texture != null)
                {
                    Texture2D.DestroyImmediate(texture);
                }

                EditorUtility.ClearProgressBar();
            }
        }