Skip to content

Commit

Permalink
Merge pull request xyonico#25 from DeadlyKitten/master
Browse files Browse the repository at this point in the history
Updated Plugin to Beat Saber v0.13.0
  • Loading branch information
Assistant authored Mar 18, 2019
2 parents b97add3 + ca03c12 commit 38bb9d7
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 83 deletions.
3 changes: 2 additions & 1 deletion CustomAvatar-Editor/CustomAvatar-Editor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(TargetDir)$(TargetName).dll" "$(BeatSaberUnityProject)\Assets\"</PostBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>
86 changes: 52 additions & 34 deletions CustomAvatar/AvatarEventsPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.SceneManagement;

Expand All @@ -25,31 +24,50 @@ public void Restart()

private void _Restart()
{
OnDestroy();
Start();
CleanUp();
}

private void Start()
private void OnEnable()
{
SceneManager.sceneLoaded += SceneManagerOnSceneLoaded;

_eventManager = gameObject.GetComponent<EventManager>();
}

private void OnDestroy()
private void OnDisable()
{
if (_scoreController == null) return;
_scoreController.noteWasCutEvent -= SliceCallBack;
_scoreController.noteWasMissedEvent -= NoteMissCallBack;
_scoreController.multiplierDidChangeEvent -= MultiplierCallBack;
_scoreController.comboDidChangeEvent -= ComboChangeEvent;
SceneManager.sceneLoaded -= SceneManagerOnSceneLoaded;
}

_saberCollisionManager.sparkleEffectDidStartEvent -= SaberStartCollide;
_saberCollisionManager.sparkleEffectDidEndEvent -= SaberEndCollide;
private void OnDestroy()
{
CleanUp();
}

_gameEnergyCounter.gameEnergyDidReach0Event -= FailLevelCallBack;
private void CleanUp()
{
if (_scoreController)
{
_scoreController.noteWasCutEvent -= SliceCallBack;
_scoreController.noteWasMissedEvent -= NoteMissCallBack;
_scoreController.multiplierDidChangeEvent -= MultiplierCallBack;
_scoreController.comboDidChangeEvent -= ComboChangeEvent;
}

if (_saberCollisionManager)
{
_saberCollisionManager.sparkleEffectDidStartEvent -= SaberStartCollide;
_saberCollisionManager.sparkleEffectDidEndEvent -= SaberEndCollide;
}

if (_gameEnergyCounter)
_gameEnergyCounter.gameEnergyDidReach0Event -= FailLevelCallBack;

if (_beatmapObjectCallbackController)
_beatmapObjectCallbackController.beatmapEventDidTriggerEvent -= OnBeatmapEventDidTriggerEvent;

_beatmapObjectCallbackController.beatmapEventDidTriggerEvent -= OnBeatmapEventDidTriggerEvent;
_beatmapDataModel.beatmapDataDidChangeEvent -= BeatmapDataChangedCallback;
if (_beatmapDataModel)
_beatmapDataModel.beatmapDataDidChangeEvent -= BeatmapDataChangedCallback;
}

private void SceneManagerOnSceneLoaded(Scene newScene, LoadSceneMode mode)
Expand All @@ -74,19 +92,19 @@ private void SceneManagerOnSceneLoaded(Scene newScene, LoadSceneMode mode)
_scoreController.multiplierDidChangeEvent += MultiplierCallBack;
_scoreController.comboDidChangeEvent += ComboChangeEvent;

if (_saberCollisionManager != null)
if (_saberCollisionManager)
{
_saberCollisionManager.sparkleEffectDidStartEvent += SaberStartCollide;
_saberCollisionManager.sparkleEffectDidEndEvent += SaberEndCollide;
}

if (_gameEnergyCounter != null) _gameEnergyCounter.gameEnergyDidReach0Event += FailLevelCallBack;
if (_gameEnergyCounter) _gameEnergyCounter.gameEnergyDidReach0Event += FailLevelCallBack;

if (_beatmapObjectCallbackController != null)
if (_beatmapObjectCallbackController)
_beatmapObjectCallbackController.beatmapEventDidTriggerEvent += OnBeatmapEventDidTriggerEvent;

_lastNoteId = -1;
if (_beatmapDataModel != null)
if (_beatmapDataModel)
{
_beatmapDataModel.beatmapDataDidChangeEvent += BeatmapDataChangedCallback;
BeatmapDataChangedCallback();
Expand All @@ -109,77 +127,77 @@ private void SliceCallBack(NoteData noteData, NoteCutInfo noteCutInfo, int multi
{
if (!noteCutInfo.allIsOK)
{
_eventManager.OnComboBreak?.Invoke();
_eventManager?.OnComboBreak?.Invoke();
}
else
{
_eventManager.OnSlice?.Invoke();
_eventManager?.OnSlice?.Invoke();
}

if (noteData.id == _lastNoteId)
{
_eventManager.OnLevelFinish?.Invoke();
_eventManager?.OnLevelFinish?.Invoke();
}
}

private void NoteMissCallBack(NoteData noteData, int multiplier)
{
if (noteData.noteType != NoteType.Bomb)
{
_eventManager.OnComboBreak?.Invoke();
_eventManager?.OnComboBreak?.Invoke();
}
}

private void MultiplierCallBack(int multiplier, float progress)
{
if (multiplier > 1 && progress < 0.1f)
{
_eventManager.MultiplierUp?.Invoke();
_eventManager?.MultiplierUp?.Invoke();
}
}

private void SaberStartCollide(Saber.SaberType saber)
{
_eventManager.SaberStartColliding?.Invoke();
_eventManager?.SaberStartColliding?.Invoke();
}

private void SaberEndCollide(Saber.SaberType saber)
{
_eventManager.SaberStopColliding?.Invoke();
_eventManager?.SaberStopColliding?.Invoke();
}

private void FailLevelCallBack()
{
_eventManager.OnLevelFail?.Invoke();
_eventManager?.OnLevelFail?.Invoke();
}

private void OnBeatmapEventDidTriggerEvent (BeatmapEventData beatmapEventData)
private void OnBeatmapEventDidTriggerEvent(BeatmapEventData beatmapEventData)
{
if ((int) beatmapEventData.type >= 5) return;
if (beatmapEventData == null || (int) beatmapEventData.type >= 5) return;

if (beatmapEventData.value > 0 && beatmapEventData.value < 4)
{
_eventManager.OnBlueLightOn?.Invoke();
_eventManager?.OnBlueLightOn?.Invoke();
}

if (beatmapEventData.value > 4 && beatmapEventData.value < 8)
{
_eventManager.OnRedLightOn?.Invoke();
_eventManager?.OnRedLightOn?.Invoke();
}
}

private void ComboChangeEvent(int combo)
{
_eventManager.OnComboChanged?.Invoke(combo);
_eventManager?.OnComboChanged?.Invoke(combo);
}

public void MenuEnteredEvent()
{
_eventManager.OnMenuEnter?.Invoke();
_eventManager?.OnMenuEnter?.Invoke();
}
public void LevelStartedEvent()
{
_eventManager.OnLevelStart?.Invoke();
_eventManager?.OnLevelStart?.Invoke();
}
}
}
4 changes: 2 additions & 2 deletions CustomAvatar/AvatarSpawner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;

