#if UNITY_EDITOR
using System.Collections.Generic;
using System.IO;
using TMPro;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
///
/// Tools → VRBeatSaber → 전체 자동 설정
/// 씬 생성, 프리팹 생성, Build Settings 등록까지 한 번에 처리
///
public static class VRBeatSaberSceneBuilder
{
private static GameObject s_cardPrefab;
// ══════════════════════════════════════════════════════════
// 뒤로가기 버튼 패치 (기존 씬에 추가)
// ══════════════════════════════════════════════════════════
[MenuItem("Tools/VRBeatSaber/뒤로가기 버튼 추가 (기존 씬 패치)")]
public static void PatchBackButtons()
{
if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) return;
// SongSelect: 뒤로(Intro) + DetailPanel 닫기(X)
PatchSceneWithBackButton(
"Assets/Scenes/SongSelect.unity",
() =>
{
FindAndBindBackButton("backButton", "< 뒤로", new Vector2(-500, 310), new Vector2(130, 50));
AddDetailPanelCloseButton();
});
// SongCreator: 뒤로(Intro)
PatchSceneWithBackButton(
"Assets/Scenes/SongCreator.unity",
() => FindAndBindBackButton("backButton", "< 뒤로", new Vector2(-405, 345), new Vector2(130, 50)));
// MapEditorScene: 뒤로(SongCreator)
PatchSceneWithBackButton(
"Assets/Scenes/MapEditorScene.unity",
FindAndBindBackButtonOnMapEditor);
// Game: 뒤로(SongSelect) — 우측 상단 소형 버튼
PatchSceneWithBackButton(
"Assets/Scenes/Game.unity",
AddGameSceneBackButton);
AssetDatabase.Refresh();
EditorUtility.DisplayDialog("완료", "뒤로가기 버튼 추가 완료!\n\n추가된 버튼:\n- SongSelect: < 뒤로 + 상세패널 X 닫기\n- SongCreator: < 뒤로\n- MapEditorScene: < 뒤로\n- Game: < 뒤로", "확인");
}
private static void PatchSceneWithBackButton(string scenePath, System.Action patchAction)
{
if (!File.Exists(scenePath)) { Debug.LogWarning($"[SceneBuilder] 씬 없음: {scenePath}"); return; }
var scene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single);
patchAction();
EditorSceneManager.SaveScene(scene);
Debug.Log($"[SceneBuilder] 패치 완료: {scenePath}");
}
private static void FindAndBindBackButton(string fieldName, string label, Vector2 pos, Vector2 size) where T : MonoBehaviour
{
var mgr = Object.FindObjectOfType();
if (mgr == null) { Debug.LogWarning($"[SceneBuilder] {typeof(T).Name} 없음"); return; }
// 이미 있으면 건너뜀
var so = new SerializedObject(mgr);
if (so.FindProperty(fieldName)?.objectReferenceValue != null) return;
// Canvas 찾기
var canvas = Object.FindObjectOfType