feat: improve VR menu pointer and BeatSaber flow
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace VRBeats
|
||||
{
|
||||
// 모든 씬에서 자동 실행.
|
||||
// Game 씬: VRPointerController를 비활성 상태로 추가 → VR_InteractorController가 게임오버 시 활성화.
|
||||
// 나머지 씬: 바로 활성 상태로 추가.
|
||||
public class VRPointerSetup : MonoBehaviour
|
||||
{
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
|
||||
private static void AutoInject()
|
||||
{
|
||||
var go = new GameObject("[VRPointerSetup]");
|
||||
go.AddComponent<VRPointerSetup>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
bool isGameScene = SceneManager.GetActiveScene().name == "Game";
|
||||
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})");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user