/// <summary> /// Initialize the application GUI, singleton classes, and initialize OpenVR. /// </summary> protected void Awake() { #if DEBUG Utils.Log(Globals.KERBALVR_NAME + " plugin starting..."); #endif // init objects gui = new AppGUI(); _hmdIsEnabled = false; HmdIsAllowed = false; // init GameObjects GameObject kvrDeviceManager = new GameObject("KVR_DeviceManager"); kvrDeviceManager.AddComponent <DeviceManager>(); DeviceManager deviceManagerComponent = DeviceManager.Instance; // init the singleton DontDestroyOnLoad(kvrDeviceManager); GameObject kvrScene = new GameObject("KVR_Scene"); kvrScene.AddComponent <Scene>(); Scene kvrSceneComponent = Scene.Instance; // init the singleton DontDestroyOnLoad(kvrScene); // add an event triggered when game scene changes, to handle // shutting off the HMD outside of allowed VR scenes GameEvents.onGameSceneLoadRequested.Add(OnGameSceneLoadRequested); // initialize the OpenVR API bool success = InitHMD(); if (!success) { Utils.LogError("Unable to initialize VR headset!"); } else { Utils.Log("Initialized OpenVR."); } // when ready for a GUI, load it GameEvents.onGUIApplicationLauncherReady.Add(gui.OnAppLauncherReady); GameEvents.onGUIApplicationLauncherDestroyed.Add(gui.OnAppLauncherDestroyed); // don't destroy this object when switching scenes DontDestroyOnLoad(this); }
/// <summary> /// Initialize the application GUI, singleton classes, and initialize OpenVR. /// </summary> private void Awake() { #if DEBUG Utils.Log(Globals.KERBALVR_NAME + " plugin starting..."); #endif // init objects gui = new AppGUI(); HmdIsAllowed = false; // init GameObjects GameObject kvrDeviceManager = new GameObject("KVR_DeviceManager"); kvrDeviceManager.AddComponent <DeviceManager>(); DeviceManager deviceManagerComponent = DeviceManager.Instance; // init the singleton DontDestroyOnLoad(kvrDeviceManager); GameObject kvrScene = new GameObject("KVR_Scene"); kvrScene.AddComponent <Scene>(); Scene kvrSceneComponent = Scene.Instance; // init the singleton DontDestroyOnLoad(kvrScene); GameObject kvrConfiguration = new GameObject("KVR_Configuration"); kvrConfiguration.AddComponent <Configuration>(); Configuration kvrConfigurationComponent = Configuration.Instance; // init the singleton DontDestroyOnLoad(kvrConfiguration); // initialize OpenVR if allowed in config if (Configuration.Instance.InitOpenVrAtStartup) { InitializeHMD(); } // add an event triggered when game scene changes, to handle // shutting off the HMD outside of allowed VR scenes GameEvents.onGameSceneLoadRequested.Add(OnGameSceneLoadRequested); // when ready for a GUI, load it GameEvents.onGUIApplicationLauncherReady.Add(gui.OnAppLauncherReady); GameEvents.onGUIApplicationLauncherDestroyed.Add(gui.OnAppLauncherDestroyed); // don't destroy this object when switching scenes DontDestroyOnLoad(this); }