@@ -17,9 +17,7 @@ public class ScenePage : WindowPage
17
17
public PageHelper Pages = new PageHelper ( ) ;
18
18
19
19
private float m_timeOfLastUpdate = - 1f ;
20
- private static int PASSIVE_UPDATE_INTERVAL = 1 ;
21
-
22
- private static bool m_getRootObjectsFailed = false ;
20
+ private const int PASSIVE_UPDATE_INTERVAL = 1 ;
23
21
24
22
// ----- Holders for GUI elements ----- //
25
23
@@ -54,7 +52,7 @@ public void SetTransformTarget(Transform t)
54
52
if ( m_searching )
55
53
CancelSearch ( ) ;
56
54
57
- Update_Impl ( ) ;
55
+ Update_Impl ( true ) ;
58
56
}
59
57
60
58
public void TraverseUp ( )
@@ -90,11 +88,12 @@ public List<GameObjectCache> SearchSceneObjects(string _search)
90
88
{
91
89
var matches = new List < GameObjectCache > ( ) ;
92
90
93
- foreach ( var obj in Resources . FindObjectsOfTypeAll < GameObject > ( ) )
91
+ foreach ( var obj in Resources . FindObjectsOfTypeAll ( ReflectionHelpers . GameObjectType ) )
94
92
{
95
- if ( obj . name . ToLower ( ) . Contains ( _search . ToLower ( ) ) && obj . scene . name == m_currentScene )
93
+ var go = obj . TryCast < GameObject > ( ) ;
94
+ if ( go . name . ToLower ( ) . Contains ( _search . ToLower ( ) ) && go . scene . name == m_currentScene )
96
95
{
97
- matches . Add ( new GameObjectCache ( obj ) ) ;
96
+ matches . Add ( new GameObjectCache ( go ) ) ;
98
97
}
99
98
}
100
99
@@ -111,9 +110,9 @@ public override void Update()
111
110
Update_Impl ( ) ;
112
111
}
113
112
114
- private void Update_Impl ( )
113
+ private void Update_Impl ( bool manual = false )
115
114
{
116
- var allTransforms = new List < Transform > ( ) ;
115
+ List < Transform > allTransforms = new List < Transform > ( ) ;
117
116
118
117
// get current list of all transforms (either scene root or our current transform children)
119
118
if ( m_currentTransform )
@@ -125,30 +124,26 @@ private void Update_Impl()
125
124
}
126
125
else
127
126
{
128
- if ( ! m_getRootObjectsFailed )
127
+ if ( ! manual && m_getRootObjectsFailed ) return ;
128
+
129
+ if ( ! manual )
129
130
{
130
131
try
131
132
{
132
- var list = SceneManager . GetSceneByName ( m_currentScene )
133
- . GetRootGameObjects ( )
134
- . ToArray ( ) ;
133
+ var scene = SceneManager . GetSceneByName ( m_currentScene ) ;
135
134
136
- foreach ( var obj in list )
137
- {
138
- allTransforms . Add ( obj . transform ) ;
139
- }
135
+ allTransforms . AddRange ( scene . GetRootGameObjects ( )
136
+ . Select ( it => it . transform ) ) ;
140
137
}
141
138
catch
142
139
{
143
140
m_getRootObjectsFailed = true ;
144
- PASSIVE_UPDATE_INTERVAL = 2 ;
145
-
146
- allTransforms = GetRootObjectsManual_Impl ( ) ;
141
+ allTransforms . AddRange ( GetRootObjectsManual_Impl ( ) ) ;
147
142
}
148
143
}
149
144
else
150
145
{
151
- allTransforms = GetRootObjectsManual_Impl ( ) ;
146
+ allTransforms . AddRange ( GetRootObjectsManual_Impl ( ) ) ;
152
147
}
153
148
}
154
149
@@ -168,14 +163,30 @@ private void Update_Impl()
168
163
}
169
164
}
170
165
171
- private List < Transform > GetRootObjectsManual_Impl ( )
166
+ private IEnumerable < Transform > GetRootObjectsManual_Impl ( )
172
167
{
173
- var allTransforms = Resources . FindObjectsOfTypeAll < Transform > ( )
174
- . Where ( x => x . parent == null
175
- && x . gameObject . scene . name == m_currentScene )
176
- . ToList ( ) ;
168
+ try
169
+ {
170
+ var array = Resources . FindObjectsOfTypeAll ( ReflectionHelpers . TransformType ) ;
177
171
178
- return allTransforms ;
172
+ var list = new List < Transform > ( ) ;
173
+ foreach ( var obj in array )
174
+ {
175
+ var transform = obj . TryCast < Transform > ( ) ;
176
+ if ( transform . parent == null && transform . gameObject . scene . name == m_currentScene )
177
+ {
178
+ list . Add ( transform ) ;
179
+ }
180
+ }
181
+ return list ;
182
+ }
183
+ catch ( Exception e )
184
+ {
185
+ MelonLogger . Log ( "Exception getting root scene objects (manual): "
186
+ + e . GetType ( ) + ", " + e . Message + "\r \n "
187
+ + e . StackTrace ) ;
188
+ return new Transform [ 0 ] ;
189
+ }
179
190
}
180
191
181
192
// --------- GUI Draw Function --------- //
@@ -277,7 +288,7 @@ private void DrawPageButtons()
277
288
{
278
289
Pages . TurnPage ( Turn . Left , ref this . scroll ) ;
279
290
280
- Update_Impl ( ) ;
291
+ Update_Impl ( true ) ;
281
292
}
282
293
283
294
Pages . CurrentPageLabel ( ) ;
@@ -286,7 +297,7 @@ private void DrawPageButtons()
286
297
{
287
298
Pages . TurnPage ( Turn . Right , ref this . scroll ) ;
288
299
289
- Update_Impl ( ) ;
300
+ Update_Impl ( true ) ;
290
301
}
291
302
}
292
303
@@ -316,6 +327,14 @@ private void DrawGameObjectList()
316
327
else
317
328
{
318
329
GUILayout . Label ( "Scene Root GameObjects:" , null ) ;
330
+
331
+ if ( m_getRootObjectsFailed )
332
+ {
333
+ if ( GUILayout . Button ( "Update Root Object List (auto-update failed!)" , null ) )
334
+ {
335
+ Update_Impl ( true ) ;
336
+ }
337
+ }
319
338
}
320
339
321
340
if ( m_objectList . Count > 0 )
0 commit comments