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();
}