using System.Collections; using TMPro; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class MenuSyncButtonInjector : MonoBehaviour { private const string MenuSceneName = "Menu"; [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)] private static void AutoCreate() { if (FindFirstObjectByType() != null) return; GameObject go = new GameObject("[MenuSyncButtonInjector]"); DontDestroyOnLoad(go); go.AddComponent(); } private void Awake() { SceneManager.sceneLoaded += OnSceneLoaded; StartCoroutine(InjectAfterFrame()); } private void OnDestroy() { SceneManager.sceneLoaded -= OnSceneLoaded; } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { StartCoroutine(InjectAfterFrame()); } private IEnumerator InjectAfterFrame() { yield return null; if (SceneManager.GetActiveScene().name != MenuSceneName) yield break; if (GameObject.Find("SyncButton") != null) yield break; Button sourceButton = FindButtonByText("CreateSong"); if (sourceButton == null) sourceButton = FindButtonByText("음악만들기"); if (sourceButton == null) yield break; Button syncButton = Instantiate(sourceButton, sourceButton.transform.parent); syncButton.gameObject.name = "SyncButton"; foreach (VRBeats.LoadSceneButton loader in syncButton.GetComponents()) { loader.enabled = false; Destroy(loader); } syncButton.onClick.RemoveAllListeners(); syncButton.onClick.AddListener(SyncCalibrationOverlay.Open); RectTransform sourceRect = sourceButton.GetComponent(); RectTransform syncRect = syncButton.GetComponent(); syncRect.anchoredPosition = sourceRect.anchoredPosition + new Vector2(0.0f, -22.0f); TextMeshProUGUI tmp = syncButton.GetComponentInChildren(true); if (tmp != null) tmp.text = "SYNC"; Text text = syncButton.GetComponentInChildren(true); if (text != null) text.text = "SYNC"; } private static Button FindButtonByText(string text) { foreach (Button button in FindObjectsByType