using System; using System.IO; using System.Linq; using System.Threading.Tasks; using HotUpdate.Gameplay; using Newtonsoft.Json; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; using UnityEngine.UI; public static class VerifyMainMenuMusic { public static string Preflight() { var scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene(); return JsonConvert.SerializeObject(new { scene.path, scene.isDirty, scenes = Enumerable.Range(0, UnityEngine.SceneManagement.SceneManager.sceneCount) .Select(i => UnityEngine.SceneManagement.SceneManager.GetSceneAt(i)) .Select(s => new { s.path, s.isDirty }).ToArray() }); } public static string PrepareBoot() { var previous = EditorSceneManager.playModeStartScene; SessionState.SetString("AIGame.Music.PreviousPlayScene", previous == null ? "" : AssetDatabase.GetAssetPath(previous)); EditorSceneManager.playModeStartScene = AssetDatabase.LoadAssetAtPath("Assets/Scenes/Boot.unity"); return "Boot selected for Play Mode only; existing edit scenes preserved: " + Preflight(); } public static string RestoreScenes() { Check(!EditorApplication.isPlaying, "Exit Play Mode before restore"); string path = SessionState.GetString("AIGame.Music.PreviousPlayScene", ""); EditorSceneManager.playModeStartScene = string.IsNullOrEmpty(path) ? null : AssetDatabase.LoadAssetAtPath(path); SessionState.EraseString("AIGame.Music.PreviousPlayScene"); return Preflight(); } static void Check(bool ok, string message) { if (!ok) throw new Exception(message); } static async Task Until(Func condition, string message, int seconds = 25) { var deadline = DateTime.UtcNow.AddSeconds(seconds); while (!condition()) { Check(DateTime.UtcNow < deadline, message); await Task.Delay(100); } } public static async Task Play() { Check(EditorApplication.isPlaying, "Play Mode required"); const string musicKey = "AIGame.Settings.music", sfxKey = "AIGame.Settings.sfx"; bool hadMusic = PlayerPrefs.HasKey(musicKey), hadSfx = PlayerPrefs.HasKey(sfxKey); int musicValue = PlayerPrefs.GetInt(musicKey, 1), sfxValue = PlayerPrefs.GetInt(sfxKey, 1); float listenerVolume = AudioListener.volume; PrototypeFlow flow = null; try { await Until(() => UnityEngine.Object.FindObjectOfType() != null, "Music not loaded by bootstrap"); var music = UnityEngine.Object.FindObjectOfType(); var source = music.Source; Check(source != null && source.clip.name == "MeadowBreeze_MainMenu_Loop", "Wrong selected song"); Check(source.loop && !source.playOnAwake && source.spatialBlend == 0, "Invalid authored audio source"); PrototypeClientPrefs.Music = true; PrototypeClientPrefs.Sfx = true; await Until(() => source.isPlaying, "Main menu music did not start"); float before = source.time; await Task.Delay(300); Check(source.time > before, "Playback samples did not advance"); flow = UnityEngine.Object.FindObjectOfType(); await Until(() => flow != null && flow.Game != null && !flow.IsBusy, "Gameplay not ready for navigation"); flow.Handle("Home"); for (int i = 0; i < 3; i++) { before = source.time; flow.Handle("Settings"); await Until(() => flow.Page == "UI_PrototypeSettings", "Settings did not open"); Check(source.isPlaying && source.time >= before - 0.1f, "Opening settings restarted or stopped music"); var button = UnityEngine.Object.FindObjectsOfType