@@ -18,7 +18,7 @@ public static Scene? SelectedScene
18
18
get => m_selectedScene ;
19
19
internal set
20
20
{
21
- if ( m_selectedScene != null && m_selectedScene ? . handle == value ? . handle )
21
+ if ( m_selectedScene != null && m_selectedScene == value )
22
22
return ;
23
23
m_selectedScene = value ;
24
24
OnInspectedSceneChanged ? . Invoke ( ( Scene ) m_selectedScene ) ;
@@ -37,6 +37,7 @@ internal set
37
37
/// </summary>
38
38
public static ReadOnlyCollection < Scene > LoadedScenes => new ReadOnlyCollection < Scene > ( allLoadedScenes ) ;
39
39
private static readonly List < Scene > allLoadedScenes = new List < Scene > ( ) ;
40
+ private static HashSet < Scene > previousLoadedScenes ;
40
41
41
42
/// <summary>
42
43
/// The names of all scenes in the build settings, if they could be retrieved.
@@ -82,7 +83,7 @@ internal static GameObject DontDestroyMe
82
83
}
83
84
private static GameObject dontDestroyObject ;
84
85
85
- public static bool InspectingAssetScene => ! SelectedScene ? . IsValid ( ) ?? false ;
86
+ public static bool InspectingAssetScene => SelectedScene . HasValue && SelectedScene . Value == default ;
86
87
87
88
internal static void Init ( )
88
89
{
@@ -110,17 +111,9 @@ internal static void Init()
110
111
111
112
internal static void Update ( )
112
113
{
113
- int curHandle = SelectedScene ? . handle ?? - 1 ;
114
- // DontDestroyOnLoad always exists, so default to true if our curHandle is that handle.
115
- // otherwise we will check while iterating.
116
- bool inspectedExists = curHandle == DontDestroyHandle || curHandle == 0 ;
117
-
118
- // Quick sanity check if the loaded scenes changed
119
- bool anyChange = LoadedSceneCount != allLoadedScenes . Count ;
120
- // otherwise keep a lookup table of the previous handles to check if the list changed at all.
121
- HashSet < int > previousHandles = null ;
122
- if ( ! anyChange )
123
- previousHandles = new HashSet < int > ( allLoadedScenes . Select ( it => it . handle ) ) ;
114
+ // check if the loaded scenes changed. always confirm DontDestroy / HideAndDontSave
115
+ int confirmedCount = 2 ;
116
+ bool inspectedExists = SelectedScene == DontDestroyScene || ( SelectedScene . HasValue && SelectedScene . Value == default ) ;
124
117
125
118
allLoadedScenes . Clear ( ) ;
126
119
@@ -130,20 +123,22 @@ internal static void Update()
130
123
if ( scene == default || ! scene . isLoaded )
131
124
continue ;
132
125
133
- // If no changes yet, ensure the previous list contained this handle.
134
- if ( ! anyChange && ! previousHandles . Contains ( scene . handle ) )
135
- anyChange = true ;
126
+ // If no changes yet, ensure the previous list contained the scene
127
+ if ( previousLoadedScenes != null && previousLoadedScenes . Contains ( scene ) )
128
+ confirmedCount ++ ;
136
129
137
130
// If we have not yet confirmed inspectedExists, check if this scene is our currently inspected one.
138
- if ( curHandle != - 1 && ! inspectedExists && scene . handle == curHandle )
131
+ if ( ! inspectedExists && scene == SelectedScene )
139
132
inspectedExists = true ;
140
133
141
134
allLoadedScenes . Add ( scene ) ;
142
135
}
143
136
144
- // Always add the DontDestroyOnLoad scene and the "none" scene.
137
+ bool anyChange = confirmedCount != allLoadedScenes . Count ;
138
+
145
139
allLoadedScenes . Add ( DontDestroyScene ) ;
146
140
allLoadedScenes . Add ( default ) ;
141
+ previousLoadedScenes = new HashSet < Scene > ( allLoadedScenes ) ;
147
142
148
143
// Default to first scene if none selected or previous selection no longer exists.
149
144
if ( ! inspectedExists )
@@ -163,14 +158,14 @@ internal static void Update()
163
158
else
164
159
{
165
160
var allObjects = RuntimeProvider . Instance . FindObjectsOfTypeAll ( typeof ( GameObject ) ) ;
166
- var list = new List < GameObject > ( ) ;
161
+ var objects = new List < GameObject > ( ) ;
167
162
foreach ( var obj in allObjects )
168
163
{
169
164
var go = obj . TryCast < GameObject > ( ) ;
170
165
if ( go . transform . parent == null && ! go . scene . IsValid ( ) )
171
- list . Add ( go ) ;
166
+ objects . Add ( go ) ;
172
167
}
173
- rootObjects = list . ToArray ( ) ;
168
+ rootObjects = objects . ToArray ( ) ;
174
169
}
175
170
}
176
171
}
0 commit comments