diff --git a/Assets/MagnetismHeroes/Editor/ProjectBootstrap.cs b/Assets/MagnetismHeroes/Editor/ProjectBootstrap.cs index 528b737..ca15805 100644 --- a/Assets/MagnetismHeroes/Editor/ProjectBootstrap.cs +++ b/Assets/MagnetismHeroes/Editor/ProjectBootstrap.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Linq; using UnityEditor; using UnityEditor.Build.Reporting; using UnityEditor.SceneManagement; @@ -46,6 +47,26 @@ namespace MagnetismHeroes.Editor Debug.Log("[Scaffold] Unity project prepared."); } + public static void ConnectApp() + { + const string prefabPath = "Assets/MagnetismHeroes/UnityRuntime/Presentation/Prefabs/GameApp.prefab"; + var prefab = AssetDatabase.LoadAssetAtPath(prefabPath); + if (prefab == null) throw new InvalidOperationException("GameApp prefab missing."); + var scene = EditorSceneManager.OpenScene(MainScenePath, OpenSceneMode.Single); + var instances = scene.GetRootGameObjects().Where(root => + PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(root) == prefabPath).ToArray(); + if (instances.Length > 1) throw new InvalidOperationException("Main contains duplicate GameApp instances."); + foreach (var root in scene.GetRootGameObjects()) + { + if ((root.name == "Main Camera" && root.GetComponent() != null) + || (root.name == "Directional Light" && root.GetComponent() != null)) + UnityEngine.Object.DestroyImmediate(root); + } + if (instances.Length == 0) PrefabUtility.InstantiatePrefab(prefab, scene); + EditorSceneManager.SaveScene(scene, MainScenePath); + Debug.Log("[Integration] Main connected to GameApp."); + } + public static void BuildAndroid() { string apkPath = Environment.GetEnvironmentVariable("MAGNETISM_APK_PATH");