2026-05-26 17:13:02 +09:00
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
|
|
|
|
|
namespace VRBeats
|
|
|
|
|
{
|
|
|
|
|
// 모든 씬에서 자동 실행.
|
|
|
|
|
// Game 씬: VRPointerController를 비활성 상태로 추가 → VR_InteractorController가 게임오버 시 활성화.
|
|
|
|
|
// 나머지 씬: 바로 활성 상태로 추가.
|
|
|
|
|
public class VRPointerSetup : MonoBehaviour
|
|
|
|
|
{
|
2026-05-26 18:21:58 +09:00
|
|
|
private static VRPointerSetup instance;
|
|
|
|
|
|
|
|
|
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
|
|
|
|
private static void ResetStatics()
|
|
|
|
|
{
|
|
|
|
|
instance = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
2026-05-26 17:13:02 +09:00
|
|
|
private static void AutoInject()
|
|
|
|
|
{
|
2026-05-26 18:21:58 +09:00
|
|
|
if (instance != null)
|
|
|
|
|
return;
|
|
|
|
|
|
2026-05-26 17:13:02 +09:00
|
|
|
var go = new GameObject("[VRPointerSetup]");
|
|
|
|
|
go.AddComponent<VRPointerSetup>();
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-26 18:21:58 +09:00
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
if (instance != null && instance != this)
|
|
|
|
|
{
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
instance = this;
|
|
|
|
|
DontDestroyOnLoad(gameObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
|
{
|
|
|
|
|
SceneManager.sceneLoaded += OnSceneLoaded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
|
{
|
|
|
|
|
SceneManager.sceneLoaded -= OnSceneLoaded;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-26 17:13:02 +09:00
|
|
|
private void Start()
|
|
|
|
|
{
|
2026-05-26 18:21:58 +09:00
|
|
|
SetupActiveScene();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
|
|
|
|
{
|
|
|
|
|
SetupScene(scene);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void SetupActiveScene()
|
|
|
|
|
{
|
|
|
|
|
SetupScene(SceneManager.GetActiveScene());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void SetupScene(Scene scene)
|
|
|
|
|
{
|
|
|
|
|
bool isGameScene = scene.name == "Game";
|
2026-05-26 17:13:02 +09:00
|
|
|
SetupControllers(disabledByDefault: isGameScene);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void SetupControllers(bool disabledByDefault)
|
|
|
|
|
{
|
|
|
|
|
foreach (var go in FindObjectsByType<GameObject>(FindObjectsSortMode.None))
|
|
|
|
|
{
|
|
|
|
|
string name = go.name;
|
|
|
|
|
bool isRight = name.Contains("Right");
|
|
|
|
|
bool isLeft = name.Contains("Left");
|
|
|
|
|
|
|
|
|
|
if (!isRight && !isLeft) continue;
|
|
|
|
|
if (!name.Contains("Controller") && !name.Contains("Hand")) continue;
|
|
|
|
|
if (go.GetComponent<LineRenderer>() == null) continue;
|
|
|
|
|
if (go.GetComponent<VRPointerController>() != null) continue;
|
|
|
|
|
|
|
|
|
|
var pointer = go.AddComponent<VRPointerController>();
|
|
|
|
|
|
|
|
|
|
var field = typeof(VRPointerController)
|
|
|
|
|
.GetField("isRightHand",
|
|
|
|
|
System.Reflection.BindingFlags.NonPublic |
|
|
|
|
|
System.Reflection.BindingFlags.Instance);
|
|
|
|
|
field?.SetValue(pointer, isRight);
|
|
|
|
|
|
|
|
|
|
// Game 씬에서는 게임오버 전까지 비활성
|
|
|
|
|
if (disabledByDefault)
|
|
|
|
|
pointer.enabled = false;
|
|
|
|
|
|
|
|
|
|
Debug.Log($"[VRPointerSetup] {(isRight ? "Right" : "Left")} pointer 추가: {go.name} (enabled={!disabledByDefault})");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|