@@ -17,10 +17,11 @@ public static Scene? SelectedScene
17
17
get => selectedScene ;
18
18
internal set
19
19
{
20
- if ( selectedScene != null && selectedScene == value )
20
+ if ( selectedScene . HasValue && selectedScene == value )
21
21
return ;
22
22
selectedScene = value ;
23
23
OnInspectedSceneChanged ? . Invoke ( ( Scene ) selectedScene ) ;
24
+ ExplorerCore . Log ( $ "Set selected scene to { value ? . name } ") ;
24
25
}
25
26
}
26
27
private static Scene ? selectedScene ;
@@ -30,7 +31,7 @@ internal set
30
31
31
32
/// <summary>All currently loaded Scenes.</summary>
32
33
public static List < Scene > LoadedScenes { get ; private set ; } = new ( ) ;
33
- private static HashSet < Scene > previousLoadedScenes ;
34
+ // private static HashSet<Scene> previousLoadedScenes;
34
35
35
36
/// <summary>The names of all scenes in the build settings, if they could be retrieved.</summary>
36
37
public static List < string > AllSceneNames { get ; private set ; } = new ( ) ;
@@ -39,7 +40,7 @@ internal set
39
40
public static event Action < Scene > OnInspectedSceneChanged ;
40
41
41
42
/// <summary>Invoked whenever the list of currently loaded Scenes changes. The argument contains all loaded scenes after the change.</summary>
42
- public static event Action < List < Scene > > OnLoadedScenesChanged ;
43
+ public static event Action < List < Scene > > OnLoadedScenesUpdated ;
43
44
44
45
/// <summary>Generally will be 2, unless DontDestroyExists == false, then this will be 1.</summary>
45
46
internal static int DefaultSceneCount => 1 + ( DontDestroyExists ? 1 : 0 ) ;
@@ -84,23 +85,20 @@ internal static void Init()
84
85
85
86
internal static void Update ( )
86
87
{
87
- // check if the loaded scenes changed. always confirm DontDestroy / HideAndDontSave
88
- int confirmedCount = DefaultSceneCount ;
89
- bool inspectedExists = ( SelectedScene . HasValue && SelectedScene . Value . handle == - 12 )
90
- || ( SelectedScene . HasValue && SelectedScene . Value . handle == - 1 ) ;
88
+ // Inspected scene will exist if it's DontDestroyOnLoad or HideAndDontSave
89
+ bool inspectedExists =
90
+ SelectedScene . HasValue
91
+ && ( ( DontDestroyExists && SelectedScene . Value . handle == - 12 )
92
+ || SelectedScene . Value . handle == - 1 ) ;
91
93
92
94
LoadedScenes . Clear ( ) ;
93
95
94
96
for ( int i = 0 ; i < SceneManager . sceneCount ; i ++ )
95
97
{
96
98
Scene scene = SceneManager . GetSceneAt ( i ) ;
97
- if ( scene == default || ! scene . isLoaded )
99
+ if ( scene == default || ! scene . isLoaded || ! scene . IsValid ( ) )
98
100
continue ;
99
101
100
- // If no changes yet, ensure the previous list contained the scene
101
- if ( previousLoadedScenes != null && previousLoadedScenes . Contains ( scene ) )
102
- confirmedCount ++ ;
103
-
104
102
// If we have not yet confirmed inspectedExists, check if this scene is our currently inspected one.
105
103
if ( ! inspectedExists && scene == SelectedScene )
106
104
inspectedExists = true ;
@@ -112,17 +110,12 @@ internal static void Update()
112
110
LoadedScenes . Add ( new Scene { m_Handle = - 12 } ) ;
113
111
LoadedScenes . Add ( new Scene { m_Handle = - 1 } ) ;
114
112
115
- bool anyChange = confirmedCount != LoadedScenes . Count ;
116
-
117
- previousLoadedScenes = new HashSet < Scene > ( LoadedScenes ) ;
118
-
119
113
// Default to first scene if none selected or previous selection no longer exists.
120
114
if ( ! inspectedExists )
121
115
SelectedScene = LoadedScenes . First ( ) ;
122
116
123
117
// Notify on the list changing at all
124
- if ( anyChange )
125
- OnLoadedScenesChanged ? . Invoke ( LoadedScenes ) ;
118
+ OnLoadedScenesUpdated ? . Invoke ( LoadedScenes ) ;
126
119
127
120
// Finally, update the root objects list.
128
121
if ( SelectedScene != null && ( ( Scene ) SelectedScene ) . IsValid ( ) )
0 commit comments