mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 22:27:45 +08:00
Add try/catch to IsNullOrDestroyed
This commit is contained in:
parent
9fe998aa22
commit
66daabf770
@ -9,7 +9,6 @@ using UnityEngine.Events;
|
|||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
// Project-wide namespace for accessibility
|
|
||||||
namespace UnityExplorer
|
namespace UnityExplorer
|
||||||
{
|
{
|
||||||
public static class UnityHelpers
|
public static class UnityHelpers
|
||||||
@ -32,25 +31,28 @@ namespace UnityExplorer
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool IsNullOrDestroyed(this object obj, bool suppressWarning = true)
|
public static bool IsNullOrDestroyed(this object obj, bool suppressWarning = true)
|
||||||
{
|
{
|
||||||
var unityObj = obj as Object;
|
try
|
||||||
if (obj == null)
|
|
||||||
{
|
{
|
||||||
if (!suppressWarning)
|
if (obj == null)
|
||||||
ExplorerCore.LogWarning("The target instance is null!");
|
{
|
||||||
|
if (!suppressWarning)
|
||||||
|
ExplorerCore.LogWarning("The target instance is null!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (obj is Object)
|
else if (obj is Object unityObj && !unityObj)
|
||||||
{
|
|
||||||
if (!unityObj)
|
|
||||||
{
|
{
|
||||||
if (!suppressWarning)
|
if (!suppressWarning)
|
||||||
ExplorerCore.LogWarning("The target UnityEngine.Object was destroyed!");
|
ExplorerCore.LogWarning("The target UnityEngine.Object was destroyed!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user