BakeReflectionProbe() private method

private BakeReflectionProbe ( ReflectionProbe probe, string path ) : bool
probe UnityEngine.ReflectionProbe
path string
return bool
        private void BakeCustomReflectionProbe(ReflectionProbe probe, bool usePreviousAssetPath)
        {
            string path = "";

            if (usePreviousAssetPath)
            {
                path = AssetDatabase.GetAssetPath(probe.customBakedTexture);
            }

            string targetExtension = probe.hdr ? "exr" : "png";

            if (string.IsNullOrEmpty(path) || Path.GetExtension(path) != "." + targetExtension)
            {
                // We use the path of the active scene as the target path
                string targetPath = FileUtil.GetPathWithoutExtension(SceneManager.GetActiveScene().path);
                if (string.IsNullOrEmpty(targetPath))
                {
                    targetPath = "Assets";
                }
                else if (Directory.Exists(targetPath) == false)
                {
                    Directory.CreateDirectory(targetPath);
                }

                string fileName = probe.name + (probe.hdr ? "-reflectionHDR" : "-reflection") + "." + targetExtension;
                fileName = Path.GetFileNameWithoutExtension(AssetDatabase.GenerateUniqueAssetPath(Path.Combine(targetPath, fileName)));

                path = EditorUtility.SaveFilePanelInProject("Save reflection probe's cubemap.", fileName, targetExtension, "", targetPath);
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                ReflectionProbe collidingProbe;
                if (IsCollidingWithOtherProbes(path, probe, out collidingProbe))
                {
                    if (!EditorUtility.DisplayDialog("Cubemap is used by other reflection probe",
                                                     string.Format("'{0}' path is used by the game object '{1}', do you really want to overwrite it?",
                                                                   path, collidingProbe.name), "Yes", "No"))
                    {
                        return;
                    }
                }
            }

            EditorUtility.DisplayProgressBar("Reflection Probes", "Baking " + path, 0.5f);
            if (!Lightmapping.BakeReflectionProbe(probe, path))
            {
                Debug.LogError("Failed to bake reflection probe to " + path);
            }
            EditorUtility.ClearProgressBar();
        }
        private void BakeCustomReflectionProbe(ReflectionProbe probe, bool usePreviousAssetPath)
        {
            string text = "";

            if (usePreviousAssetPath)
            {
                text = AssetDatabase.GetAssetPath(probe.customBakedTexture);
            }
            string text2 = (!probe.hdr) ? "png" : "exr";

            if (string.IsNullOrEmpty(text) || Path.GetExtension(text) != "." + text2)
            {
                string text3 = FileUtil.GetPathWithoutExtension(SceneManager.GetActiveScene().path);
                if (string.IsNullOrEmpty(text3))
                {
                    text3 = "Assets";
                }
                else if (!Directory.Exists(text3))
                {
                    Directory.CreateDirectory(text3);
                }
                string text4 = probe.name + ((!probe.hdr) ? "-reflection" : "-reflectionHDR") + "." + text2;
                text4 = Path.GetFileNameWithoutExtension(AssetDatabase.GenerateUniqueAssetPath(Path.Combine(text3, text4)));
                text  = EditorUtility.SaveFilePanelInProject("Save reflection probe's cubemap.", text4, text2, "", text3);
                if (string.IsNullOrEmpty(text))
                {
                    return;
                }
                ReflectionProbe reflectionProbe;
                if (this.IsCollidingWithOtherProbes(text, probe, out reflectionProbe))
                {
                    if (!EditorUtility.DisplayDialog("Cubemap is used by other reflection probe", string.Format("'{0}' path is used by the game object '{1}', do you really want to overwrite it?", text, reflectionProbe.name), "Yes", "No"))
                    {
                        return;
                    }
                }
            }
            EditorUtility.DisplayProgressBar("Reflection Probes", "Baking " + text, 0.5f);
            if (!Lightmapping.BakeReflectionProbe(probe, text))
            {
                Debug.LogError("Failed to bake reflection probe to " + text);
            }
            EditorUtility.ClearProgressBar();
        }
