94 lines
2.9 KiB
C#
94 lines
2.9 KiB
C#
|
|
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<MenuSyncButtonInjector>() != null)
|
||
|
|
return;
|
||
|
|
|
||
|
|
GameObject go = new GameObject("[MenuSyncButtonInjector]");
|
||
|
|
DontDestroyOnLoad(go);
|
||
|
|
go.AddComponent<MenuSyncButtonInjector>();
|
||
|
|
}
|
||
|
|
|
||
|
|
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<VRBeats.LoadSceneButton>())
|
||
|
|
{
|
||
|
|
loader.enabled = false;
|
||
|
|
Destroy(loader);
|
||
|
|
}
|
||
|
|
|
||
|
|
syncButton.onClick.RemoveAllListeners();
|
||
|
|
syncButton.onClick.AddListener(SyncCalibrationOverlay.Open);
|
||
|
|
|
||
|
|
RectTransform sourceRect = sourceButton.GetComponent<RectTransform>();
|
||
|
|
RectTransform syncRect = syncButton.GetComponent<RectTransform>();
|
||
|
|
syncRect.anchoredPosition = sourceRect.anchoredPosition + new Vector2(0.0f, -22.0f);
|
||
|
|
|
||
|
|
TextMeshProUGUI tmp = syncButton.GetComponentInChildren<TextMeshProUGUI>(true);
|
||
|
|
if (tmp != null)
|
||
|
|
tmp.text = "SYNC";
|
||
|
|
|
||
|
|
Text text = syncButton.GetComponentInChildren<Text>(true);
|
||
|
|
if (text != null)
|
||
|
|
text.text = "SYNC";
|
||
|
|
}
|
||
|
|
|
||
|
|
private static Button FindButtonByText(string text)
|
||
|
|
{
|
||
|
|
foreach (Button button in FindObjectsByType<Button>(FindObjectsSortMode.None))
|
||
|
|
{
|
||
|
|
TextMeshProUGUI tmp = button.GetComponentInChildren<TextMeshProUGUI>(true);
|
||
|
|
if (tmp != null && tmp.text.Trim() == text)
|
||
|
|
return button;
|
||
|
|
|
||
|
|
Text legacyText = button.GetComponentInChildren<Text>(true);
|
||
|
|
if (legacyText != null && legacyText.text.Trim() == text)
|
||
|
|
return button;
|
||
|
|
}
|
||
|
|
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|