using ABI_RC.Systems.MovementSystem; using UnityEngine; namespace NAK.DesktopVRSwitch.VRModeTrackers; public class MovementSystemTracker : VRModeTracker { private MovementSystem _movementSystem; private Vector3 preSwitchWorldPosition; private Quaternion preSwitchWorldRotation; 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; } private void OnPreSwitch(bool intoVR) { _movementSystem = MovementSystem.Instance; 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; _movementSystem.TeleportToPosRot(preSwitchWorldPosition, preSwitchWorldRotation, false); if (!intoVR) _movementSystem.UpdateColliderCenter(_movementSystem.transform.position); _movementSystem.SetImmobilized(false); _movementSystem.ChangeCrouch(false); _movementSystem.ChangeProne(false); } }