PropertyDrawerBase

The base class all property drawers from the package derive from. It contains some extra utility functions.

Inheritance:
  • object -> GUIDrawer -> PropertyDrawer -> PropertyDrawerBase

Namespace:

EditorAttributes.Editor

Assembly:

EditorAttributes.Editor.asmdef

Syntax:

public class PropertyDrawerBase : PropertyDrawer

Properties

CanApplyGlobalColor

Checks if the global color can be applied on an element.

Type: bool

Declaration:

protected bool CanApplyGlobalColor { get; }

Methods

CreatePropertyGUI(SerializedProperty)

Override this method to make your own UI Toolkit based GUI for the property.

Declaration:

public override VisualElement CreatePropertyGUI(SerializedProperty property)
Parameters:
  • SerializedProperty property: The SerializedProperty to make the custom GUI for

Returns: VisualElement: The element containing the custom GUI

Overrides:

PropertyDrawer.CreatePropertyGUI(SerializedProperty)

CopyValue(VisualElement, SerializedProperty)

Override this function to customize the copied value from an element with using AddPropertyContextMenu(VisualElement, SerializedProperty).

Declaration:

protected virtual string CopyValue(VisualElement element, SerializedProperty property)
Parameters:
  • VisualElement element: The element on which the context menu was added

  • SerializedProperty property: The attached serialized property

Returns: string: The string that will be copied into the clipboard

PasteValue(VisualElement, SerializedProperty, string)

Override this function to customize the paste behaivour for an element with using AddPropertyContextMenu(VisualElement, SerializedProperty).

Declaration:

protected virtual void PasteValue(VisualElement element, SerializedProperty property, string clipboardValue)
Parameters:
  • VisualElement element: The element on which the context menu was added

  • SerializedProperty property: The attached serialized property

  • string clipboardValue: The current clipboard value

IsSupportedPropertyType(SerializedProperty)

Checks to see if the property type is supported by the drawer.

Note

This always returns true by default, override it to add custom type checks.

Declaration:

protected virtual bool IsSupportedPropertyType(SerializedProperty property)
Parameters:
  • SerializedProperty property: The serialized property to check

Returns: bool: True if the type is supported, false otherwise

CreatePropertyField(SerializedProperty)

Creates a properly binded property field from a serialized property.

Declaration:

public static PropertyField CreatePropertyField(SerializedProperty property)
Parameters:
  • SerializedProperty property: The serialized property

Returns: PropertyField: The binded property field

SetProperyValueFromString(string, SerializedProperty)

Sets the value of a property from a string.

Declaration:

protected static void SetProperyValueFromString(string value, SerializedProperty property)
Parameters:
  • string value: The string value to convert

  • SerializedProperty property: The serialized property to assign the value to

GetPropertyValueAsString(SerializedProperty)

Gets the value of a serialzied property and returns it as a string.

Declaration:

protected static string GetPropertyValueAsString(SerializedProperty property)
Parameters:
  • SerializedProperty property: The serialized property to get the value from

Returns: string: The serialized property value as a string

FindNestedProperty(SerializedProperty, string)

Finds a nested serialized property.

Declaration:

protected static SerializedProperty FindNestedProperty(SerializedProperty property, string propertyName)
Parameters:
  • SerializedProperty property: The serialized property

  • string propertyName: The name of the property to find

Returns: SerializedProperty: The nested serialized property

GetCollectionProperty(SerializedProperty)

Gets the collection property from a collection item property.

Declaration:

public static SerializedProperty GetCollectionProperty(SerializedProperty property)
Parameters:
  • SerializedProperty property: The collection item property

Returns: SerializedProperty: The collection property

GetSerializedPropertyName(string, SerializedProperty)

Gets the name of a serialized property accounting for C# properties.

Declaration:

public static string GetSerializedPropertyName(string propertyName, SerializedProperty property)
Parameters:
  • string propertyName: The name of the property to look for

  • SerializedProperty property: The serialized property

Returns: string: The name of the serialized property

IsPropertyEnumFlag()

