Skip to content

Helpful Unity Resource attributes for serialized fields.

Notifications You must be signed in to change notification settings

austephner/AssetFieldAttributes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Asset Attributes

Summary

Adds an attribute that can be placed on editor fields to display a dropdown selection for found assets.

Disclaimer

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.

Usage

  1. For any UnityEngine.Object field, apply the AssetSelector attribute
  2. Provide a directory for the attribute to improve performance
  3. 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.

img.png

With the "allow follders" disabled:

img2.png

Notes

  • You can disable the folder/pathing in the dropdown to just display the asset's name.
  • You can pass true or false (or nothing) to determine whether or not a "None" option should appear in the dropdown. This will set the reference to null if selected.
  • You can specify what file type to search for, the system by default will use .asset

Releases

No releases published

Packages

No packages published

Languages