The ValueProviderMenu attribute can be used to introduce new menu items that will be shown in the dropdown menus for all Init arguments of targeted types.
The attribute can be added to a ScriptableObject-derived class that implements IValueProvider<TValue> or IValueByTypeProvider.
You can then use the Value property to access the value stored inside the field.
Example
[CreateAssetMenu] // <- Create a single asset from the class [ValueProviderMenu("Hierarchy/Get Component", Is.SceneObject)] class GetComponent : ScriptableObject, IValueByTypeProvider { public bool TryGetFor<TValue>(Component client, out TValue value) { if(client == null) { value = default; return false; } return Find.In(client.gameObject, out value); } }
Shared Value Provider Asset
If you create a single asset from the value provider class somewhere in your project, then all Init arguments for which the menu item is selected, will be assigned a reference to that same single asset.
This can be useful for preserving memory, in cases where only a single value provider is needed.
Separate Value Providers
If you have zero, or more than one instances of the value provider class in your project, then each Init argument for which the menu item is selected, will be assigned its own instance of the value provider object.
This can be useful when you want to add serialized fields to the value provider, which each client can then use to configure the value provider to fit their individual needs.
Is Constraints
The following Is constraints can be applied for the targets of value providers with the ValueProviderMenu attribute:
Unconstrained
Class
ValueType
Concrete
Abstract
Interface
BuiltIn
Component
WrappedObject
SceneObject
Asset
Collection
Service
Shown in dropdown menus of Init parameters whose type is the defining type of a Service (registered using the ServiceAttribute).
Note that you can add multiple constraints to one ValueProviderMenu attribute using the | operator.
Type Constraints
You can also provide one or more Type arguments in the ValueProviderMenu attribute’s constructor, to constrain it to only appear in the dropdown menus of Init parameters that match those types.
Not Type Constraints
You can also assign a Type to the Not property in the ValueProviderMenu attribute’s constructor, to constrain it to NOT appear in the dropdown menus of Init parameters whose type matches that type.
If you would like to stop it from appearing in the dropdown menus of more than one types of Init parameters, then you can assign an array of types to the NotAny property instead.