열차 목업의 내부 확인용 프로젝트
smchoi
2024-07-24 ec231f4110c782d44ea2820a1eaaa7a5711c6f16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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;
    }
}