#if UNITY_EDITOR using BrewMonster.Scripts; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; using UnityEngine.SceneManagement; namespace BrewMonster.Editor { /// /// Tạo scene GameContentBootstrap và đưa lên đầu Build Settings (trước Bootstrap). /// public static class GameContentBootstrapSceneSetup { const string ContentScenePath = "Assets/PerfectWorld/Scene/GameContentBootstrap.unity"; const string BootstrapScenePath = "Assets/PerfectWorld/Scene/Bootstrap.unity"; [MenuItem("Perfect World/Addressables/Setup Two-Scene Bootstrap")] public static void SetupTwoSceneBootstrap() { EnsureContentBootstrapScene(); RemoveGameContentBootstrapFromBootstrapScene(); ReorderBuildSettings(); AssetDatabase.SaveAssets(); Debug.Log( "[Cuong] Two-scene bootstrap: (0) GameContentBootstrap → (1) Bootstrap. " + "Gỡ GameContentBootstrap khỏi Bootstrap.unity; cấu hình _nextSceneName trên component trong scene Content."); } static void EnsureContentBootstrapScene() { if (System.IO.File.Exists(ContentScenePath)) return; var scene = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single); var root = new GameObject("GameContentBootstrap"); var bootstrap = root.AddComponent(); var so = new SerializedObject(bootstrap); so.FindProperty("_loadNextSceneAfterSuccess").boolValue = true; so.FindProperty("_nextSceneName").stringValue = "Bootstrap"; so.ApplyModifiedPropertiesWithoutUndo(); EditorSceneManager.SaveScene(scene, ContentScenePath); Debug.Log($"[Cuong] Created {ContentScenePath}"); } static void RemoveGameContentBootstrapFromBootstrapScene() { if (!System.IO.File.Exists(BootstrapScenePath)) { Debug.LogWarning($"[Cuong] Missing {BootstrapScenePath}"); return; } var scene = EditorSceneManager.OpenScene(BootstrapScenePath, OpenSceneMode.Single); var targets = Object.FindObjectsByType(FindObjectsInactive.Include, FindObjectsSortMode.None); if (targets == null || targets.Length == 0) { Debug.Log("[Cuong] Bootstrap.unity: no GameContentBootstrap found (already clean)."); return; } foreach (var t in targets) Object.DestroyImmediate(t.gameObject); EditorSceneManager.MarkSceneDirty(scene); EditorSceneManager.SaveScene(scene); } static void ReorderBuildSettings() { var scenes = new System.Collections.Generic.List(EditorBuildSettings.scenes); EditorBuildSettingsScene contentEntry = null; for (int i = scenes.Count - 1; i >= 0; i--) { if (scenes[i].path == ContentScenePath) { contentEntry = scenes[i]; scenes.RemoveAt(i); break; } } if (contentEntry == null) contentEntry = new EditorBuildSettingsScene(ContentScenePath, true); contentEntry.enabled = true; scenes.Insert(0, contentEntry); EditorBuildSettings.scenes = scenes.ToArray(); Debug.Log("[Cuong] Build Settings: GameContentBootstrap is index 0."); } } } #endif