Failsafe in case Component is null from GetComponents?

This commit is contained in:
Sinai 2021-06-07 19:27:09 +10:00
parent a72877befb
commit 91671bf243

View File

@ -147,32 +147,39 @@ namespace UnityExplorer.UI.Inspectors
var behaviours = GOTarget.GetComponents<Behaviour>(); var behaviours = GOTarget.GetComponents<Behaviour>();
bool needRefresh = false; bool needRefresh = false;
if (comps.Length != componentEntries.Count || behaviours.Length != behaviourEntries.Count)
{
needRefresh = true;
}
else
{
foreach (var comp in comps)
{
if (!compInstanceIDs.Contains(comp.GetInstanceID()))
{
needRefresh = true;
break;
}
}
if (!needRefresh) int count = 0;
foreach (var comp in comps)
{
if (!comp)
continue;
count++;
if (!compInstanceIDs.Contains(comp.GetInstanceID()))
{ {
for (int i = 0; i < behaviours.Length; i++) needRefresh = true;
break;
}
}
if (!needRefresh)
{
if (count != componentEntries.Count)
needRefresh = true;
else
{
count = 0;
foreach (var behaviour in behaviours)
{ {
var behaviour = behaviours[i]; if (!behaviour)
if (behaviour.enabled != behaviourEnabledStates[i]) continue;
if (count >= behaviourEnabledStates.Count || behaviour.enabled != behaviourEnabledStates[count])
{ {
needRefresh = true; needRefresh = true;
break; break;
} }
count++;
} }
if (!needRefresh && count != behaviourEntries.Count)
needRefresh = true;
} }
} }
@ -181,9 +188,9 @@ namespace UnityExplorer.UI.Inspectors
componentEntries.Clear(); componentEntries.Clear();
compInstanceIDs.Clear(); compInstanceIDs.Clear();
foreach (var comp in comps) foreach (var comp in comps)
{ {
if (!comp) continue;
componentEntries.Add(comp); componentEntries.Add(comp);
compInstanceIDs.Add(comp.GetInstanceID()); compInstanceIDs.Add(comp.GetInstanceID());
} }
@ -192,6 +199,7 @@ namespace UnityExplorer.UI.Inspectors
behaviourEnabledStates.Clear(); behaviourEnabledStates.Clear();
foreach (var behaviour in behaviours) foreach (var behaviour in behaviours)
{ {
if (!behaviour) continue;
behaviourEntries.Add(behaviour); behaviourEntries.Add(behaviour);
behaviourEnabledStates.Add(behaviour.enabled); behaviourEnabledStates.Add(behaviour.enabled);
} }
@ -211,7 +219,7 @@ namespace UnityExplorer.UI.Inspectors
private void OnAddComponentClicked(string input) private void OnAddComponentClicked(string input)
{ {
if (ReflectionUtility.AllTypes.TryGetValue(input, out Type type)) if (ReflectionUtility.GetTypeByName(input) is Type type)
{ {
try try
{ {