Exemplo n.º 3
0
        private void BakeCustomReflectionProbe(ReflectionProbe probe, bool usePreviousAssetPath)
        {
            string assetPath = string.Empty;

            if (usePreviousAssetPath)
            {
                assetPath = AssetDatabase.GetAssetPath(probe.customBakedTexture);
            }
            string extension = !probe.hdr ? "png" : "exr";

            if (string.IsNullOrEmpty(assetPath) || (Path.GetExtension(assetPath) != ("." + extension)))
            {
                ReflectionProbe probe2;
                string          pathWithoutExtension = FileUtil.GetPathWithoutExtension(EditorApplication.currentScene);
                if (string.IsNullOrEmpty(pathWithoutExtension))
                {
                    pathWithoutExtension = "Assets";
                }
                else if (!Directory.Exists(pathWithoutExtension))
                {
                    Directory.CreateDirectory(pathWithoutExtension);
                }
                string fileNameWithoutExtension = probe.name + (!probe.hdr ? "-reflection" : "-reflectionHDR") + "." + extension;
                fileNameWithoutExtension = Path.GetFileNameWithoutExtension(AssetDatabase.GenerateUniqueAssetPath(Path.Combine(pathWithoutExtension, fileNameWithoutExtension)));
                assetPath = EditorUtility.SaveFilePanelInProject("Save reflection probe's cubemap.", fileNameWithoutExtension, extension, string.Empty, pathWithoutExtension);
                if (string.IsNullOrEmpty(assetPath))
                {
                    return;
                }
                if (this.IsCollidingWithOtherProbes(assetPath, probe, out probe2) && !EditorUtility.DisplayDialog("Cubemap is used by other reflection probe", string.Format("'{0}' path is used by the game object '{1}', do you really want to overwrite it?", assetPath, probe2.name), "Yes", "No"))
                {
                    return;
                }
            }
            EditorUtility.DisplayProgressBar("Reflection Probes", "Baking " + assetPath, 0.5f);
            if (!Lightmapping.BakeReflectionProbe(probe, assetPath))
            {
                Debug.LogError("Failed to bake reflection probe to " + assetPath);
            }
            EditorUtility.ClearProgressBar();
        }
        private void BakeCustomReflectionProbe(ReflectionProbe probe, bool usePreviousAssetPath)
        {
            string text = string.Empty;

            if (usePreviousAssetPath)
            {
                text = AssetDatabase.GetAssetPath(probe.customBakedTexture);
            }
            string text2 = (!probe.hdr) ? "png" : "exr";

            if (string.IsNullOrEmpty(text) || Path.GetExtension(text) != "." + text2)
            {
                string text3 = FileUtil.GetPathWithoutExtension(EditorApplication.currentScene);
                if (string.IsNullOrEmpty(text3))
                {
                    text3 = "Assets";
                }
                else
                {
                    if (!Directory.Exists(text3))
                    {
                        Directory.CreateDirectory(text3);
                    }
                }
                string text4 = probe.name + ((!probe.hdr) ? "-reflection" : "-reflectionHDR") + "." + text2;
                text4 = Path.GetFileNameWithoutExtension(AssetDatabase.GenerateUniqueAssetPath(Path.Combine(text3, text4)));
                text  = EditorUtility.SaveFilePanelInProject("Save reflection probe's cubemap.", text4, text2, string.Empty, text3);
                if (string.IsNullOrEmpty(text))
                {
                    return;
                }
            }
            EditorUtility.DisplayProgressBar("Reflection Probes", "Baking " + text, 0.5f);
            if (!Lightmapping.BakeReflectionProbe(probe, text))
            {
                Debug.LogError("Failed to bake reflection probe to " + text);
            }
            EditorUtility.ClearProgressBar();
        }
Exemplo n.º 5
0
        private void BakeCustomReflectionProbe(ReflectionProbe probe, bool usePreviousAssetPath)
        {
            string str1 = string.Empty;

            if (usePreviousAssetPath)
            {
                str1 = AssetDatabase.GetAssetPath((UnityEngine.Object)probe.customBakedTexture);
            }
            string extension = !probe.hdr ? "png" : "exr";

            if (string.IsNullOrEmpty(str1) || Path.GetExtension(str1) != "." + extension)
            {
                string str2 = FileUtil.GetPathWithoutExtension(SceneManager.GetActiveScene().path);
                if (string.IsNullOrEmpty(str2))
                {
                    str2 = "Assets";
                }
                else if (!Directory.Exists(str2))
                {
                    Directory.CreateDirectory(str2);
                }
                string path2 = probe.name + (!probe.hdr ? "-reflection" : "-reflectionHDR") + "." + extension;
                str1 = EditorUtility.SaveFilePanelInProject("Save reflection probe's cubemap.", Path.GetFileNameWithoutExtension(AssetDatabase.GenerateUniqueAssetPath(Path.Combine(str2, path2))), extension, string.Empty, str2);
                ReflectionProbe collidingProbe;
                if (string.IsNullOrEmpty(str1) || this.IsCollidingWithOtherProbes(str1, probe, out collidingProbe) && !EditorUtility.DisplayDialog("Cubemap is used by other reflection probe", string.Format("'{0}' path is used by the game object '{1}', do you really want to overwrite it?", (object)str1, (object)collidingProbe.name), "Yes", "No"))
                {
                    return;
                }
            }
            EditorUtility.DisplayProgressBar("Reflection Probes", "Baking " + str1, 0.5f);
            if (!Lightmapping.BakeReflectionProbe(probe, str1))
            {
                Debug.LogError((object)("Failed to bake reflection probe to " + str1));
            }
            EditorUtility.ClearProgressBar();
        }