Adds an attribute that can be placed on editor fields to display a dropdown selection for found assets.
While this is a super useful attribute, the performance is not great and something that needs to be performed. Avoid displaying many fields with this attribute at once.
- For any
UnityEngine.Object
field, apply theAssetSelector
attribute - Provide a directory for the attribute to improve performance
- In the Unity Editor, make a selection
public class MyBehaviour : MonoBehaviour
{
[AssetSelector(typeof(ExampleAsset), new string[] {"ResourceAttributes/Samples/"})]
public ExampleAsset[] exampleAssets;
}
All assets found at the given path(s) will be listed as a selectable option. You can omit the path field in the attribute's constructor but this is not recommended. Doing so will search the entire asset database which is performance costly.
With the "allow follders" disabled:
- You can disable the folder/pathing in the dropdown to just display the asset's name.
- You can pass
true
orfalse
(or nothing) to determine whether or not a "None" option should appear in the dropdown. This will set the reference tonull
if selected. - You can specify what file type to search for, the system by default will use
.asset