Tanoda
TypeReferences.ClassTypeReferencePropertyDrawer Class Reference

Custom property drawer for ClassTypeReference properties. More...

Inheritance diagram for TypeReferences.ClassTypeReferencePropertyDrawer:

Public Member Functions

override float GetPropertyHeight (SerializedProperty property, GUIContent label)
 
override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
 

Properties

static Func< ICollection< Type > > ExcludedTypeCollectionGetter [get, set]
 Gets or sets a function that returns a collection of types that are to be excluded from drop-down. A value of null specifies that no types are to be excluded. More...
 

Detailed Description

Custom property drawer for ClassTypeReference properties.

Definition at line 17 of file ClassTypeReferencePropertyDrawer.cs.

Member Function Documentation

◆ GetPropertyHeight()

override float TypeReferences.ClassTypeReferencePropertyDrawer.GetPropertyHeight ( SerializedProperty  property,
GUIContent  label 
)

Definition at line 253 of file ClassTypeReferencePropertyDrawer.cs.

◆ OnGUI()

override void TypeReferences.ClassTypeReferencePropertyDrawer.OnGUI ( Rect  position,
SerializedProperty  property,
GUIContent  label 
)

Definition at line 257 of file ClassTypeReferencePropertyDrawer.cs.

Property Documentation

◆ ExcludedTypeCollectionGetter

Func<ICollection<Type> > TypeReferences.ClassTypeReferencePropertyDrawer.ExcludedTypeCollectionGetter
staticgetset

Gets or sets a function that returns a collection of types that are to be excluded from drop-down. A value of null specifies that no types are to be excluded.

This property must be set immediately before presenting a class type reference property field using EditorGUI.PropertyField or EditorGUILayout.PropertyField since the value of this property is reset to null each time the control is drawn.

Since filtering makes extensive use of ICollection<Type>.Contains it is recommended to use a collection that is optimized for fast lookups such as HashSet<Type> for better performance.

Exclude a specific type from being selected:

private SerializedProperty _someClassTypeReferenceProperty;
public override void OnInspectorGUI() {
serializedObject.Update();
ClassTypeReferencePropertyDrawer.ExcludedTypeCollectionGetter = GetExcludedTypeCollection;
EditorGUILayout.PropertyField(_someClassTypeReferenceProperty);
serializedObject.ApplyModifiedProperties();
}
private ICollection\<Type\> GetExcludedTypeCollection() {
var set = new HashSet\<Type\>();
set.Add(typeof(SpecialClassToHideInDropdown));
return set;
}

Definition at line 56 of file ClassTypeReferencePropertyDrawer.cs.


The documentation for this class was generated from the following file: