diff --git a/Source/CustomAvatar/Player/GameEnvironmentObjectManager.cs b/Source/CustomAvatar/Player/GameEnvironmentObjectManager.cs index 7c849dab..8a02bf66 100644 --- a/Source/CustomAvatar/Player/GameEnvironmentObjectManager.cs +++ b/Source/CustomAvatar/Player/GameEnvironmentObjectManager.cs @@ -128,13 +128,14 @@ private void HandleBeatLeaderSpectatorCamera() var controller = (Component)_container.TryResolve(BeatLeaderReflection.kCameraControllerType); var originComponent = (Component)_container.TryResolve(BeatLeaderReflection.kOriginComponentType); + Camera camera = BeatLeaderReflection.kCameraField(controller); - if (controller == null || originComponent == null) + if (controller == null || originComponent == null || camera == null) { return; } - SpectatorCamera spectatorCameraController = _container.InstantiateComponent(BeatLeaderReflection.kCameraField(controller).gameObject); + SpectatorCamera spectatorCameraController = _container.InstantiateComponent(camera.gameObject); spectatorCameraController.origin = BeatLeaderReflection.kReplayerCoreGetter(originComponent); spectatorCameraController.playerSpace = BeatLeaderReflection.kReplayerCenterAdjustGetter(originComponent); } diff --git a/Source/CustomAvatar/Rendering/MainCamera.cs b/Source/CustomAvatar/Rendering/MainCamera.cs index fa393eac..0445762c 100644 --- a/Source/CustomAvatar/Rendering/MainCamera.cs +++ b/Source/CustomAvatar/Rendering/MainCamera.cs @@ -68,16 +68,19 @@ private void OnEnable() { if (_settings != null) { + _settings.cameraNearClipPlane.changed -= OnCameraNearClipPlaneChanged; _settings.cameraNearClipPlane.changed += OnCameraNearClipPlaneChanged; } if (_fpfcSettings != null) { + _fpfcSettings.Changed -= OnFpfcSettingsChanged; _fpfcSettings.Changed += OnFpfcSettingsChanged; } if (_beatSaberUtilities != null) { + _beatSaberUtilities.focusChanged -= OnFocusChanged; _beatSaberUtilities.focusChanged += OnFocusChanged; OnFocusChanged(_beatSaberUtilities.hasFocus); } @@ -153,10 +156,13 @@ private void OnFpfcSettingsChanged(IFPFCSettings fpfcSettings) private void OnFocusChanged(bool hasFocus) { - _trackedPoseDriver.UseRelativeTransform = !hasFocus; - _trackedPoseDriver.originPose = hasFocus ? Pose.identity : new Pose( - Vector3.Project(Quaternion.Euler(0, 180, 0) * -transform.localPosition * 2, Vector3.right) + new Vector3(0, 0, 1.5f), - Quaternion.Euler(0, 180, 0)); + if (_trackedPoseDriver != null) + { + _trackedPoseDriver.UseRelativeTransform = !hasFocus; + _trackedPoseDriver.originPose = hasFocus ? Pose.identity : new Pose( + Vector3.Project(Quaternion.Euler(0, 180, 0) * -transform.localPosition * 2, Vector3.right) + new Vector3(0, 0, 1.5f), + Quaternion.Euler(0, 180, 0)); + } UpdateCameraMask(); }