Class UnityObjectUtils
Small, generalized helpers for Unity object identity checks and component lookup, factored out of the
per-service copies that used to hand-roll them (e.g. the destroyed-object-aware null check that used
to live only in UnityAssetPrefetcherService).
Inheritance
UnityObjectUtils
Assembly: Serenity.UnityGlobal.Infrastructure.dll
Syntax
public static class UnityObjectUtils
Methods
DestroyInAnyMode(Object)
Destroys a Unity object through whichever API the current mode accepts:
UnityEngine.Object.Destroy(UnityEngine.Object) while playing, UnityEngine.Object.DestroyImmediate(UnityEngine.Object)
otherwise. An already-destroyed or null target is left alone.
Declaration
public static void DestroyInAnyMode(Object target)
Parameters
| Type |
Name |
Description |
| Object |
target |
The object to destroy. May be null or already destroyed.
|
GetOrAddComponent<TComponent>(Component)
Returns the existing TComponent on sibling's GameObject, or adds one if none is present.
Declaration
public static TComponent GetOrAddComponent<TComponent>(this Component sibling) where TComponent : Component
Parameters
| Type |
Name |
Description |
| Component |
sibling |
|
Returns
| Type |
Description |
| TComponent |
|
Type Parameters
| Name |
Description |
| TComponent |
|
GetOrAddComponent<TComponent>(GameObject)
Returns the existing TComponent on host, or adds one if none is present.
Declaration
public static TComponent GetOrAddComponent<TComponent>(this GameObject host) where TComponent : Component
Parameters
| Type |
Name |
Description |
| GameObject |
host |
|
Returns
| Type |
Description |
| TComponent |
|
Type Parameters
| Name |
Description |
| TComponent |
|
IsAlive(object)
True when candidate is non-null — and, when it is a UnityEngine.Object,
not destroyed either (Unity's "fake null" case: a managed reference to a native object that has
already been destroyed is correctly treated as gone instead of passing a plain reference-null check).
Declaration
public static bool IsAlive(object candidate)
Parameters
| Type |
Name |
Description |
| object |
candidate |
|
Returns