Update GameObjectInspector.cs

This commit is contained in:
Sinai
2021-05-04 20:39:54 +10:00
parent a89d66cf81
commit 961ff80c6d

View File

@ -98,12 +98,51 @@ namespace UnityExplorer.UI.Inspectors
}
private readonly List<Component> _componentEntries = new List<Component>();
private readonly HashSet<int> _compInstanceIDs = new HashSet<int>();
private List<Component> 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<Component>();
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<string, string> compToStringCache = new Dictionary<string, string>();
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<Component>();
foreach (var comp in comps)
_componentEntries.Add(comp);
ComponentList.RefreshData();
ComponentList.ScrollPool.Refresh(true);
}
protected override void OnCloseClicked()
{
InspectorManager.ReleaseInspector(this);