diff --git a/CustomNotes/CustomNotes.csproj b/CustomNotes/CustomNotes.csproj index 9127fe7..f5ede19 100644 --- a/CustomNotes/CustomNotes.csproj +++ b/CustomNotes/CustomNotes.csproj @@ -45,6 +45,9 @@ $(BeatSaberDir)\Plugins\BSML.dll False + + $(BeatSaberDir)\Plugins\CameraUtils.dll + False $(BeatSaberDir)\Beat Saber_Data\Managed\Colors.dll @@ -139,7 +142,7 @@ - + diff --git a/CustomNotes/Installers/CustomNotesGameInstaller.cs b/CustomNotes/Installers/CustomNotesGameInstaller.cs index 9cd5de7..e90f18b 100644 --- a/CustomNotes/Installers/CustomNotesGameInstaller.cs +++ b/CustomNotes/Installers/CustomNotesGameInstaller.cs @@ -35,7 +35,7 @@ public override void InstallBindings() _shouldSetup = !autoDisable && (!(_gameplayCoreSceneSetupData.gameplayModifiers.ghostNotes || _gameplayCoreSceneSetupData.gameplayModifiers.disappearingArrows) || !Container.HasBinding()); if (_pluginConfig.Enabled && _noteAssetLoader.SelectedNote != 0 && _shouldSetup) { - Container.BindInterfacesAndSelfTo().AsSingle(); + Container.BindInterfacesAndSelfTo().AsSingle(); Container.Bind().To().AsSingle(); CustomNote note = _noteAssetLoader.CustomNoteObjects[_noteAssetLoader.SelectedNote]; diff --git a/CustomNotes/Managers/GameCameraManager.cs b/CustomNotes/Managers/GameCameraManager.cs deleted file mode 100644 index ca71053..0000000 --- a/CustomNotes/Managers/GameCameraManager.cs +++ /dev/null @@ -1,42 +0,0 @@ -using CustomNotes.Settings.Utilities; -using CustomNotes.Utilities; -using System; -using UnityEngine; -using Zenject; - -namespace CustomNotes.Managers -{ - public class GameCameraManager : IInitializable, IDisposable - { - public Camera MainCamera { get; } - - private PluginConfig _pluginConfig; - - [Inject] - internal GameCameraManager(PluginConfig pluginConfig, Camera mainCamera) - { - _pluginConfig = pluginConfig; - MainCamera = mainCamera; - } - - public void Initialize() - { - Logger.log.Debug($"Initializing {nameof(GameCameraManager)}!"); - if (_pluginConfig.HMDOnly || LayerUtils.HMDOverride) - { - LayerUtils.CreateWatermark(); - LayerUtils.SetCamera(MainCamera, LayerUtils.CameraView.FirstPerson); - } - } - - public void Dispose() - { - Logger.log.Debug($"Disposing {nameof(GameCameraManager)}!"); - LayerUtils.DestroyWatermark(); - if (_pluginConfig.HMDOnly || LayerUtils.HMDOverride) - { - LayerUtils.SetCamera(MainCamera, LayerUtils.CameraView.Default); - } - } - } -} diff --git a/CustomNotes/Managers/WatermarkManager.cs b/CustomNotes/Managers/WatermarkManager.cs new file mode 100644 index 0000000..21007c4 --- /dev/null +++ b/CustomNotes/Managers/WatermarkManager.cs @@ -0,0 +1,34 @@ +using CustomNotes.Settings.Utilities; +using CustomNotes.Utilities; +using System; +using Zenject; + +namespace CustomNotes.Managers +{ + public class WatermarkManager : IInitializable, IDisposable + { + + private PluginConfig _pluginConfig; + + [Inject] + internal WatermarkManager(PluginConfig pluginConfig) + { + _pluginConfig = pluginConfig; + } + + public void Initialize() + { + Logger.log.Debug($"Initializing {nameof(WatermarkManager)}!"); + if (_pluginConfig.HMDOnly || LayerUtils.HMDOverride) + { + LayerUtils.CreateWatermark(); + } + } + + public void Dispose() + { + Logger.log.Debug($"Disposing {nameof(WatermarkManager)}!"); + LayerUtils.DestroyWatermark(); + } + } +} diff --git a/CustomNotes/Utilities/LayerUtils.cs b/CustomNotes/Utilities/LayerUtils.cs index dce3ac6..b5d2bc7 100644 --- a/CustomNotes/Utilities/LayerUtils.cs +++ b/CustomNotes/Utilities/LayerUtils.cs @@ -1,16 +1,8 @@ -using CustomNotes.Data; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using UnityEngine; -using BeatSaberMarkupLanguage.ViewControllers; -using BeatSaberMarkupLanguage.FloatingScreen; +using UnityEngine; using BeatSaberMarkupLanguage; +using CameraUtils.Core; using TMPro; using HMUI; -using UnityEngine.UI; using CustomNotes.Settings.Utilities; namespace CustomNotes.Utilities @@ -33,53 +25,21 @@ public static bool HMDOnly /// /// Note layer type. /// - public enum NoteLayer : int - { - Note = 8, - FirstPerson = 24, - ThirdPerson = 8 - } - - /// - /// Camera type. Determines culling mask. - /// - public enum CameraView - { - Default, - FirstPerson, - ThirdPerson - } - - /// - /// Sets the type of a camera to first/third person. - /// - /// Camera - /// Type to set the camera to. - public static void SetCamera(Camera cam, CameraView view) - { - if (cam == null) return; - switch(view) - { - default: - case CameraView.Default: - case CameraView.ThirdPerson: - cam.cullingMask &= ~(1 << (int) NoteLayer.FirstPerson); - cam.cullingMask |= 1 << (int) NoteLayer.ThirdPerson; - break; - case CameraView.FirstPerson: - cam.cullingMask &= ~(1 << (int) NoteLayer.ThirdPerson); - cam.cullingMask |= 1 << (int) NoteLayer.FirstPerson; - break; - } + public static class NoteLayer { + public const VisibilityLayer Note = VisibilityLayer.Note; + public const VisibilityLayer FirstPerson = VisibilityLayer.HmdOnlyAndReflected; + public const VisibilityLayer ThirdPerson = VisibilityLayer.DesktopOnlyAndReflected; } - /// /// Recursively sets the layer of a GameObject. /// /// GameObject. /// The layer to recursively set. - public static void SetLayer(GameObject gameObject, NoteLayer layer) => SetLayer(gameObject, (int)layer); + public static void SetLayer(GameObject gameObject, VisibilityLayer layer) + { + gameObject.SetLayerRecursively(layer); + } /// /// Recursively sets the layer of a GameObject. @@ -88,13 +48,7 @@ public static void SetCamera(Camera cam, CameraView view) /// The layer to recursively set. public static void SetLayer(GameObject gameObject, int layer) { - if (gameObject == null) return; - if (gameObject.layer == layer) return; - gameObject.layer = layer; - foreach (Transform t in gameObject.GetComponentsInChildren()) - { - t.gameObject.layer = layer; - } + gameObject.SetLayerRecursively((VisibilityLayer)layer); } /// diff --git a/CustomNotes/manifest.json b/CustomNotes/manifest.json index 8533514..2f189c2 100644 --- a/CustomNotes/manifest.json +++ b/CustomNotes/manifest.json @@ -14,7 +14,8 @@ "BSIPA": "^4.2.1", "BeatSaberMarkupLanguage": "^1.6.0", "SiraUtil": "^3.0.6", - "SongCore": "^3.0.0" + "SongCore": "^3.0.0", + "CameraUtils": "^1.0.0" }, "links": { "project-home": "https://github.com/legoandmars/BeatSaberCustomNotes",