Skip to content

Commit

Permalink
Added CameraUtils dependency
Browse files Browse the repository at this point in the history
- Removed Camera modifications logic
- Migrated LayerUtils.NoteLayer to CameraUtils.VisibilityLayer enum
- Renamed GameCameraManager to WatermarkManager
  • Loading branch information
Reezonate committed Dec 7, 2022
1 parent 07157d4 commit 22163a5
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 102 deletions.
5 changes: 4 additions & 1 deletion CustomNotes/CustomNotes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<HintPath>$(BeatSaberDir)\Plugins\BSML.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="CameraUtils">
<HintPath>$(BeatSaberDir)\Plugins\CameraUtils.dll</HintPath>
</Reference>
<Reference Include="Colors, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Private>False</Private>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Colors.dll</HintPath>
Expand Down Expand Up @@ -139,7 +142,7 @@
<Compile Include="Managers\CustomBurstSliderController.cs" />
<Compile Include="Managers\CustomNoteController.cs" />
<Compile Include="Managers\CustomNotesViewManager.cs" />
<Compile Include="Managers\GameCameraManager.cs" />
<Compile Include="Managers\WatermarkManager.cs" />
<Compile Include="Managers\MenuButtonManager.cs" />
<Compile Include="Managers\CustomNoteManager.cs" />
<Compile Include="Overrides\CustomNoteColorNoteVisuals.cs" />
Expand Down
2 changes: 1 addition & 1 deletion CustomNotes/Installers/CustomNotesGameInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override void InstallBindings()
_shouldSetup = !autoDisable && (!(_gameplayCoreSceneSetupData.gameplayModifiers.ghostNotes || _gameplayCoreSceneSetupData.gameplayModifiers.disappearingArrows) || !Container.HasBinding<MultiplayerLevelSceneSetupData>());
if (_pluginConfig.Enabled && _noteAssetLoader.SelectedNote != 0 && _shouldSetup)
{
Container.BindInterfacesAndSelfTo<GameCameraManager>().AsSingle();
Container.BindInterfacesAndSelfTo<WatermarkManager>().AsSingle();
Container.Bind<IInitializable>().To<CustomNoteManager>().AsSingle();
CustomNote note = _noteAssetLoader.CustomNoteObjects[_noteAssetLoader.SelectedNote];

Expand Down
42 changes: 0 additions & 42 deletions CustomNotes/Managers/GameCameraManager.cs

This file was deleted.

34 changes: 34 additions & 0 deletions CustomNotes/Managers/WatermarkManager.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
68 changes: 11 additions & 57 deletions CustomNotes/Utilities/LayerUtils.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -33,53 +25,21 @@ public static bool HMDOnly
/// <summary>
/// Note layer type.
/// </summary>
public enum NoteLayer : int
{
Note = 8,
FirstPerson = 24,
ThirdPerson = 8
}

/// <summary>
/// Camera type. Determines culling mask.
/// </summary>
public enum CameraView
{
Default,
FirstPerson,
ThirdPerson
}

/// <summary>
/// Sets the type of a camera to first/third person.
/// </summary>
/// <param name="cam">Camera</param>
/// <param name="view">Type to set the camera to.</param>
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;
}


/// <summary>
/// Recursively sets the layer of a GameObject.
/// </summary>
/// <param name="gameObject">GameObject.</param>
/// <param name="layer">The layer to recursively set.</param>
public static void SetLayer(GameObject gameObject, NoteLayer layer) => SetLayer(gameObject, (int)layer);
public static void SetLayer(GameObject gameObject, VisibilityLayer layer)
{
gameObject.SetLayerRecursively(layer);
}

/// <summary>
/// Recursively sets the layer of a GameObject.
Expand All @@ -88,13 +48,7 @@ public static void SetCamera(Camera cam, CameraView view)
/// <param name="layer">The layer to recursively set.</param>
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<Transform>())
{
t.gameObject.layer = layer;
}
gameObject.SetLayerRecursively((VisibilityLayer)layer);
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion CustomNotes/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 22163a5

Please sign in to comment.