mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-03 06:49:22 +00:00
[DesktopVRSwitch] Wait frame on MovementSystem OnPostSwitch.
testing
This commit is contained in:
parent
0fb7c3d401
commit
52d4ef3279
8 changed files with 123 additions and 48 deletions
|
@ -7,8 +7,6 @@ namespace NAK.DesktopVRSwitch.VRModeTrackers;
|
|||
|
||||
public class MetaPortTracker : VRModeTracker
|
||||
{
|
||||
private MetaPort _metaPort;
|
||||
|
||||
public override void TrackerInit()
|
||||
{
|
||||
VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch;
|
||||
|
@ -21,7 +19,7 @@ public class MetaPortTracker : VRModeTracker
|
|||
|
||||
private void OnPostSwitch(bool intoVR)
|
||||
{
|
||||
_metaPort = MetaPort.Instance;
|
||||
MetaPort _metaPort = MetaPort.Instance;
|
||||
if (_metaPort == null)
|
||||
{
|
||||
DesktopVRSwitch.Logger.Error("Error while getting MetaPort!");
|
||||
|
@ -33,11 +31,11 @@ public class MetaPortTracker : VRModeTracker
|
|||
_metaPort.isUsingVr = intoVR;
|
||||
|
||||
// replace
|
||||
UpdateRichPresence();
|
||||
UpdateRichPresence(_metaPort);
|
||||
ResetSteamVROverrides(intoVR);
|
||||
}
|
||||
|
||||
private void UpdateRichPresence()
|
||||
private void UpdateRichPresence(MetaPort _metaPort)
|
||||
{
|
||||
// Hacky way of updating rich presence
|
||||
if (_metaPort.settings.GetSettingsBool("ImplementationRichPresenceDiscordEnabled", true))
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
using ABI_RC.Systems.MovementSystem;
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.DesktopVRSwitch.VRModeTrackers;
|
||||
|
||||
public class MovementSystemTracker : VRModeTracker
|
||||
{
|
||||
private MovementSystem _movementSystem;
|
||||
private Vector3 preSwitchWorldPosition;
|
||||
private Quaternion preSwitchWorldRotation;
|
||||
|
||||
|
@ -24,33 +23,68 @@ public class MovementSystemTracker : VRModeTracker
|
|||
VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch;
|
||||
}
|
||||
|
||||
private MovementSystem GetMovementSystemInstance()
|
||||
{
|
||||
MovementSystem _movementSystem = MovementSystem.Instance;
|
||||
if (_movementSystem == null)
|
||||
{
|
||||
DesktopVRSwitch.Logger.Error("Error while getting MovementSystem!");
|
||||
}
|
||||
return _movementSystem;
|
||||
}
|
||||
|
||||
private void OnPreSwitch(bool intoVR)
|
||||
{
|
||||
_movementSystem = MovementSystem.Instance;
|
||||
MovementSystem _movementSystem = GetMovementSystemInstance();
|
||||
if (_movementSystem != null)
|
||||
{
|
||||
DesktopVRSwitch.Logger.Msg("Storing player world position and rotation.");
|
||||
preSwitchWorldPosition = _movementSystem.rotationPivot.transform.position;
|
||||
preSwitchWorldPosition.y = _movementSystem.transform.position.y;
|
||||
preSwitchWorldRotation = _movementSystem.rotationPivot.transform.rotation;
|
||||
|
||||
preSwitchWorldPosition = Utils.GetPlayerRootPosition();
|
||||
preSwitchWorldRotation = _movementSystem.rotationPivot.transform.rotation;
|
||||
|
||||
_movementSystem.SetImmobilized(true);
|
||||
_movementSystem.ChangeCrouch(false);
|
||||
_movementSystem.ChangeProne(false);
|
||||
_movementSystem.ChangeCrouch(false);
|
||||
_movementSystem.ChangeProne(false);
|
||||
_movementSystem.SetImmobilized(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFailedSwitch(bool intoVR)
|
||||
{
|
||||
_movementSystem.SetImmobilized(false);
|
||||
MovementSystem _movementSystem = GetMovementSystemInstance();
|
||||
if (_movementSystem != null)
|
||||
{
|
||||
DesktopVRSwitch.Logger.Msg("Resetting MovementSystem mobility.");
|
||||
_movementSystem.SetImmobilized(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPostSwitch(bool intoVR)
|
||||
{
|
||||
_movementSystem.rotationPivot = Utils.GetPlayerCameraObject(intoVR).transform;
|
||||
_movementSystem.TeleportToPosRot(preSwitchWorldPosition, preSwitchWorldRotation, false);
|
||||
// Lazy
|
||||
MelonLoader.MelonCoroutines.Start(TeleportFrameAfter(intoVR));
|
||||
}
|
||||
|
||||
if (!intoVR)
|
||||
_movementSystem.UpdateColliderCenter(_movementSystem.transform.position);
|
||||
private IEnumerator TeleportFrameAfter(bool intoVR)
|
||||
{
|
||||
yield return null; // need to wait a frame
|
||||
|
||||
_movementSystem.SetImmobilized(false);
|
||||
_movementSystem.ChangeCrouch(false);
|
||||
_movementSystem.ChangeProne(false);
|
||||
MovementSystem _movementSystem = GetMovementSystemInstance();
|
||||
if (_movementSystem != null)
|
||||
{
|
||||
DesktopVRSwitch.Logger.Msg("Resetting MovementSystem mobility and applying stored position and rotation.");
|
||||
|
||||
_movementSystem.rotationPivot = Utils.GetPlayerCameraObject(intoVR).transform;
|
||||
_movementSystem.TeleportToPosRot(preSwitchWorldPosition, preSwitchWorldRotation, false);
|
||||
|
||||
if (!intoVR)
|
||||
_movementSystem.UpdateColliderCenter(_movementSystem.transform.position);
|
||||
|
||||
_movementSystem.ChangeCrouch(false);
|
||||
_movementSystem.ChangeProne(false);
|
||||
_movementSystem.SetImmobilized(false);
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
}
|
|
@ -34,7 +34,7 @@ public class PlayerSetupTracker : VRModeTracker
|
|||
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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue