docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class SerializedPropertyExtension

    Extensions for SerializedProperty

    Inheritance
    object
    SerializedPropertyExtension
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEditor.Rendering
    Assembly: Unity.RenderPipelines.Core.Editor.dll
    Syntax
    public static class SerializedPropertyExtension

    Methods

    GetEnumName<T>(SerializedProperty)

    Helper to get an enum name from a SerializedProperty

    Declaration
    public static string GetEnumName<T>(this SerializedProperty property) where T : Enum
    Parameters
    Type Name Description
    SerializedProperty property

    The SerializedProperty

    Returns
    Type Description
    string

    The string containing the name of the enum

    Type Parameters
    Name Description
    T

    A valid Enum

    GetEnumValue<T>(SerializedProperty)

    Helper to get an enum value from a SerializedProperty. This handle case where index do not correspond to enum value.

    Declaration
    public static T GetEnumValue<T>(this SerializedProperty property) where T : Enum
    Parameters
    Type Name Description
    SerializedProperty property

    The SerializedProperty

    Returns
    Type Description
    T

    The Enum value

    Type Parameters
    Name Description
    T

    A valid Enum

    Examples
    enum MyEnum
    {
        A = 2,
        B = 4,
    }
    public class MyObject : MonoBehavior
    {
        public MyEnum theEnum = MyEnum.A;
    }
    [CustomEditor(typeof(MyObject))]
    class MyObjectEditor : Editor
    {
        public override void OnInspectorGUI()
        {
            Debug.Log($"By enumValueIndex: {(MyEnum)serializedObject.FindProperty("theEnum").enumValueIndex}");         //write the value (MyEnum)(0)
            Debug.Log($"By GetEnumValue: {(MyEnum)serializedObject.FindProperty("theEnum").GetEnumValue<MyEnum>()}");   //write the value MyEnum.A
        }
    }

    GetInline<T>(SerializedProperty)

    Get the value of a SerializedProperty.

    This function will be inlined by the compiler. Caution: The case of Enum is not handled here.

    Declaration
    public static T GetInline<T>(this SerializedProperty serializedProperty) where T : struct
    Parameters
    Type Name Description
    SerializedProperty serializedProperty

    The property to get.

    Returns
    Type Description
    T

    The value of the property.

    Type Parameters
    Name Description
    T

    The type of the value to get.

    It is expected to be a supported type by the SerializedProperty.

    IsTargetAlive(SerializedProperty)

    Checks if the property target is alive

    Declaration
    public static bool IsTargetAlive(this SerializedProperty property)
    Parameters
    Type Name Description
    SerializedProperty property

    The SerializedProperty to check

    Returns
    Type Description
    bool

    true, if the property is not null

    SetEnumValue<T>(SerializedProperty, T)

    Helper to set an enum value to a SerializedProperty

    Declaration
    public static void SetEnumValue<T>(this SerializedProperty property, T value) where T : Enum
    Parameters
    Type Name Description
    SerializedProperty property

    The SerializedProperty

    T value

    The Enum

    Type Parameters
    Name Description
    T

    A valid Enum

    SetInline<T>(SerializedProperty, T)

    Set the value of a SerializedProperty.

    This function will be inlined by the compiler. Caution: The case of Enum is not handled here.

    Declaration
    public static void SetInline<T>(this SerializedProperty serializedProperty, T value) where T : struct
    Parameters
    Type Name Description
    SerializedProperty serializedProperty

    The property to set.

    T value

    The value to set.

    Type Parameters
    Name Description
    T

    The type of the value to set.

    It is expected to be a supported type by the SerializedProperty.

    In This Article
    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)