Skip to main content

Class TypeSelectorAttribute

Namespace: Aspid.FastTools.Types
Assembly: Aspid.FastTools.dll

Draws the field with the type-selector window.

[Conditional("UNITY_EDITOR")]
public sealed class TypeSelectorAttribute : PropertyAttribute

Inheritance​

object ← Attribute ← PropertyAttribute ← TypeSelectorAttribute

Extension Methods​

TextInputBaseFieldTextSelectionExtensions.AddOnCursorIndexChange<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, Action), TextInputBaseFieldTextSelectionExtensions.AddOnSelectIndexChange<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, Action), INotifyValueChangedExtensions.AddValueChanged<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, EventCallback<ChangeEvent<TValue>>), ProfilerMarkerExtensionsForGenerator.Marker<TypeSelectorAttribute>(TypeSelectorAttribute), TextInputBaseFieldTextSelectionExtensions.RemoveOnCursorIndexChange<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, Action), TextInputBaseFieldTextSelectionExtensions.RemoveOnSelectIndexChange<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, Action), INotifyValueChangedExtensions.RemoveValueChanged<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, EventCallback<ChangeEvent<TValue>>), TextInputBaseFieldExtensions.SetAutoCorrection<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, bool), TextInputBaseFieldTextSelectionExtensions.SetCursorIndex<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, int), TextInputBaseFieldExtensions.SetDelayed<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, bool), TextInputBaseFieldTextSelectionExtensions.SetDoubleClickSelectsWord<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, bool), TextInputBaseFieldExtensions.SetHideMobileInput<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, bool), TextInputBaseFieldExtensions.SetHidePlaceholderOnFocus<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, bool), TextInputBaseFieldExtensions.SetHideSoftKeyboard<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, bool), SliderExtensions.SetHighValue<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, TValue), TextInputBaseFieldExtensions.SetKeyboardType<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, TouchScreenKeyboardType), BaseFieldExtensions.SetLabel<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, string), SliderExtensions.SetLowValue<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, TValue), TextInputBaseFieldExtensions.SetMaskChar<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, char), TextInputBaseFieldExtensions.SetMaxLength<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, int), TextInputBaseFieldExtensions.SetPassword<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, bool), TextInputBaseFieldExtensions.SetPlaceholder<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, string), TextInputBaseFieldExtensions.SetReadOnly<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, bool), TextInputBaseFieldTextSelectionExtensions.SetSelectAllOnFocus<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, bool), TextInputBaseFieldTextSelectionExtensions.SetSelectAllOnMouseUp<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, bool), TextInputBaseFieldTextSelectionExtensions.SetSelectIndex<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, int), TextInputBaseFieldTextSelectionExtensions.SetSelectable<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, bool), TextInputBaseFieldTextSelectionExtensions.SetTripleClickSelectsLine<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, bool), INotifyValueChangedExtensions.SetValue<TypeSelectorAttribute, TValue>(TypeSelectorAttribute, TValue, bool)

Examples​

[TypeSelector(typeof(MonoBehaviour))]
[SerializeField] private string _behaviorType;
[TypeSelector]
[SerializeField] private string _anyType;
[TypeSelector(typeof(IDisposable), typeof(ScriptableObject))]
[SerializeField] private string _type;

Remarks​

With several base types the picker shows only types assignable to all of them.

Constructors​

TypeSelectorAttribute()​

Creates an unconstrained attribute: any type is offered.

public TypeSelectorAttribute()

TypeSelectorAttribute(Type)​

Creates an attribute constrained to a single base type.

public TypeSelectorAttribute(Type type)

Parameters​

type Type

The base constraint type.

TypeSelectorAttribute(params Type[]?)​

Creates an attribute constrained to one or more base types.

public TypeSelectorAttribute(params Type[]? types)

Parameters​

types Type[]?

The base constraint types.

TypeSelectorAttribute(string)​

Creates an attribute constrained to a single base type named by a string.

public TypeSelectorAttribute(string assemblyQualifiedName)

Parameters​

assemblyQualifiedName string

An assembly-qualified type name ("MyGame.IWeapon, MyGame") or the name of a member supplying the constraint — see the remarks.

Examples​

[SerializeField] private SerializableType _category;

[TypeSelector(nameof(_category))]
[SerializeField] private string _subType;

Remarks​

Resolved member-first: an identifier matching an instance field or property on the target object supplies the constraint from its current value, so it can be driven live by another field; anything else is treated as an assembly-qualified type name. A member may be a Type, a string, a SerializableType, or an array of these. Prefer nameof(...) so a rename keeps the reference intact. A name that resolves to nothing is surfaced as an inline inspector notice.

TypeSelectorAttribute(params string[]?)​

Creates an attribute constrained to one or more base types, each named by a string.

public TypeSelectorAttribute(params string[]? assemblyQualifiedNames)

Parameters​

assemblyQualifiedNames string[]?

Each entry is resolved independently, member-first; see TypeSelectorAttribute.%23ctor.

Properties​

Allow​

Gets or sets which special type categories the picker offers besides concrete classes; TypeAllow.All by default.

public TypeAllow Allow { get; set; }

Property Value​

TypeAllow

Remarks​

Ignored on a [SerializeReference] field, which always lists only instantiable types.

AssemblyQualifiedNames​

Gets the raw constraint arguments: assembly-qualified names of base types, or names of members supplying them (see TypeSelectorAttribute.%23ctor). Empty for an unconstrained selector.

public string[] AssemblyQualifiedNames { get; }

Property Value​

string[]

Required​

Gets or sets a value indicating whether an unset field shows an inline "required" warning and counts as a violation for the build/CI gate.

public bool Required { get; set; }

Property Value​

bool

Examples​

[TypeSelector(typeof(IWeapon), Required = true)]
[SerializeReference] private IWeapon _weapon;

Remarks​

"Unset" means null for a [SerializeReference] field and an empty name for a string or SerializableType field. A reference that is set but whose type no longer resolves is not a violation of this flag — the separate missing-type gate covers that.