diff --git a/Assets/Gothic-Core/Scripts/Models/Config/JsonRootConfig.cs b/Assets/Gothic-Core/Scripts/Models/Config/JsonRootConfig.cs index 1262081d6..7b2acaf98 100644 --- a/Assets/Gothic-Core/Scripts/Models/Config/JsonRootConfig.cs +++ b/Assets/Gothic-Core/Scripts/Models/Config/JsonRootConfig.cs @@ -10,5 +10,7 @@ public class JsonRootConfig public List ModFolders; public string LogLevel; public string LogCategories; + // PC builds: the keyboard/mouse device simulator instead of a headset (the Editor uses DeveloperConfig's). + public bool EnableVRDeviceSimulator; } } diff --git a/Assets/Gothic-Core/Scripts/Services/Config/ConfigService.cs b/Assets/Gothic-Core/Scripts/Services/Config/ConfigService.cs index 343af61de..81d95d1cf 100644 --- a/Assets/Gothic-Core/Scripts/Services/Config/ConfigService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Config/ConfigService.cs @@ -20,6 +20,23 @@ namespace Gothic.Core.Services.Config /// public class ConfigService { + /// + /// The keyboard/mouse device simulator instead of a headset. Editor: DeveloperConfig; builds: + /// GameSettings(.dev).json "EnableVRDeviceSimulator" - a PC build can be tried without the headset on. + /// Always off on mobile. + /// + public bool EffectiveEnableVRDeviceSimulator + { + get + { +#if UNITY_EDITOR + return Dev.EnableVRDeviceSimulator; +#else + return Root != null && Root.EnableVRDeviceSimulator && !UnityEngine.Application.isMobilePlatform; +#endif + } + } + public JsonRootConfig Root { get; private set; } public DeveloperConfig Dev { get; private set; } public GothicIniConfig Gothic { get; private set; } diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VRSpectatorCamera.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VRSpectatorCamera.cs index 74098b5a4..f9378cf2e 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VRSpectatorCamera.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VRSpectatorCamera.cs @@ -50,7 +50,7 @@ private void Start() // If we have Device Simulator AND Spectator camera active, then the camera won't move at all in GameView. // And to be honest: We don't need the Spectator camera at that time. - if (_configService.Dev.EnableVRDeviceSimulator) + if (_configService.EffectiveEnableVRDeviceSimulator) { DisableSpectatorCamera(); return; diff --git a/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrInput.cs b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrInput.cs index e40342661..f645ca335 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrInput.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrInput.cs @@ -76,7 +76,7 @@ bool IsThumbTouching(VrHandSide side) Vector2 GetThumbstick(VrHandSide side); /// - /// Activates the desktop device simulator (DeveloperConfig.EnableVRDeviceSimulator). + /// Activates the desktop device simulator (ConfigService.EffectiveEnableVRDeviceSimulator). /// void SetDeviceSimulatorActive(bool isActive); } diff --git a/Assets/Gothic-VR/Scripts/Services/Context/VRContextInteractionService.cs b/Assets/Gothic-VR/Scripts/Services/Context/VRContextInteractionService.cs index 3a0928f84..7ce09d58b 100644 --- a/Assets/Gothic-VR/Scripts/Services/Context/VRContextInteractionService.cs +++ b/Assets/Gothic-VR/Scripts/Services/Context/VRContextInteractionService.cs @@ -152,7 +152,7 @@ private void OnLoadingSceneLoaded() public float GetFrameRate() { // If we have no VR device attached to our computer, we will get an NPE for activeLoader. - if (_configService.Dev.EnableVRDeviceSimulator || XRGeneralSettings.Instance.Manager.activeLoader == null) + if (_configService.EffectiveEnableVRDeviceSimulator || XRGeneralSettings.Instance.Manager.activeLoader == null) { return 0; } @@ -204,8 +204,11 @@ public void SetupPlayerController(DeveloperConfig developerConfig) ApplyControlLayout(); } - // XRDeviceSimulator - _vrInput.SetDeviceSimulatorActive(developerConfig.EnableVRDeviceSimulator); + // XRDeviceSimulator (Editor: DeveloperConfig, builds: GameSettings.json) + var isSimulatorEnabled = _configService.EffectiveEnableVRDeviceSimulator; + if (isSimulatorEnabled) + StopXRForSimulator(); + _vrInput.SetDeviceSimulatorActive(isSimulatorEnabled); // A trigger click at a worn item in the backpack equips it. var equipToggle = new GameObject("_BackpackEquipToggle").AddComponent(); @@ -315,6 +318,22 @@ private void ApplyPhysicalHands() /// /// Game settings "controller hand", "jump button" and "menu button" from Gothic.ini. /// + /// + /// Builds start XR on startup. With a headset (or SteamVR) running, it would still drive the camera next to the + /// simulator - XR stops, mouse and keyboard own the rig and the window shows the game. + /// + private void StopXRForSimulator() + { + var settings = XRGeneralSettings.Instance; + var manager = settings != null ? settings.Manager : null; + if (manager == null || manager.activeLoader == null) + return; + + manager.StopSubsystems(); + manager.DeinitializeLoader(); + Logger.Log("[VRDeviceSimulator] XR stopped, the simulator drives the player.", LogCat.VR); + } + private void ApplyControlLayout() { var gothicIni = _configService.Gothic; @@ -336,7 +355,7 @@ private void ApplyComfortSettings(bool useDefaultValues = false) // The device simulator's head has no height: with the player's real height (floor tracking) the camera // sat on the floor and the wall fade blacked out the game version / profile menu. Seated, the rig puts // the eyes at their default height. Gothic.ini's setting takes over once it's loaded. - var defaultSitStand = _configService.Dev.EnableVRDeviceSimulator + var defaultSitStand = _configService.EffectiveEnableVRDeviceSimulator ? VrSitStand.Sitting : VrSitStand.PlayerHeight; _rig.ApplyComfortSettings(defaultSitStand, VrMoveDirection.Camera, VrTurnType.Snap, 45f, 90f); diff --git a/Assets/StreamingAssets/GameSettings.json b/Assets/StreamingAssets/GameSettings.json index dfe5842f6..9d6768f82 100644 --- a/Assets/StreamingAssets/GameSettings.json +++ b/Assets/StreamingAssets/GameSettings.json @@ -3,5 +3,6 @@ "Gothic2Path": "---Defaults to Steam installation path (PCVR) or files/Gothic2 (Mobile VR)---", "ModFolders": [], "LogLevel": "---Set log level to one of these values: Message/Warning/Error. Default: Warning---", - "LogCategories": "--Filter categories as list via colon/semicolon. Default: ALL--" + "LogCategories": "--Filter categories as list via colon/semicolon. Default: ALL--", + "EnableVRDeviceSimulator": false }