|
|
|
|
|
|
if (!BakePlanarReflectionProbe(probe, path)) |
|
|
|
Debug.LogError("Failed to bake reflection probe to " + path); |
|
|
|
EditorUtility.ClearProgressBar(); |
|
|
|
|
|
|
|
AssetDatabase.ImportAsset(path); |
|
|
|
probe.customTexture = AssetDatabase.LoadAssetAtPath<Texture2D>(path); |
|
|
|
EditorUtility.SetDirty(probe); |
|
|
|
} |
|
|
|
|
|
|
|
public static void BakeAllPlanarReflectionProbes() |
|
|
|
|
|
|
|
|
|
|
public static void ResetProbeSceneTextureInMaterial(PlanarReflectionProbe p) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
static MethodInfo k_Lightmapping_BakeReflectionProbeSnapshot = typeof(UnityEditor.Lightmapping).GetMethod("BakeReflectionProbeSnapshot", BindingFlags.Static | BindingFlags.NonPublic); |
|
|
|
|
|
|
{ |
|
|
|
var rt = ReflectionSystem.NewRenderTarget(probe); |
|
|
|
var bakedTexture = probe.bakedTexture as Texture2D; |
|
|
|
if (bakedTexture == null) |
|
|
|
var assetPath = string.Empty; |
|
|
|
if (bakedTexture != null) |
|
|
|
assetPath = AssetDatabase.GetAssetPath(bakedTexture); |
|
|
|
if (string.IsNullOrEmpty(assetPath)) |
|
|
|
assetPath = GetBakePath(probe); |
|
|
|
|
|
|
|
var importAsset = false; |
|
|
|
if (bakedTexture == null || string.IsNullOrEmpty(assetPath)) |
|
|
|
var bakedAssetPath = GetBakePath(probe); |
|
|
|
AssetDatabase.CreateAsset(bakedTexture, bakedAssetPath); |
|
|
|
importAsset = true; |
|
|
|
|
|
|
|
EditorUtility.SetDirty(probe); |
|
|
|
} |
|
|
|
|
|
|
|
ReflectionSystem.Render(probe, rt); |
|
|
|
|
|
|
RenderTexture.active = art; |
|
|
|
|
|
|
|
var assetPath = AssetDatabase.GetAssetPath(bakedTexture); |
|
|
|
var bytes = bakedTexture.EncodeToEXR(); |
|
|
|
File.WriteAllBytes(assetPath, bytes); |
|
|
|
if (importAsset) |
|
|
|
AssetDatabase.CreateAsset(bakedTexture, assetPath); |
|
|
|
else |
|
|
|
{ |
|
|
|
var bytes = bakedTexture.EncodeToEXR(); |
|
|
|
File.WriteAllBytes(assetPath, bytes); |
|
|
|
AssetDatabase.ImportAsset(assetPath); |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
var scene = probe.gameObject.scene; |
|
|
|
|
|
|
|
var targetPath = GetSceneBakeDirectoryPath(scene); |
|
|
|
if (Directory.Exists(targetPath) == false) |
|
|
|
if (!Directory.Exists(targetPath)) |
|
|
|
return Path.GetFileNameWithoutExtension(AssetDatabase.GenerateUniqueAssetPath(Path.Combine(targetPath, fileName))); |
|
|
|
return AssetDatabase.GenerateUniqueAssetPath(Path.Combine(targetPath, fileName)); |
|
|
|
} |
|
|
|
|
|
|
|
static string GetSceneBakeDirectoryPath(Scene scene) |
|
|
|