96 lines
2.6 KiB
C#
96 lines
2.6 KiB
C#
using System.Collections;
|
||
using UnityEngine;
|
||
using UnityEngine.InputSystem;
|
||
using UnityEngine.SceneManagement;
|
||
using UnityEngine.UI;
|
||
|
||
public class TitleManager : MonoBehaviour
|
||
{
|
||
[Header("VR入力設定")]
|
||
[Tooltip("スタート用の右手トリガー入力(例: XRI RightHand Interaction/Activate など)")]
|
||
[SerializeField] private InputActionProperty rightTriggerAction;
|
||
[Tooltip("スタート用の左手トリガー入力(任意)")]
|
||
[SerializeField] private InputActionProperty leftTriggerAction;
|
||
|
||
[Header("UI Buttons(任意)")]
|
||
[SerializeField] private Button startButton;
|
||
[SerializeField] private Button exitButton;
|
||
|
||
[Header("Scene Settings")]
|
||
[SerializeField] private string mainGameSceneName = "MainGameScene";
|
||
|
||
private bool isStarting = false;
|
||
|
||
private void Awake()
|
||
{
|
||
if (startButton != null) startButton.onClick.AddListener(StartGame);
|
||
if (exitButton != null) exitButton.onClick.AddListener(OnExitButtonClicked);
|
||
}
|
||
|
||
private void OnEnable()
|
||
{
|
||
EnableAction(rightTriggerAction);
|
||
EnableAction(leftTriggerAction);
|
||
}
|
||
|
||
private void OnDisable()
|
||
{
|
||
DisableAction(rightTriggerAction);
|
||
DisableAction(leftTriggerAction);
|
||
}
|
||
|
||
private void EnableAction(InputActionProperty prop)
|
||
{
|
||
if (prop.action != null) prop.action.Enable();
|
||
}
|
||
|
||
private void DisableAction(InputActionProperty prop)
|
||
{
|
||
if (prop.action != null) prop.action.Disable();
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
if (isStarting) return;
|
||
|
||
// トリガー入力の判定(右手または左手)
|
||
if (IsTriggerPressed(rightTriggerAction) || IsTriggerPressed(leftTriggerAction))
|
||
{
|
||
StartGame();
|
||
}
|
||
}
|
||
|
||
private bool IsTriggerPressed(InputActionProperty prop)
|
||
{
|
||
if (prop.action == null) return false;
|
||
return prop.action.triggered || prop.action.ReadValue<float>() > 0.5f;
|
||
}
|
||
|
||
public void StartGame()
|
||
{
|
||
if (isStarting) return;
|
||
isStarting = true;
|
||
|
||
if (startButton != null) startButton.interactable = false;
|
||
Debug.Log("🚀 トリガー入力を検知:メインゲームシーンを読み込みます。");
|
||
StartCoroutine(LoadSceneRoutine());
|
||
}
|
||
|
||
public void OnExitButtonClicked()
|
||
{
|
||
#if UNITY_EDITOR
|
||
UnityEditor.EditorApplication.isPlaying = false;
|
||
#else
|
||
Application.Quit();
|
||
#endif
|
||
}
|
||
|
||
private IEnumerator LoadSceneRoutine()
|
||
{
|
||
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(mainGameSceneName);
|
||
while (!asyncLoad.isDone)
|
||
{
|
||
yield return null;
|
||
}
|
||
}
|
||
} |