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​

ProfilerMarkerExtensionsForGenerator.Marker<TypeSelectorAttribute>(TypeSelectorAttribute, int)

Examples​

[TypeSelector(typeof(MonoBehaviour))]
[SerializeField] private string _behaviorType;
[TypeSelector(typeof(IDisposable), typeof(ScriptableObject))]
[SerializeField] private string _type;
[SerializeField] private SerializableType _category;
[TypeSelector(nameof(_category))]
[SerializeField] private string _subType;
[TypeSelector(typeof(IWeapon), Required = true)]
[SerializeReference] private IWeapon _weapon;

Remarks​

On an array or List<T> field each element gets a picker, and the add button of a [SerializeReference] list opens one.

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 type.

TypeSelectorAttribute(params Type[]?)​

Creates an attribute constrained to one or more base types.

public TypeSelectorAttribute(params Type[]? types)

Parameters​

types Type[]?

The base types; the picker offers only types assignable to all of them.

TypeSelectorAttribute(string)​

Creates an attribute constrained by a type name or by a member that supplies the base types.

public TypeSelectorAttribute(string assemblyQualifiedName)

Parameters​

assemblyQualifiedName string

An assembly-qualified type name ("MyGame.IWeapon, MyGame") or a member name (nameof(_category)).

Remarks​

An instance field or property of that name supplies the types from its current value: a Type, a String, an ISerializableType or an array of these. Any other string is an assembly-qualified type name.

TypeSelectorAttribute(params string[]?)​

Creates an attribute constrained by one or more type or member names.

public TypeSelectorAttribute(params string[]? assemblyQualifiedNames)

Parameters​

assemblyQualifiedNames string[]?

Type or member names, each resolved as in 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 a "required" warning and is reported as a violation.

public bool Required { get; set; }

Property Value​

bool

Remarks​

Applies to [SerializeReference], String and SerializableTypeBase fields; a type that no longer resolves is reported by the missing-type check instead.