11using System ;
2+ using System . Collections . Generic ;
23using System . Linq ;
4+ using System . Reflection ;
35using IllusionPlugin ;
46using TMPro ;
57using UnityEngine ;
68using UnityEngine . SceneManagement ;
79using UnityEngine . UI ;
10+ using Zenject ;
811using Object = UnityEngine . Object ;
912
1013namespace PracticePlugin
@@ -18,12 +21,16 @@ public string Name
1821
1922 public string Version
2023 {
21- get { return "v3.0 " ; }
24+ get { return "v3.2 " ; }
2225 }
23-
26+
2427 public const float MaxSize = 5.05f ;
2528 public const float StepSize = 0.05f ;
2629
30+ public const string MenuSceneName = "Menu" ;
31+ public const string GameSceneName = "GameCore" ;
32+ public const string ContextSceneName = "StandardLevel" ;
33+
2734 public static GameObject SettingsObject { get ; private set ; }
2835
2936 public static float TimeScale
@@ -76,17 +83,55 @@ public void OnApplicationStart()
7683 {
7784 if ( _init ) return ;
7885 _init = true ;
79- SceneManager . activeSceneChanged += SceneManagerOnActiveSceneChanged ;
86+ SceneManager . sceneLoaded += SceneManagerOnSceneLoaded ;
87+ }
88+
89+ private void SceneManagerOnActiveSceneChanged ( Scene oldScene , Scene newScene )
90+ {
91+ Console . WriteLine ( "Active scene changed: " + newScene . name ) ;
92+ for ( var i = 0 ; i < SceneManager . sceneCount ; i ++ )
93+ {
94+ var scene = SceneManager . GetSceneAt ( i ) ;
95+ Console . WriteLine ( "Scene loaded!!: " + scene . name ) ;
96+ }
97+
98+ var gameScene = new Scene ( ) ;
99+ if ( ! gameScene . isLoaded ) return ;
100+
101+ Console . WriteLine ( "It's loaded!" ) ;
102+
103+ var effectPoolsInstaller = Resources . FindObjectsOfTypeAll < EffectPoolsInstaller > ( ) . FirstOrDefault ( ) ;
104+ if ( effectPoolsInstaller != null )
105+ {
106+ ReflectionUtil . CopyComponent ( effectPoolsInstaller , typeof ( EffectPoolsInstaller ) , typeof ( CustomEffectPoolsInstaller ) ,
107+ effectPoolsInstaller . gameObject ) ;
108+ Object . DestroyImmediate ( effectPoolsInstaller ) ;
109+
110+ Console . WriteLine ( "Trying to find scene context" ) ;
111+ SceneContext sceneContext = null ;
112+ foreach ( var gameObject in gameScene . GetRootGameObjects ( ) )
113+ {
114+ sceneContext = gameObject . GetComponentInChildren < SceneContext > ( ) ;
115+ if ( sceneContext != null )
116+ {
117+ break ;
118+ }
119+ }
120+
121+ if ( sceneContext == null ) return ;
122+ Console . WriteLine ( "Found it" ) ;
123+ sceneContext . enabled = false ;
124+ }
80125 }
81126
82127 public void OnApplicationQuit ( )
83128 {
84- SceneManager . activeSceneChanged -= SceneManagerOnActiveSceneChanged ;
129+ SceneManager . sceneLoaded -= SceneManagerOnSceneLoaded ;
85130 }
86131
87- private void SceneManagerOnActiveSceneChanged ( Scene arg0 , Scene scene )
132+ private void SceneManagerOnSceneLoaded ( Scene scene , LoadSceneMode mode )
88133 {
89- if ( scene . buildIndex == 1 )
134+ if ( scene . name == MenuSceneName )
90135 {
91136 if ( _resetNoFail )
92137 {
@@ -118,20 +163,60 @@ private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
118163 SettingsObject . GetComponentInChildren < TMP_Text > ( ) . text = "SPEED" ;
119164 Object . DontDestroyOnLoad ( SettingsObject ) ;
120165 }
121- else
166+ else if ( scene . name == GameSceneName )
122167 {
168+ CustomEffectPoolsInstaller customEffectPoolsInstaller = null ;
169+ var effectPoolsInstaller = Resources . FindObjectsOfTypeAll < EffectPoolsInstaller > ( ) . FirstOrDefault ( ) ;
170+ if ( effectPoolsInstaller != null )
171+ {
172+ customEffectPoolsInstaller = ( CustomEffectPoolsInstaller ) ReflectionUtil . CopyComponent ( effectPoolsInstaller ,
173+ typeof ( EffectPoolsInstaller ) , typeof ( CustomEffectPoolsInstaller ) , effectPoolsInstaller . gameObject ) ;
174+ }
175+
176+ SceneContext sceneContext = null ;
177+ SceneDecoratorContext sceneDecoratorContext = null ;
178+
179+ foreach ( var gameObject in scene . GetRootGameObjects ( ) )
180+ {
181+ if ( sceneContext == null )
182+ {
183+ sceneContext = gameObject . GetComponentInChildren < SceneContext > ( true ) ;
184+ }
185+ }
186+
187+ foreach ( var gameObject in SceneManager . GetSceneByName ( ContextSceneName ) . GetRootGameObjects ( ) )
188+ {
189+ if ( sceneDecoratorContext == null )
190+ {
191+ sceneDecoratorContext = gameObject . GetComponentInChildren < SceneDecoratorContext > ( true ) ;
192+
193+ if ( sceneDecoratorContext != null )
194+ {
195+ Console . WriteLine ( "Found one in " + gameObject . name ) ;
196+ }
197+ }
198+ }
199+
200+
201+ if ( sceneContext != null && sceneDecoratorContext != null )
202+ {
203+ Console . WriteLine ( "We're live!" ) ;
204+ var prop = typeof ( Context ) . GetField ( "_installers" , BindingFlags . NonPublic | BindingFlags . Public | BindingFlags . Instance ) ;
205+ var installersList = ( List < MonoInstaller > ) prop . GetValue ( sceneDecoratorContext ) ;
206+ Console . WriteLine ( "There are " + installersList . Count + " installers!" ) ;
207+ installersList . Remove ( effectPoolsInstaller ) ;
208+ Object . DestroyImmediate ( effectPoolsInstaller ) ;
209+ installersList . Add ( customEffectPoolsInstaller ) ;
210+ Console . WriteLine ( "Done!" ) ;
211+ }
212+
123213 if ( _mainGameSceneSetupData == null )
124214 {
125215 _mainGameSceneSetupData = Resources . FindObjectsOfTypeAll < MainGameSceneSetupData > ( ) . FirstOrDefault ( ) ;
126216 if ( _mainGameSceneSetupData == null ) return ;
127217 _mainGameSceneSetupData . didFinishEvent += MainGameSceneSetupDataOnDidFinishEvent ;
128218 }
129219
130- if ( scene . buildIndex != 5 )
131- {
132- return ;
133- }
134-
135220 if ( _lastLevelId != _mainGameSceneSetupData . difficultyLevel . level . levelID &&
136221 ! string . IsNullOrEmpty ( _lastLevelId ) )
137222 {
@@ -161,8 +246,6 @@ private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
161246 TimeScale = Mathf . Clamp ( TimeScale , 1 , MaxSize ) ;
162247 }
163248
164- NoteCutSoundReplacer . ReplacePrefab ( ) ;
165-
166249 var canvas = Resources . FindObjectsOfTypeAll < HorizontalLayoutGroup > ( )
167250 . FirstOrDefault ( x => x . name == "Buttons" )
168251 ? . transform . parent ;
0 commit comments