Checks to see if the serialized property is a flagged enum.

Declaration:

protected bool IsPropertyEnumFlag()

Returns: bool: True if the serialized property type is a flagged enum

GetCollectionElementIndex(SerializedProperty)

Get the element index of the property in a collection.

Declaration:

public static int GetCollectionElementIndex(SerializedProperty property)
Parameters:
  • SerializedProperty property: The serialized property

Returns: int: The index of the property if in an collection, else -1

DisplayErrorBox(VisualElement, HelpBox)

Displays an error box in the inspector.

Declaration:

public static void DisplayErrorBox(VisualElement root, HelpBox errorBox)
Parameters:
  • VisualElement root: The root visual element

  • HelpBox errorBox: The help box to displaying the errors

UpdateVisualElement(VisualElement, Action, long)

Schedules an action to update.

Declaration:

public static void UpdateVisualElement(VisualElement visualElement, Action logicToUpdate, long intervalMs = 60L)
Parameters:
  • VisualElement visualElement: The visual element to schedule the update

  • Action logicToUpdate: The logic to execute on the specified element

  • optional, long intervalMs: The update interval in milliseconds

Returns: IVisualElementScheduledItem: The scheduled visual element item

AddElement(VisualElement, VisualElement)

Add an element to another visual element if it doesn’t exist.

Declaration:

public static void AddElement(VisualElement root, VisualElement element)
Parameters:
  • VisualElement root: The root to add the element on

  • VisualElement element: The element to add

RemoveElement(VisualElement, VisualElement)

Removes an element from another visual element if it exists.

Declaration:

public static void RemoveElement(VisualElement owner, VisualElement element)
Parameters:
  • VisualElement owner: The owner containing the element

  • VisualElement element: The element to remove

GetConditionValue(MemberInfo, IConditionalAttribute, SerializedProperty, HelpBox)

Gets the value of a condition for a conditional attribute.

Declaration:

public static bool GetConditionValue(MemberInfo memberInfo, IConditionalAttribute conditionalAttribute, SerializedProperty serializedProperty, HelpBox errorBox)
Parameters:
  • MemberInfo memberInfo: The member info of the condition

  • IConditionalAttribute conditionalAttribute: The conditional attribute

  • SerializedProperty serializedProperty: The serialized property

  • HelpBox errorBox: The error box to display any errors to

Returns: bool: True if the condition is satisfied

GetDynamicString(string, SerializedProperty, IDynamicStringAttribute, HelpBox)

Gets the string value from a member if the input mode is set to Dynamic.

Declaration:

public static string GetDynamicString(string inputText, SerializedProperty property, IDynamicStringAttribute dynamicStringAttribute, HelpBox errorBox)
Parameters:
  • string inputText: The string input that may contain the member name

  • SerializedProperty property: The serialized property

  • IDynamicStringAttribute dynamicStringAttribute: The dynamic string attribute

  • HelpBox errorBox: The error box to display any errors to

Returns: string: If the input mode is Constant will return the base input string, if is Dynamic will return the string value of the member

AddPropertyContextMenu(VisualElement, SerializedProperty)

Adds the property context menu to a non property element.

Declaration:

public static void AddPropertyContextMenu(VisualElement element, SerializedProperty property)
Parameters:
  • VisualElement element: The element to add the context menu to

  • SerializedProperty property: The serialized property

InvokeFunctionOnAllTargets(Object[], string, object[], bool)

Invokes a function on all specified targets.

Declaration:

public static void InvokeFunctionOnAllTargets(Object[] targets, string functionName, object[] parameterValues = null, bool makeTargetsDirty = true)
Parameters:
  • Object[] targets: The property to get the targets from

  • string functionName: The name of the function to invoke

  • optional, object[] parameterValues: Parameter values for the function

  • optional, bool makeTargetsDirty: Whether to make the targets dirty after invoking the function

ApplyBoxStyle(VisualElement)

Applies the help box style to a visual element.

Declaration:

