docs.unity.cn

XR Core Utilities 2.4.0

Search Results for

    Show / Hide Table of Contents

    Class UnityObjectUtils

    Utility methods for working with UnityEngine Object types.

    Inheritance
    object
    UnityObjectUtils
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.XR.CoreUtils
    Assembly: Unity.XR.CoreUtils.dll
    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 T, if found on the object. Otherwise returns null.

    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, bool)

    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.

    bool 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.

    In This Article
    • Methods
      • ConvertUnityObjectToType<T>(Object)
      • Destroy(Object, bool)
      • RemoveDestroyedKeys<TKey, TValue>(Dictionary<TKey, TValue>)
      • RemoveDestroyedObjects<T>(List<T>)
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)