Class SerializedPropertyExtension
Extensions for SerializedProperty
Namespace: UnityEditor.Rendering
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 |
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 |
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;
}
#if UNITY_EDITOR
[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
}
}
#endif
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 |
---|---|
Boolean | 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 | |
T | value | The value |
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. |