Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Assets/Gothic-Core/Scripts/Models/Config/JsonRootConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ public class JsonRootConfig
public List<JsonModFolder> 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;
}
}
17 changes: 17 additions & 0 deletions Assets/Gothic-Core/Scripts/Services/Config/ConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ namespace Gothic.Core.Services.Config
/// </summary>
public class ConfigService
{
/// <summary>
/// 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.
/// </summary>
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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Assets/Gothic-VR/Scripts/Interaction/Ports/IVrInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool IsThumbTouching(VrHandSide side)
Vector2 GetThumbstick(VrHandSide side);

/// <summary>
/// Activates the desktop device simulator (DeveloperConfig.EnableVRDeviceSimulator).
/// Activates the desktop device simulator (ConfigService.EffectiveEnableVRDeviceSimulator).
/// </summary>
void SetDeviceSimulatorActive(bool isActive);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<VRBackpackEquipToggle>();
Expand Down Expand Up @@ -315,6 +318,22 @@ private void ApplyPhysicalHands()
/// <summary>
/// Game settings "controller hand", "jump button" and "menu button" from Gothic.ini.
/// </summary>
/// <summary>
/// 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.
/// </summary>
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;
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion Assets/StreamingAssets/GameSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}