Class UnityObjectUtils
Utility methods for working with UnityEngine Object types.
Inherited Members
Namespace: Unity.XR.CoreUtils
Syntax
public static class UnityObjectUtils
Methods
ConvertUnityObjectToType<T>(Object)
Returns a component of the specified type that is associated with an object, if possible.
Declaration
public static T ConvertUnityObjectToType<T>(Object objectIn)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Object | objectIn | The Unity Object reference to convert. |
Returns
Type | Description |
---|---|
T | A component of type |
Type Parameters
Name | Description |
---|---|
T | The type to convert to. |
Remarks
If the objectIn
is the requested type, then this function casts it to
type T and returns it.
If objectIn
is a GameObject, then this function returns
the first component of the requested type, if one exists.
If objectIn
is a different type of component, this function returns
the first component of the requested type on the same GameObject, if one exists.
Destroy(Object, Boolean)
Calls the proper Destroy method on an object based on if application is playing.
Declaration
public static void Destroy(Object obj, bool withUndo = false)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | Object to be destroyed. |
Boolean | withUndo | Whether to record and undo operation for the destroy action. |
Remarks
In Play mode or when running your built application, this function calls Destroy.
In the Editor, outside of Play mode, this function calls DestroyImmediate.
RemoveDestroyedKeys<TKey, TValue>(Dictionary<TKey, TValue>)
Removes any destroyed keys from a dictionary that uses UnityObjects as its key type.
Declaration
public static void RemoveDestroyedKeys<TKey, TValue>(Dictionary<TKey, TValue> dictionary)
where TKey : Object
Parameters
Type | Name | Description |
---|---|---|
Dictionary<TKey, TValue> | dictionary | A dictionary of UnityObjects that may contain destroyed objects. |
Type Parameters
Name | Description |
---|---|
TKey | The specific type of UnityObject serving as keys in the dictionary. |
TValue | The value type of the dictionary. |
RemoveDestroyedObjects<T>(List<T>)
Removes any destroyed UnityObjects from a list.
Declaration
public static void RemoveDestroyedObjects<T>(List<T> list)
where T : Object
Parameters
Type | Name | Description |
---|---|---|
List<T> | list | A list of UnityObjects that may contain destroyed objects. |
Type Parameters
Name | Description |
---|---|
T | The specific type of UnityObject in the dictionary. |