@@ -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 ( )
0 commit comments