@@ -11,9 +11,7 @@ namespace UnityExplorer.ObjectExplorer
11
11
{
12
12
public static class SceneHandler
13
13
{
14
- /// <summary>
15
- /// The currently inspected Scene.
16
- /// </summary>
14
+ /// <summary>The currently inspected Scene.</summary>
17
15
public static Scene ? SelectedScene
18
16
{
19
17
get => selectedScene ;
@@ -27,63 +25,39 @@ internal set
27
25
}
28
26
private static Scene ? selectedScene ;
29
27
30
- /// <summary>
31
- /// The GameObjects in the currently inspected scene.
32
- /// </summary>
28
+ /// <summary>The GameObjects in the currently inspected scene.</summary>
33
29
public static GameObject [ ] CurrentRootObjects { get ; private set ; } = new GameObject [ 0 ] ;
34
30
35
- /// <summary>
36
- /// All currently loaded Scenes.
37
- /// </summary>
38
- public static List < Scene > LoadedScenes { get ; private set ; } = new List < Scene > ( ) ;
31
+ /// <summary>All currently loaded Scenes.</summary>
32
+ public static List < Scene > LoadedScenes { get ; private set ; } = new ( ) ;
39
33
private static HashSet < Scene > previousLoadedScenes ;
40
34
41
- /// <summary>
42
- /// The names of all scenes in the build settings, if they could be retrieved.
43
- /// </summary>
44
- public static readonly List < string > AllSceneNames = new List < string > ( ) ;
35
+ /// <summary>The names of all scenes in the build settings, if they could be retrieved.</summary>
36
+ public static List < string > AllSceneNames { get ; private set ; } = new ( ) ;
45
37
46
- /// <summary>
47
- /// Whether or not we successfuly retrieved the names of the scenes in the build settings.
48
- /// </summary>
49
- public static bool WasAbleToGetScenesInBuild { get ; private set ; }
50
-
51
- /// <summary>
52
- /// Invoked when the currently inspected Scene changes. The argument is the new scene.
53
- /// </summary>
38
+ /// <summary>Invoked when the currently inspected Scene changes. The argument is the new scene.</summary>
54
39
public static event Action < Scene > OnInspectedSceneChanged ;
55
40
56
- /// <summary>
57
- /// Invoked whenever the list of currently loaded Scenes changes. The argument contains all loaded scenes after the change.
58
- /// </summary>
41
+ /// <summary>Invoked whenever the list of currently loaded Scenes changes. The argument contains all loaded scenes after the change.</summary>
59
42
public static event Action < List < Scene > > OnLoadedScenesChanged ;
60
43
61
- /// <summary>
62
- /// Equivalent to <see cref="SceneManager.sceneCount"/> + 2, to include 'DontDestroyOnLoad' and the 'None' scene.
63
- /// </summary>
64
- public static int LoadedSceneCount => SceneManager . sceneCount + 2 ;
44
+ /// <summary>Generally will be 2, unless DontDestroyExists == false, then this will be 1.</summary>
45
+ internal static int DefaultSceneCount => 1 + ( DontDestroyExists ? 1 : 0 ) ;
65
46
66
- internal static Scene DontDestroyScene => DontDestroyMe . scene ;
67
- internal static int DontDestroyHandle => DontDestroyScene . handle ;
47
+ /// <summary>Whether or not we are currently inspecting the "HideAndDontSave" asset scene.</summary>
48
+ public static bool InspectingAssetScene => SelectedScene . HasValue && SelectedScene . Value == default ;
68
49
69
- internal static GameObject DontDestroyMe
70
- {
71
- get
72
- {
73
- if ( ! dontDestroyObject )
74
- {
75
- dontDestroyObject = new GameObject ( "DontDestroyMe" ) ;
76
- GameObject . DontDestroyOnLoad ( dontDestroyObject ) ;
77
- }
78
- return dontDestroyObject ;
79
- }
80
- }
81
- private static GameObject dontDestroyObject ;
50
+ /// <summary>Whether or not we successfuly retrieved the names of the scenes in the build settings.</summary>
51
+ public static bool WasAbleToGetScenesInBuild { get ; private set ; }
82
52
83
- public static bool InspectingAssetScene => SelectedScene . HasValue && SelectedScene . Value == default ;
53
+ /// <summary>Whether or not the "DontDestroyOnLoad" scene exists in this game.</summary>
54
+ public static bool DontDestroyExists { get ; private set ; }
84
55
85
56
internal static void Init ( )
86
57
{
58
+ // Check if the game has "DontDestroyOnLoad"
59
+ DontDestroyExists = Scene . GetNameInternal ( - 12 ) == "DontDestroyOnLoad" ;
60
+
87
61
// Try to get all scenes in the build settings. This may not work.
88
62
try
89
63
{
@@ -111,8 +85,9 @@ internal static void Init()
111
85
internal static void Update ( )
112
86
{
113
87
// check if the loaded scenes changed. always confirm DontDestroy / HideAndDontSave
114
- int confirmedCount = 2 ;
115
- bool inspectedExists = SelectedScene == DontDestroyScene || ( SelectedScene . HasValue && SelectedScene . Value == default ) ;
88
+ int confirmedCount = DefaultSceneCount ;
89
+ bool inspectedExists = ( SelectedScene . HasValue && SelectedScene . Value . handle == - 12 )
90
+ || ( SelectedScene . HasValue && SelectedScene . Value . handle == - 1 ) ;
116
91
117
92
LoadedScenes . Clear ( ) ;
118
93
@@ -133,8 +108,9 @@ internal static void Update()
133
108
LoadedScenes . Add ( scene ) ;
134
109
}
135
110
136
- LoadedScenes . Add ( DontDestroyScene ) ;
137
- LoadedScenes . Add ( default ) ;
111
+ if ( DontDestroyExists )
112
+ LoadedScenes . Add ( new Scene { m_Handle = - 12 } ) ;
113
+ LoadedScenes . Add ( new Scene { m_Handle = - 1 } ) ;
138
114
139
115
bool anyChange = confirmedCount != LoadedScenes . Count ;
140
116
0 commit comments