Add try/catch to IsNullOrDestroyed

This commit is contained in:
Sinai 2021-10-12 20:20:08 +11:00
parent 9fe998aa22
commit 66daabf770

View File

@ -9,7 +9,6 @@ using UnityEngine.Events;
using UnityEngine.UI;
using Object = UnityEngine.Object;
// Project-wide namespace for accessibility
namespace UnityExplorer
{
public static class UnityHelpers
@ -32,7 +31,8 @@ namespace UnityExplorer
/// </summary>
public static bool IsNullOrDestroyed(this object obj, bool suppressWarning = true)
{
var unityObj = obj as Object;
try
{
if (obj == null)
{
if (!suppressWarning)
@ -40,18 +40,20 @@ namespace UnityExplorer
return true;
}
else if (obj is Object)
{
if (!unityObj)
else if (obj is Object unityObj && !unityObj)
{
if (!suppressWarning)
ExplorerCore.LogWarning("The target UnityEngine.Object was destroyed!");
return true;
}
}
return false;
}
catch
{
return false;
}
}
/// <summary>
/// Get the full Transform heirarchy path for this provided Transform.