[DesktopVRSwitch] Nuke CohtmlUISystem Gamepad handling for now.

This commit is contained in:
NotAKidoS 2023-06-19 23:47:43 -05:00
parent 5f95755ad2
commit 0fb7c3d401
19 changed files with 146 additions and 21 deletions

View file

@ -1,4 +1,5 @@
using ABI_RC.Core.Savior;
using UnityEngine;
namespace NAK.DesktopVRSwitch.VRModeTrackers;

View file

@ -1,5 +1,6 @@
using ABI_RC.Core.Savior;
namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class CVRInputManagerTracker : VRModeTracker

View file

@ -5,18 +5,17 @@ namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class CVRPickupObjectTracker : MonoBehaviour
{
private CVRPickupObject _pickupObject;
private Transform _storedGripOrigin;
internal CVRPickupObject _pickupObject;
internal Transform _storedGripOrigin;
public CVRPickupObjectTracker(CVRPickupObject pickupObject, Transform storedGripOrigin)
void Start()
{
this._pickupObject = pickupObject;
this._storedGripOrigin = storedGripOrigin;
VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch;
}
private void OnDestroy()
void OnDestroy()
{
VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch;
}
public void OnPostSwitch(bool intoVR)

View file

@ -1,5 +1,6 @@
using ABI_RC.Core.InteractionSystem;
namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class CVR_InteractableManagerTracker : VRModeTracker

View file

@ -1,5 +1,6 @@
using ABI_RC.Core.InteractionSystem;
namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class CVR_MenuManagerTracker : VRModeTracker

View file

@ -5,21 +5,18 @@ namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class CameraFacingObjectTracker : MonoBehaviour
{
private CameraFacingObject _cameraFacingObject;
internal CameraFacingObject _cameraFacingObject;
public CameraFacingObjectTracker(CameraFacingObject cameraFacingObject)
void Start()
{
this._cameraFacingObject = cameraFacingObject;
VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch;
}
private void OnDestroy()
void OnDestroy()
{
VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch;
}
public void OnPreSwitch(bool intoVR) { }
public void OnFailedSwitch(bool intoVR) { }
public void OnPostSwitch(bool intoVR)
{
_cameraFacingObject.m_Camera = Utils.GetPlayerCameraObject(intoVR).GetComponent<Camera>();

View file

@ -1,5 +1,6 @@
using ABI_RC.Core.Savior;
namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class CheckVRTracker : VRModeTracker

View file

@ -1,5 +1,6 @@
using ABI_RC.Core;
using ABI_RC.Core.UI;
using UnityEngine;
namespace NAK.DesktopVRSwitch.VRModeTrackers;

View file

@ -1,5 +1,6 @@
using ABI_RC.Core.Player;
namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class HudOperationsTracker : VRModeTracker

View file

@ -2,6 +2,7 @@
using ABI_RC.Systems.IK.SubSystems;
using ABI_RC.Systems.IK.TrackingModules;
namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class IKSystemTracker : VRModeTracker

View file

@ -1,9 +1,14 @@
using ABI_RC.Core.Savior;
using UnityEngine;
using UnityEngine.XR;
using Valve.VR;
namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class MetaPortTracker : VRModeTracker
{
private MetaPort _metaPort;
public override void TrackerInit()
{
VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch;
@ -16,7 +21,7 @@ public class MetaPortTracker : VRModeTracker
private void OnPostSwitch(bool intoVR)
{
MetaPort _metaPort = MetaPort.Instance;
_metaPort = MetaPort.Instance;
if (_metaPort == null)
{
DesktopVRSwitch.Logger.Error("Error while getting MetaPort!");
@ -27,6 +32,13 @@ public class MetaPortTracker : VRModeTracker
// Main thing most of the game checks for if using VR
_metaPort.isUsingVr = intoVR;
// replace
UpdateRichPresence();
ResetSteamVROverrides(intoVR);
}
private void UpdateRichPresence()
{
// Hacky way of updating rich presence
if (_metaPort.settings.GetSettingsBool("ImplementationRichPresenceDiscordEnabled", true))
{
@ -41,4 +53,43 @@ public class MetaPortTracker : VRModeTracker
_metaPort.settings.SetSettingsBool("ImplementationRichPresenceSteamEnabled", true);
}
}
private void ResetSteamVROverrides(bool intoVR)
{
if (intoVR)
{
// Testing
XRSettings.eyeTextureResolutionScale = 1;
XRSettings.gameViewRenderMode = DesktopVRSwitch.EntryRenderVRGameView.Value ? GameViewRenderMode.LeftEye : GameViewRenderMode.None;
SteamVR_Settings.instance.pauseGameWhenDashboardVisible = false;
if (MetaPort.Instance.settings.GetSettingsBool("InteractionTobiiEyeTracking", false))
{
MetaPort.Instance.TobiiXrInitializer.Initialize();
}
return;
}
// Reset physics time to Desktop default
Time.fixedDeltaTime = 0.02f;
// Reset queued frames
QualitySettings.maxQueuedFrames = 2;
// Reset framerate target
int graphicsFramerateTarget = MetaPort.Instance.settings.GetSettingInt("GraphicsFramerateTarget", 0);
ABI_RC.Core.CVRTools.SetFramerateTarget(graphicsFramerateTarget);
// Reset VSync setting
bool graphicsVSync = MetaPort.Instance.settings.GetSettingsBool("GraphicsVSync", false);
QualitySettings.vSyncCount = graphicsVSync ? 1 : 0;
// Reset anti-aliasing
int graphicsMsaaLevel = MetaPort.Instance.settings.GetSettingInt("GraphicsMsaaLevel", 0);
QualitySettings.antiAliasing = graphicsMsaaLevel;
// Won't do anything if not already running
MetaPort.Instance.TobiiXrInitializer.DeInitialize();
}
}

View file

@ -1,4 +1,5 @@
using ABI_RC.Systems.MovementSystem;
using UnityEngine;
namespace NAK.DesktopVRSwitch.VRModeTrackers;
@ -12,12 +13,14 @@ public class MovementSystemTracker : VRModeTracker
public override void TrackerInit()
{
VRModeSwitchManager.OnPreVRModeSwitch += OnPreSwitch;
VRModeSwitchManager.OnFailVRModeSwitch += OnFailedSwitch;
VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch;
}
public override void TrackerDestroy()
{
VRModeSwitchManager.OnPreVRModeSwitch -= OnPreSwitch;
VRModeSwitchManager.OnFailVRModeSwitch -= OnFailedSwitch;
VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch;
}
@ -28,10 +31,16 @@ public class MovementSystemTracker : VRModeTracker
preSwitchWorldPosition = Utils.GetPlayerRootPosition();
preSwitchWorldRotation = _movementSystem.rotationPivot.transform.rotation;
_movementSystem.SetImmobilized(true);
_movementSystem.ChangeCrouch(false);
_movementSystem.ChangeProne(false);
}
private void OnFailedSwitch(bool intoVR)
{
_movementSystem.SetImmobilized(false);
}
private void OnPostSwitch(bool intoVR)
{
_movementSystem.rotationPivot = Utils.GetPlayerCameraObject(intoVR).transform;
@ -40,6 +49,7 @@ public class MovementSystemTracker : VRModeTracker
if (!intoVR)
_movementSystem.UpdateColliderCenter(_movementSystem.transform.position);
_movementSystem.SetImmobilized(false);
_movementSystem.ChangeCrouch(false);
_movementSystem.ChangeProne(false);
}

View file

@ -1,5 +1,6 @@
using ABI_RC.Core.Player;
namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class PlayerSetupTracker : VRModeTracker
@ -29,8 +30,11 @@ public class PlayerSetupTracker : VRModeTracker
// This might error if we started in VR.
// '_cam' is not set until Start().
CVR_DesktopCameraController.UpdateFov();
if (CVR_DesktopCameraController._cam == null)
CVR_DesktopCameraController._cam = _playerSetup.desktopCamera.GetComponent<UnityEngine.Camera>();
CVR_DesktopCameraController.UpdateFov();
// UICamera has a script that copies the FOV from the desktop cam.
// Toggling the cameras on/off resets the aspect ratio,
// so when rigs switch, that is already handled.

View file

@ -1,5 +1,6 @@
using ABI_RC.Systems.Camera;
namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class PortableCameraTracker : VRModeTracker

View file

@ -1,178 +0,0 @@
using ABI_RC.Systems.UI;
using System.Collections;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.XR;
using Valve.VR;
/**
I am unsure about this observer approach as only a few things need OnPre and OnFailed switch.
Those wouldn't be needed if I can start OpenVR before all that anyways.
Or... I just start OpenVR and see if it worked. OnPreSwitch would only be needed by menus & transition.
I think I should just use Unity Events as they would allow easier mod support. Subscribe to what you need.
**/
namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class VRModeSwitchManager : MonoBehaviour
{
public static VRModeSwitchManager Instance { get; private set; }
// I don't think I *need* this. Only using cause I don't want stuff just existing.
private static readonly List<VRModeTracker> _vrModeTrackers = new List<VRModeTracker>();
public static event UnityAction<bool> OnPreVRModeSwitch;
public static event UnityAction<bool> OnPostVRModeSwitch;
public static event UnityAction<bool> OnFailVRModeSwitch;
const string XRSETTINGS_DEVICE = "OpenVR";
public static void RegisterVRModeTracker(VRModeTracker observer)
{
_vrModeTrackers.Add(observer);
observer.TrackerInit();
}
public static void UnregisterVRModeTracker(VRModeTracker observer)
{
_vrModeTrackers.Remove(observer);
observer.TrackerDestroy();
}
// Settings
private bool _useWorldTransition = true;
private bool _reloadLocalAvatar = true;
// Internal
private bool _switchInProgress = false;
void Awake()
{
if (Instance != null)
{
DestroyImmediate(this);
return;
}
Instance = this;
}
public void StartSwitch()
{
StartCoroutine(StartSwitchCoroutine());
}
private IEnumerator StartSwitchCoroutine()
{
if (_switchInProgress)
{
yield break;
}
_switchInProgress = true;
yield return null;
if (_useWorldTransition) // start visual transition and wait for it to complete
yield return WorldTransitionSystem.Instance.StartTransitionCoroutine();
// Check if OpenVR is running
bool isUsingVr = IsInVR();
InvokeOnPreSwitch(isUsingVr);
// Start switch
if (!isUsingVr)
{
yield return StartCoroutine(StartSteamVR());
}
else
{
StopSteamVR();
}
// Check for updated VR mode
if (isUsingVr != IsInVR())
{
InvokeOnPostSwitch(!isUsingVr);
// reload the local avatar
// only reload on success
if (_reloadLocalAvatar)
Utils.ReloadLocalAvatar();
}
else
{
InvokeOnFailedSwitch(!isUsingVr);
}
if (_useWorldTransition) // finish the visual transition and wait
yield return WorldTransitionSystem.Instance.ContinueTransitionCoroutine();
_switchInProgress = false;
yield break;
}
private void SafeInvokeUnityEvent(UnityAction<bool> switchEvent, bool isUsingVr)
{
try
{
switchEvent.Invoke(isUsingVr);
}
catch (Exception e)
{
Debug.Log($"Error in event handler: {e}");
}
}
private void InvokeOnPreSwitch(bool isUsingVr)
{
SafeInvokeUnityEvent(OnPreVRModeSwitch, isUsingVr);
}
private void InvokeOnPostSwitch(bool isUsingVr)
{
SafeInvokeUnityEvent(OnPostVRModeSwitch, isUsingVr);
}
private void InvokeOnFailedSwitch(bool isUsingVr)
{
SafeInvokeUnityEvent(OnFailVRModeSwitch, isUsingVr);
}
public bool IsInVR() => XRSettings.enabled;
private IEnumerator StartSteamVR()
{
XRSettings.LoadDeviceByName(XRSETTINGS_DEVICE);
yield return null; // wait a frame before checking
if (!string.IsNullOrEmpty(XRSettings.loadedDeviceName))
{
//SteamVR.Initialize is fucking useless
SteamVR_Behaviour.Initialize(true);
SteamVR_Behaviour.instance.InitializeSteamVR(true);
}
yield return null;
yield break;
}
private void StopSteamVR()
{
// Forces SteamVR to reinitialize SteamVR_Input next switch
SteamVR_ActionSet_Manager.DisableAllActionSets();
SteamVR_Input.initialized = false;
// Remove SteamVR
DestroyImmediate(SteamVR_Behaviour.instance.gameObject);
SteamVR.enabled = false;
// Disable UnityXR
XRSettings.LoadDeviceByName("");
XRSettings.enabled = false;
// We don't really need to wait on Stop()
}
}

View file

@ -1,5 +1,6 @@
using ABI_RC.Core.Player;
namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class VRTrackerManagerTracker : VRModeTracker

View file

@ -1,5 +1,6 @@
using ABI_RC.Core.InteractionSystem;
namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class ViewManagerTracker : VRModeTracker