chore: add idempotent Main prefab connection entry

This commit is contained in:
NINI
2026-10-05 02:36:59 +09:00
parent 263fecc19a
commit 4f10fcc91a
@@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using UnityEditor; using UnityEditor;
using UnityEditor.Build.Reporting; using UnityEditor.Build.Reporting;
using UnityEditor.SceneManagement; using UnityEditor.SceneManagement;
@@ -46,6 +47,26 @@ namespace MagnetismHeroes.Editor
Debug.Log("[Scaffold] Unity project prepared."); Debug.Log("[Scaffold] Unity project prepared.");
} }
public static void ConnectApp()
{
const string prefabPath = "Assets/MagnetismHeroes/UnityRuntime/Presentation/Prefabs/GameApp.prefab";
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(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<Camera>() != null)
|| (root.name == "Directional Light" && root.GetComponent<Light>() != 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() public static void BuildAndroid()
{ {
string apkPath = Environment.GetEnvironmentVariable("MAGNETISM_APK_PATH"); string apkPath = Environment.GetEnvironmentVariable("MAGNETISM_APK_PATH");