From 961ff80c6d5b665203b90f114b808e338e4deb80 Mon Sep 17 00:00:00 2001 From: Sinai Date: Tue, 4 May 2021 20:39:54 +1000 Subject: [PATCH] Update GameObjectInspector.cs --- src/UI/Inspectors/GameObjectInspector.cs | 50 ++++++++++++++++++------ 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/src/UI/Inspectors/GameObjectInspector.cs b/src/UI/Inspectors/GameObjectInspector.cs index 5a81d75..6f392c1 100644 --- a/src/UI/Inspectors/GameObjectInspector.cs +++ b/src/UI/Inspectors/GameObjectInspector.cs @@ -98,12 +98,51 @@ namespace UnityExplorer.UI.Inspectors } private readonly List _componentEntries = new List(); + private readonly HashSet _compInstanceIDs = new HashSet(); private List GetComponentEntries() { return _componentEntries; } + private void UpdateComponents() + { + // Check if we actually need to refresh the component cells or not. + // Doing this check is far more efficient than blindly setting cells. + + var comps = GOTarget.GetComponents(); + + bool needRefresh = false; + if (comps.Length != _componentEntries.Count) + needRefresh = true; + else + { + foreach (var comp in comps) + { + if (!_compInstanceIDs.Contains(comp.GetInstanceID())) + { + needRefresh = true; + break; + } + } + } + + if (!needRefresh) + return; + + _componentEntries.Clear(); + _compInstanceIDs.Clear(); + + foreach (var comp in comps) + { + _componentEntries.Add(comp); + _compInstanceIDs.Add(comp.GetInstanceID()); + } + + ComponentList.RefreshData(); + ComponentList.ScrollPool.Refresh(true); + } + private static readonly Dictionary compToStringCache = new Dictionary(); private void SetComponentCell(ButtonCell cell, int index) @@ -139,17 +178,6 @@ namespace UnityExplorer.UI.Inspectors InspectorManager.Inspect(comp); } - private void UpdateComponents() - { - _componentEntries.Clear(); - var comps = GOTarget.GetComponents(); - foreach (var comp in comps) - _componentEntries.Add(comp); - - ComponentList.RefreshData(); - ComponentList.ScrollPool.Refresh(true); - } - protected override void OnCloseClicked() { InspectorManager.ReleaseInspector(this);