namespace CustomAvatar
{
Expand Down Expand Up @@ -26,4 +26,4 @@ public static SpawnedAvatar SpawnAvatar(CustomAvatar customAvatar, IAvatarInput
return spawnedAvatar;
}
}
}
}
36 changes: 15 additions & 21 deletions CustomAvatar/CustomAvatar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,24 @@
<DefineConstants>PLUGIN</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
</Reference>
<Reference Include="BeatSaberCustomUI">
</Reference>
<Reference Include="IllusionPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
</Reference>
<Reference Include="Assembly-CSharp" />
<Reference Include="BeatSaberCustomUI" />
<Reference Include="IllusionPlugin" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="TextMeshPro-1.0.55.2017.1.0b12, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Reference Include="UnityEngine.AnimationModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Reference Include="UnityEngine.AssetBundleModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Reference Include="UnityEngine.AudioModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Reference Include="UnityEngine.ParticleSystemModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Reference Include="UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="UnityEngine.VRModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Reference Include="UnityEngine.XRModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Reference Include="Unity.TextMeshPro" />
<Reference Include="UnityEngine" />
<Reference Include="UnityEngine.AnimationModule" />
<Reference Include="UnityEngine.AssetBundleModule" />
<Reference Include="UnityEngine.AudioModule" />
<Reference Include="UnityEngine.CoreModule" />
<Reference Include="UnityEngine.ParticleSystemModule" />
<Reference Include="UnityEngine.PhysicsModule" />
<Reference Include="UnityEngine.UI" />
<Reference Include="UnityEngine.VRModule" />
<Reference Include="UnityEngine.XRModule" />
</ItemGroup>
<ItemGroup>
<Compile Include="AvatarBehaviour.cs" />
Expand Down Expand Up @@ -104,6 +97,7 @@
<Compile Include="PosRot.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SpawnedAvatar.cs" />
<Compile Include="UI\AvatarCellInfo.cs" />
<Compile Include="UI\AvatarListViewController.cs" />
<Compile Include="UI\AvatarSettingsViewController.cs" />
<Compile Include="UI\AvatarPreviewController.cs" />
Expand Down
8 changes: 6 additions & 2 deletions CustomAvatar/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public string Name

public string Version
{
get { return "4.5.0"; }
get { return "4.6.0"; }
}

public static void Log(object message)
Expand Down Expand Up @@ -231,7 +231,11 @@ private void SceneManagerOnSceneLoaded(Scene newScene, LoadSceneMode mode)
private void SceneTransitionDidFinish()
{
Camera mainCamera = Camera.main;
SetCameraCullingMask(mainCamera);

if (mainCamera)
{
SetCameraCullingMask(mainCamera);
}

PlayerAvatarManager?.OnSceneTransitioned(SceneManager.GetActiveScene());
}
Expand Down
4 changes: 2 additions & 2 deletions CustomAvatar/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.5.0.0")]
[assembly: AssemblyFileVersion("4.5.0.0")]
[assembly: AssemblyVersion("4.6.0.0")]
[assembly: AssemblyFileVersion("4.6.0.0")]
36 changes: 36 additions & 0 deletions CustomAvatar/UI/AvatarCellInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using UnityEngine;

namespace CustomAvatar
{
class AvatarCellInfo : IPreviewBeatmapLevel
{
#region Aliases

public string name { get; set; }
public string subName { get; set; }
public string authorName { get; set; }

#endregion

#region Properties

public string levelID => null;
public string songName => name;
public string songSubName => subName;
public string songAuthorName => authorName;
public string levelAuthorName => null;
public float beatsPerMinute => 0f;
public float songTimeOffset => 0f;
public float shuffle => 0f;
public float shufflePeriod => 0f;
public AudioClip previewAudioClip => null;
public float previewStartTime => 0f;
public float previewDuration => 0f;
public float songDuration => 0f;
public Sprite coverImage { get; set; }
public SceneInfo environmentSceneInfo => null;
public BeatmapCharacteristicSO[] beatmapCharacteristics => new BeatmapCharacteristicSO[0];

#endregion
}
}
Loading

0 comments on commit 38bb9d7

Please sign in to comment.