Version 3.3.1.2

Odin has a dedicated attribute overview with examples

AssetListAttribute class

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector.Attributes
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter | AttributeTargets.All, AllowMultiple = false, Inherited = true)]
[Conditional("UNITY_EDITOR")]
public sealed class AssetListAttribute : Attribute, _Attribute

AssetLists is used on lists and arrays and single elements of unity types, and replaces the default list drawer with a list of all possible assets with the specified filter.

Use this to both filter and include or exclude assets from a list or an array, without navigating the project window.

Inheritance
  • System.Object
  • System.Attribute
  • AssetListAttribute
Remarks

Asset lists works on all asset types such as materials, scriptable objects, prefabs, custom components, audio, textures etc, and does also show inherited types.

Example

The following example will display an asset list of all prefabs located in the project window.

public class AssetListExamples : MonoBehaviour
{
    [InfoBox("The AssetList attribute work on both lists of UnityEngine.Object types and UnityEngine.Object types, but have different behaviour.")]
    [AssetList]
    [InlineEditor(InlineEditorModes.LargePreview)]
    public GameObject Prefab;

    [AssetList]
    public List<PlaceableObject> PlaceableObjects;

    [AssetList(Path = "Plugins/Sirenix/")]
    [InlineEditor(InlineEditorModes.LargePreview)]
    public UnityEngine.Object Object;

    [AssetList(AutoPopulate = true)]
    public List<PlaceableObject> PlaceableObjectsAutoPopulated;

    [AssetList(LayerNames = "MyLayerName")]
    public GameObject[] AllPrefabsWithLayerName;

    [AssetList(AssetNamePrefix = "Rock")]
    public List<GameObject> PrefabsStartingWithRock;

    [AssetList(Path = "/Plugins/Sirenix/")]
    public List<GameObject> AllPrefabsLocatedInFolder;

    [AssetList(Tags = "MyTagA, MyTabB", Path = "/Plugins/Sirenix/")]
    public List<GameObject> GameObjectsWithTag;

    [AssetList(Path = "/Plugins/Sirenix/")]
    public List<Material> AllMaterialsInSirenix;

    [AssetList(Path = "/Plugins/Sirenix/")]
    public List<ScriptableObject> AllScriptableObjects;

    [InfoBox("Use a method as a custom filter for the asset list.")]
    [AssetList(CustomFilterMethod = "HasRigidbodyComponent")]
    public List<GameObject> MyRigidbodyPrefabs;

    private bool HasRigidbodyComponent(GameObject obj)
    {
        return obj.GetComponent<Rigidbody>() != null;
    }
}

Constructors

AssetListAttribute()

Initializes a new instance of the AssetListAttribute class.

public AssetListAttribute()

Fields

AssetNamePrefix

Filter the asset list to only include assets which name begins with.

public string AssetNamePrefix
AutoPopulate

If true, all assets found and displayed by the asset list, will automatically be added to the list when inspected.

public bool AutoPopulate
CustomFilterMethod

Filter the asset list to only include assets for which the given filter method returns true.

public string CustomFilterMethod
LayerNames

Filter the asset list to only include assets with a specified layer.

public string LayerNames
Path

Filter the asset list to only include assets which is located at the specified path.

public string Path
Tags

Comma separated list of tags to filter the asset list.

public string Tags