From 36fc17aa43c41366c2c6dc8f3f16fdba29bc0436 Mon Sep 17 00:00:00 2001 From: Sinai <49360850+sinai-dev@users.noreply.github.com> Date: Mon, 19 Jul 2021 21:43:16 +1000 Subject: [PATCH] Get rid of pointless ReadOnlyCollection properties --- src/ObjectExplorer/SceneHandler.cs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/ObjectExplorer/SceneHandler.cs b/src/ObjectExplorer/SceneHandler.cs index 7768ec6..bb37217 100644 --- a/src/ObjectExplorer/SceneHandler.cs +++ b/src/ObjectExplorer/SceneHandler.cs @@ -29,14 +29,12 @@ namespace UnityExplorer.ObjectExplorer /// /// The GameObjects in the currently inspected scene. /// - public static ReadOnlyCollection CurrentRootObjects => new ReadOnlyCollection(rootObjects); - private static GameObject[] rootObjects = new GameObject[0]; + public static GameObject[] CurrentRootObjects { get; private set; } = new GameObject[0]; /// /// All currently loaded Scenes. /// - public static ReadOnlyCollection LoadedScenes => new ReadOnlyCollection(allLoadedScenes); - private static readonly List allLoadedScenes = new List(); + public static List LoadedScenes { get; private set; } = new List(); private static HashSet previousLoadedScenes; /// @@ -59,7 +57,7 @@ namespace UnityExplorer.ObjectExplorer /// /// Invoked whenever the list of currently loaded Scenes changes. The argument contains all loaded scenes after the change. /// - public static event Action> OnLoadedScenesChanged; + public static event Action> OnLoadedScenesChanged; /// /// Equivalent to + 2, to include 'DontDestroyOnLoad' and the 'None' scene. @@ -115,7 +113,7 @@ namespace UnityExplorer.ObjectExplorer int confirmedCount = 2; bool inspectedExists = SelectedScene == DontDestroyScene || (SelectedScene.HasValue && SelectedScene.Value == default); - allLoadedScenes.Clear(); + LoadedScenes.Clear(); for (int i = 0; i < SceneManager.sceneCount; i++) { @@ -131,30 +129,26 @@ namespace UnityExplorer.ObjectExplorer if (!inspectedExists && scene == SelectedScene) inspectedExists = true; - allLoadedScenes.Add(scene); + LoadedScenes.Add(scene); } - bool anyChange = confirmedCount != allLoadedScenes.Count; + bool anyChange = confirmedCount != LoadedScenes.Count; - allLoadedScenes.Add(DontDestroyScene); - allLoadedScenes.Add(default); - previousLoadedScenes = new HashSet(allLoadedScenes); + LoadedScenes.Add(DontDestroyScene); + LoadedScenes.Add(default); + previousLoadedScenes = new HashSet(LoadedScenes); // Default to first scene if none selected or previous selection no longer exists. if (!inspectedExists) - { - SelectedScene = allLoadedScenes.First(); - } + SelectedScene = LoadedScenes.First(); // Notify on the list changing at all if (anyChange) - { OnLoadedScenesChanged?.Invoke(LoadedScenes); - } // Finally, update the root objects list. if (SelectedScene != null && ((Scene)SelectedScene).IsValid()) - rootObjects = RuntimeProvider.Instance.GetRootGameObjects((Scene)SelectedScene); + CurrentRootObjects = RuntimeProvider.Instance.GetRootGameObjects((Scene)SelectedScene); else { var allObjects = RuntimeProvider.Instance.FindObjectsOfTypeAll(typeof(GameObject)); @@ -165,7 +159,7 @@ namespace UnityExplorer.ObjectExplorer if (go.transform.parent == null && !go.scene.IsValid()) objects.Add(go); } - rootObjects = objects.ToArray(); + CurrentRootObjects = objects.ToArray(); } } }