mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-17 14:37:49 +08:00
Get rid of pointless ReadOnlyCollection properties
This commit is contained in:
parent
adfa29e63c
commit
36fc17aa43
@ -29,14 +29,12 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The GameObjects in the currently inspected scene.
|
/// The GameObjects in the currently inspected scene.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static ReadOnlyCollection<GameObject> CurrentRootObjects => new ReadOnlyCollection<GameObject>(rootObjects);
|
public static GameObject[] CurrentRootObjects { get; private set; } = new GameObject[0];
|
||||||
private static GameObject[] rootObjects = new GameObject[0];
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All currently loaded Scenes.
|
/// All currently loaded Scenes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static ReadOnlyCollection<Scene> LoadedScenes => new ReadOnlyCollection<Scene>(allLoadedScenes);
|
public static List<Scene> LoadedScenes { get; private set; } = new List<Scene>();
|
||||||
private static readonly List<Scene> allLoadedScenes = new List<Scene>();
|
|
||||||
private static HashSet<Scene> previousLoadedScenes;
|
private static HashSet<Scene> previousLoadedScenes;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -59,7 +57,7 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked whenever the list of currently loaded Scenes changes. The argument contains all loaded scenes after the change.
|
/// Invoked whenever the list of currently loaded Scenes changes. The argument contains all loaded scenes after the change.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static event Action<ReadOnlyCollection<Scene>> OnLoadedScenesChanged;
|
public static event Action<List<Scene>> OnLoadedScenesChanged;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Equivalent to <see cref="SceneManager.sceneCount"/> + 2, to include 'DontDestroyOnLoad' and the 'None' scene.
|
/// Equivalent to <see cref="SceneManager.sceneCount"/> + 2, to include 'DontDestroyOnLoad' and the 'None' scene.
|
||||||
@ -115,7 +113,7 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
int confirmedCount = 2;
|
int confirmedCount = 2;
|
||||||
bool inspectedExists = SelectedScene == DontDestroyScene || (SelectedScene.HasValue && SelectedScene.Value == default);
|
bool inspectedExists = SelectedScene == DontDestroyScene || (SelectedScene.HasValue && SelectedScene.Value == default);
|
||||||
|
|
||||||
allLoadedScenes.Clear();
|
LoadedScenes.Clear();
|
||||||
|
|
||||||
for (int i = 0; i < SceneManager.sceneCount; i++)
|
for (int i = 0; i < SceneManager.sceneCount; i++)
|
||||||
{
|
{
|
||||||
@ -131,30 +129,26 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
if (!inspectedExists && scene == SelectedScene)
|
if (!inspectedExists && scene == SelectedScene)
|
||||||
inspectedExists = true;
|
inspectedExists = true;
|
||||||
|
|
||||||
allLoadedScenes.Add(scene);
|
LoadedScenes.Add(scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool anyChange = confirmedCount != allLoadedScenes.Count;
|
bool anyChange = confirmedCount != LoadedScenes.Count;
|
||||||
|
|
||||||
allLoadedScenes.Add(DontDestroyScene);
|
LoadedScenes.Add(DontDestroyScene);
|
||||||
allLoadedScenes.Add(default);
|
LoadedScenes.Add(default);
|
||||||
previousLoadedScenes = new HashSet<Scene>(allLoadedScenes);
|
previousLoadedScenes = new HashSet<Scene>(LoadedScenes);
|
||||||
|
|
||||||
// Default to first scene if none selected or previous selection no longer exists.
|
// Default to first scene if none selected or previous selection no longer exists.
|
||||||
if (!inspectedExists)
|
if (!inspectedExists)
|
||||||
{
|
SelectedScene = LoadedScenes.First();
|
||||||
SelectedScene = allLoadedScenes.First();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notify on the list changing at all
|
// Notify on the list changing at all
|
||||||
if (anyChange)
|
if (anyChange)
|
||||||
{
|
|
||||||
OnLoadedScenesChanged?.Invoke(LoadedScenes);
|
OnLoadedScenesChanged?.Invoke(LoadedScenes);
|
||||||
}
|
|
||||||
|
|
||||||
// Finally, update the root objects list.
|
// Finally, update the root objects list.
|
||||||
if (SelectedScene != null && ((Scene)SelectedScene).IsValid())
|
if (SelectedScene != null && ((Scene)SelectedScene).IsValid())
|
||||||
rootObjects = RuntimeProvider.Instance.GetRootGameObjects((Scene)SelectedScene);
|
CurrentRootObjects = RuntimeProvider.Instance.GetRootGameObjects((Scene)SelectedScene);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var allObjects = RuntimeProvider.Instance.FindObjectsOfTypeAll(typeof(GameObject));
|
var allObjects = RuntimeProvider.Instance.FindObjectsOfTypeAll(typeof(GameObject));
|
||||||
@ -165,7 +159,7 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
if (go.transform.parent == null && !go.scene.IsValid())
|
if (go.transform.parent == null && !go.scene.IsValid())
|
||||||
objects.Add(go);
|
objects.Add(go);
|
||||||
}
|
}
|
||||||
rootObjects = objects.ToArray();
|
CurrentRootObjects = objects.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user