NAK_CVR_Mods/DesktopVRSwitch/VRModeTrackers/PlayerSetupTracker.cs
2023-06-19 19:44:23 -05:00

38 lines
No EOL
1.2 KiB
C#

using ABI_RC.Core.Player;
namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class PlayerSetupTracker : VRModeTracker
{
public override void TrackerInit()
{
VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch;
}
public override void TrackerDestroy()
{
VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch;
}
private void OnPostSwitch(bool intoVR)
{
PlayerSetup _playerSetup = PlayerSetup.Instance;
if (_playerSetup == null)
{
DesktopVRSwitch.Logger.Error("Error while getting PlayerSetup!");
return;
}
DesktopVRSwitch.Logger.Msg("Switching active PlayerSetup camera rigs. Updating Desktop camera FOV.");
_playerSetup.desktopCameraRig.SetActive(!intoVR);
_playerSetup.vrCameraRig.SetActive(intoVR);
// This might error if we started in VR.
// '_cam' is not set until Start().
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.
}
}