Class UnityObjectUtils
Utility methods for working with UnityEngine.Object types
Namespace: Unity.XR.CoreUtils
Syntax
public static class UnityObjectUtils
Methods
ConvertUnityObjectToType<T>(Object)
Takes a Unity Object and returns a component of the specified type if possible. This first checks if the object is already the given type. If not it checks whether it is a game object and gets the first component of the specified type. If it is component of a different type, it will try to return the first component on the same object of the specified type.
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 | The component of the specified type, if found on the object. Otherwise returns null. |
Type Parameters
Name | Description |
---|---|
T | The type to convert to |
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 undo for the destroy action |
RemoveDestroyedKeys<TKey, TValue>(Dictionary<TKey, TValue>)
Remove UnityObjects keys from a dictionary which have been destroyed
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 in the dictionary |
TValue | The value type of the dictionary |
RemoveDestroyedObjects<T>(List<T>)
Remove UnityObjects from a dictionary which have been destroyed
Declaration
public static void RemoveDestroyedObjects<T>(List<T> list)
where T : Object
Parameters
Type | Name | Description |
---|---|---|
List<T> | list | A dictionary of UnityObjects that may contain destroyed objects |
Type Parameters
Name | Description |
---|---|
T | The specific type of UnityObject in the dictionary |