public static void ApplyBoxStyle(VisualElement visualElement)
Parameters:
  • VisualElement visualElement: The element to apply the style to

CopyStyle(VisualElement, VisualElement)

Copies all of the style values from a VisualElement to another.

Declaration:

public void CopyStyle(VisualElement copyFrom, VisualElement copyTo)
Parameters:
  • VisualElement copyFrom: The element to copy the style from

  • VisualElement copyTo: The element to copy the style to

CreateFieldForType<T>(string, object, bool)

Creates a field for a specific type.

Declaration:

public static VisualElement CreateFieldForType<T>(string fieldName, object fieldValue, bool showMixedValue = false)
Type Parameters:
  • T: The type of the field to create

Parameters:
  • string fieldName: The name of the field

  • object fieldValue: The default value of the field

  • optional, bool showMixedValue: Whether to show the mixed value state for the field

Returns: VisualElement: A visual element of the appropriate field

CreateFieldForType(Type, string, object, bool)

Creates a field for a specific type.

Declaration:

public static VisualElement CreateFieldForType(Type fieldType, string fieldName, object fieldValue, bool showMixedValue = false)
Parameters:
  • Type fieldType: The type of the field to create

  • string fieldName: The name of the field

  • object fieldValue: The default value of the field

  • optional, bool showMixedValue: Whether to show the mixed value state for the field

Returns: VisualElement: A visual element of the appropriate field

RegisterValueChangedCallbackByType<T>(VisualElement, Action<object>)

Registers a value changed callback for field of a specific type.

Declaration:

public static void RegisterValueChangedCallbackByType<T>(VisualElement field, Action<object> valueCallback)
Type Parameters:
  • T: The type of the value

Parameters:
  • VisualElement field: The visual element of the field

  • Action<object> valueCallback: The callback action

RegisterValueChangedCallbackByType(Type, VisualElement, Action<object>)

Registers a value changed callback for field of a specific type.

Declaration:

public static void RegisterValueChangedCallbackByType(Type fieldType, VisualElement field, Action<object> valueCallback)
Parameters:
  • Type fieldType: The type of the value

  • VisualElement field: The visual element of the field

  • Action<object> valueCallback: The callback action

GetFieldLabel(VisualElement)

Gets the label of the appropriate field

Declaration:

public static string GetFieldLabel(VisualElement field)
Parameters:
  • VisualElement field: The visual element of the field

Returns: string: The field label

GetFieldValue(VisualElement)

Gets the value of the appropriate field.

Declaration:

public static object GetFieldValue(VisualElement field)
Parameters:
  • VisualElement field: The visual element of the field

Returns: object: The field value

SetFieldValue(VisualElement, object, bool)

Sets the value of the appropriate field.

Declaration:

public static void SetFieldValue(VisualElement field, object value, bool notify = false)
Parameters:
  • VisualElement field: The visual element of the field

  • object value: The value to set

  • optional, bool notify: Whether to call the value change callback when setting the value

BindFieldToMember<T>(VisualElement, MemberInfo, object)

Bind a field to the target member value.

Declaration:

public static void BindFieldToMember<T>(VisualElement field, MemberInfo memberInfo, object targetObject)
Type Parameters:
  • T: The type of the field

Parameters:
  • VisualElement fieldName: The field visual element

  • MemberInfo memberInfo: The member to bind

  • object targetObject: The target object of the member

BindFieldToMember(Type, VisualElement, MemberInfo, object)

Bind a field to the target member value.

Declaration:

public static void BindFieldToMember(Type fieldType, VisualElement field, MemberInfo memberInfo, object targetObject)
Parameters:
  • Type fieldType: The type of the field

  • VisualElement fieldName: The field visual element

  • MemberInfo memberInfo: The member to bind

  • object targetObject: The target object of the member

IsCollectionValid(ICollection)

Checks if a collection is null or has no members.

Declaration:

public static bool IsCollectionValid(ICollection collection)
Parameters:
  • ICollection collection: The collection to check

Returns: bool: False is the collection is null or has no members, true otherwise