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:
SerializedPropertyproperty: 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:
VisualElementelement: The element on which the context menu was addedSerializedPropertyproperty: 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:
VisualElementelement: The element on which the context menu was addedSerializedPropertyproperty: The attached serialized propertystringclipboardValue: 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:
SerializedPropertyproperty: 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:
SerializedPropertyproperty: 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:
stringvalue: The string value to convertSerializedPropertyproperty: 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:
SerializedPropertyproperty: 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:
SerializedPropertyproperty: The serialized propertystringpropertyName: 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:
SerializedPropertyproperty: 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:
stringpropertyName: The name of the property to look forSerializedPropertyproperty: 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:
SerializedPropertyproperty: 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:
VisualElementroot: The root visual elementHelpBoxerrorBox: 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:
VisualElementvisualElement: The visual element to schedule the updateActionlogicToUpdate: The logic to execute on the specified elementoptional,
longintervalMs: 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:
VisualElementroot: The root to add the element onVisualElementelement: 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:
VisualElementowner: The owner containing the elementVisualElementelement: 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:
MemberInfomemberInfo: The member info of the conditionIConditionalAttributeconditionalAttribute: The conditional attributeSerializedPropertyserializedProperty: The serialized propertyHelpBoxerrorBox: 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:
stringinputText: The string input that may contain the member nameSerializedPropertyproperty: The serialized propertyIDynamicStringAttributedynamicStringAttribute: The dynamic string attributeHelpBoxerrorBox: 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
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 fromstringfunctionName: The name of the function to invokeoptional,
object[]parameterValues: Parameter values for the functionoptional,
boolmakeTargetsDirty: 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:
VisualElementvisualElement: 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:
VisualElementcopyFrom: The element to copy the style fromVisualElementcopyTo: 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:
stringfieldName: The name of the fieldobjectfieldValue: The default value of the fieldoptional,
boolshowMixedValue: 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:
TypefieldType: The type of the field to createstringfieldName: The name of the fieldobjectfieldValue: The default value of the fieldoptional,
boolshowMixedValue: 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:
VisualElementfield: The visual element of the fieldAction<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:
TypefieldType: The type of the valueVisualElementfield: The visual element of the fieldAction<object>valueCallback: The callback action
GetFieldLabel(VisualElement)
Gets the label of the appropriate field
Declaration:
public static string GetFieldLabel(VisualElement field)
- Parameters:
VisualElementfield: 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:
VisualElementfield: 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:
VisualElementfield: The visual element of the fieldobjectvalue: The value to setoptional,
boolnotify: 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:
VisualElementfieldName: The field visual elementMemberInfomemberInfo: The member to bindobjecttargetObject: 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:
TypefieldType: The type of the fieldVisualElementfieldName: The field visual elementMemberInfomemberInfo: The member to bindobjecttargetObject: The target object of the member
Print(object)
A short handy version of Debug.Log.
Declaration:
protected void Print(object message)
- Parameters:
objectmessage: The message to print
IsCollectionValid(ICollection)
Checks if a collection is null or has no members.
Declaration:
public static bool IsCollectionValid(ICollection collection)
- Parameters:
ICollectioncollection: The collection to check
Returns: bool: False is the collection is null or has no members, true otherwise