using System.Collections;
|
using System.Collections.Generic;
|
using Unity.VisualScripting;
|
using UnityEngine;
|
using UnityEngine.Events;
|
using UnityEngine.InputSystem.HID;
|
using UnityEngine.SceneManagement;
|
using UnityEngine.UI;
|
using UnityEngine.XR;
|
|
public enum SceneType
|
{
|
Mode_Selector,
|
Train_VR_Mode,
|
Train_Screen_Mode,
|
|
}
|
|
class ModeSwitcher : Singleton<ModeSwitcher>
|
{
|
public UILoadingBar LoadingBar;
|
|
private List<XRDisplaySubsystem> subsystems = new List<XRDisplaySubsystem>();
|
|
public override void Awake()
|
{
|
LoadingBar.Hide();
|
|
|
}
|
|
public void Start()
|
{
|
SubsystemManager.GetInstances<XRDisplaySubsystem>(subsystems);
|
}
|
|
|
public void ChangeSceneAsycn(string type)
|
{
|
if (LoadingBar == null)
|
{
|
Debug.LogError("LoadingBar is Null");
|
}
|
LoadingBar.Show();
|
|
StartCoroutine(LoadScene(type));
|
}
|
|
|
IEnumerator LoadScene(string type)
|
{
|
yield return null;
|
|
PlayerPrefs.SetString(PlayerPrefsManager.MODE, type);
|
bool isVR = type == SceneType.Train_VR_Mode.ToString();
|
|
yield return StartCoroutine(SetVRDevice(isVR));
|
|
|
AsyncOperation asyncOperation = SceneManager.LoadSceneAsync("Train");
|
while (!asyncOperation.isDone)
|
{
|
float progressValue = Mathf.Clamp01(asyncOperation.progress / 0.9f);
|
LoadingBar.SetValue(progressValue);
|
yield return null;
|
}
|
LoadingBar.Hide();
|
|
Debug.Log(XRSettings.isDeviceActive);
|
}
|
|
|
public IEnumerator SetVRDevice(bool enable)
|
{
|
|
|
if(enable)
|
{
|
foreach(XRDisplaySubsystem subsystem in subsystems)
|
{
|
subsystem.Start();
|
|
}
|
|
|
} else
|
{
|
foreach (XRDisplaySubsystem subsystem in subsystems)
|
{
|
subsystem.Stop();
|
}
|
}
|
yield return null;
|
}
|
}
|