using System.Linq;
using UnityEngine.SceneManagement;
namespace Unity.Pipeline.Editor.Commands.Baking
{
///
/// Shared helpers for the CLI-215 bake commands (lighting / NavMesh / occlusion). All three bakes
/// act on the currently open scene(s) — there is no per-asset target — so before triggering
/// any bake we verify at least one open, saved scene exists. A bake against no open/saved scene is
/// rejected up front with the documented { code: "no_scene" } result (returned, not thrown,
/// to match the CLI-215 spec), and nothing is started.
///
internal static class BakeSceneGuard
{
/// The structured "no_scene" error payload returned by a trigger with no bakeable scene.
internal static object NoSceneResult()
{
return new
{
code = "no_scene",
message = "No open, saved scene to bake. Open a scene first (open_scene) and ensure it is saved to disk."
};
}
///
/// True when there is at least one open, loaded scene that has been saved to disk (a non-empty
/// path). An untitled/never-saved scene has an empty and cannot host a
/// bake (its data has nowhere to live), so it does not count.
///
internal static bool HasBakeableScene()
{
return OpenScenes().Any(s => s.isLoaded && !string.IsNullOrEmpty(s.path));
}
/// Enumerate every open scene by index.
internal static System.Collections.Generic.IEnumerable OpenScenes()
{
for (int i = 0; i < SceneManager.sceneCount; i++)
yield return SceneManager.GetSceneAt(i);
}
}
}