Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Commit c397e02

Browse files
committed
Fixed the speed settings showing up in non-no fail mode. Fixed the level fail slow down being overwritten by the plugin.
1 parent 48d8362 commit c397e02

2 files changed

Lines changed: 42 additions & 14 deletions

File tree

PracticePlugin/Plugin.cs

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,47 @@ namespace PracticePlugin
1313
{
1414
public class Plugin : IPlugin
1515
{
16-
public static float TimeScale = 1;
1716
public static GameObject SettingsObject;
17+
18+
public static float TimeScale
19+
{
20+
get { return _timeScale; }
21+
set
22+
{
23+
_timeScale = value;
24+
if (_songAudio != null)
25+
{
26+
_songAudio.pitch = _timeScale;
27+
}
28+
29+
if (_noteCutAudioSource != null)
30+
{
31+
_noteCutAudioSource.pitch = _timeScale;
32+
}
33+
}
34+
}
35+
private static float _timeScale = 1;
36+
37+
public static bool Enabled
38+
{
39+
get { return _enabled; }
40+
set
41+
{
42+
_enabled = value;
43+
if (!_enabled)
44+
{
45+
TimeScale = 1;
46+
}
47+
}
48+
}
49+
50+
private static bool _enabled;
1851

19-
private bool _enabled;
2052
private bool _init;
2153
private MainGameSceneSetupData _mainGameSceneSetupData;
2254
private AudioTimeSyncController _audioTimeSync;
23-
private AudioSource _songAudio;
24-
private AudioSource _noteCutAudioSource;
55+
private static AudioSource _songAudio;
56+
private static AudioSource _noteCutAudioSource;
2557
private string _lastLevelId;
2658

2759
public string Name
@@ -31,7 +63,7 @@ public string Name
3163

3264
public string Version
3365
{
34-
get { return "v1.0"; }
66+
get { return "v1.1"; }
3567
}
3668

3769
public void OnApplicationStart()
@@ -87,7 +119,7 @@ private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
87119
_audioTimeSync = Resources.FindObjectsOfTypeAll<AudioTimeSyncController>().FirstOrDefault();
88120
_audioTimeSync.forcedAudioSync = true;
89121
_songAudio = ReflectionUtil.GetPrivateField<AudioSource>(_audioTimeSync, "_audioSource");
90-
_enabled = _mainGameSceneSetupData.gameplayOptions.noEnergy;
122+
Enabled = _mainGameSceneSetupData.gameplayOptions.noEnergy;
91123
var noteCutSoundEffectManager = Resources.FindObjectsOfTypeAll<NoteCutSoundEffectManager>().FirstOrDefault();
92124
var noteCutSoundEffect =
93125
ReflectionUtil.GetPrivateField<NoteCutSoundEffect>(noteCutSoundEffectManager, "_noteCutSoundEffectPrefab");
@@ -97,6 +129,7 @@ private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
97129
var canvas = Resources.FindObjectsOfTypeAll<HorizontalLayoutGroup>().FirstOrDefault(x => x.name == "Buttons")
98130
.transform.parent;
99131
canvas.gameObject.AddComponent<SpeedSettingsCreator>();
132+
TimeScale = TimeScale;
100133
}
101134
}
102135

@@ -112,14 +145,7 @@ public void OnLevelWasInitialized(int level)
112145

113146
public void OnUpdate()
114147
{
115-
if (_songAudio == null) return;
116-
if (!_enabled)
117-
{
118-
TimeScale = 1;
119-
}
120-
121-
_noteCutAudioSource.pitch = TimeScale;
122-
_songAudio.pitch = TimeScale;
148+
123149
}
124150

125151
public void OnFixedUpdate()

PracticePlugin/SpeedSettingsCreator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class SpeedSettingsCreator : MonoBehaviour
99

1010
private void OnEnable()
1111
{
12+
if (!Plugin.Enabled) return;
1213
_speedSettings = Instantiate(Plugin.SettingsObject, transform);
1314
_speedSettings.SetActive(true);
1415
_speedSettings.GetComponent<SpeedSettingsController>().Init();
@@ -20,6 +21,7 @@ private void OnEnable()
2021

2122
private void OnDisable()
2223
{
24+
if (_speedSettings == null) return;
2325
DestroyImmediate(_speedSettings);
2426
}
2527
}

0 commit comments

Comments
 (0)