From 4f10fcc91a705ede7bbe7b7744ef0efad8fb9d8b Mon Sep 17 00:00:00 2001 From: NINI Date: Mon, 5 Oct 2026 02:36:59 +0900 Subject: [PATCH] chore: add idempotent Main prefab connection entry --- .../Editor/ProjectBootstrap.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) 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");