Asset Selector 特性用于:在对象字段旁边添加一个小按钮,该按钮将向用户显示资产下拉列表,以便从特性中进行选择。
1.【AssetSelector】添加到对应的字段上即可
[AssetSelector]
public Material AnyAllMaterials;
[AssetSelector]
public Material[] ListOfAllMaterials;
2.【FlattenTreeView】是否开启树状图
[PropertySpace(40)]
[AssetSelector(FlattenTreeView = false)]//默认树状显示
public PhysicMaterial TreeView;
[AssetSelector(FlattenTreeView = true)]//非默认树状显示
public PhysicMaterial NoTreeView;
3.【Paths】单路径或多路径查找
[PropertySpace(40)]
[AssetSelector(Paths = "Assets/TutorialAsset/ExampleScriptableObjects")]
public ScriptableObject ScriptableObjectsFromFolder;
[AssetSelector(Paths = "Assets/TutorialAsset/ExampleScriptableObjects|Assets/Plugins/Sirenix/Odin Inspector")]
public ScriptableObject ScriptableObjectsFromMultipleFolders;
4.【Filter】自定义过滤条件
[PropertySpace(40)]
[AssetSelector(Filter = "New Animation t:AnimationClip l:自定义标签")]
public UnityEngine.Object AssetDatabaseSearchFilters;
5.【DisableListAddButtonBehaviour】开启后加号不会出现树形下拉条以弹窗形式出现
[Title("辅助性功能")]
[AssetSelector(DisableListAddButtonBehaviour = true)] //开启后加号不会出现树形下拉条以弹窗形式出现
public List<GameObject> DisableListAddButtonBehaviour;
6.【DrawDropdownForListElements】控制已经添加的Item是否含有下拉列表
[PropertySpace(40)]
[AssetSelector(DrawDropdownForListElements = false)]
public List<GameObject> DisableListElementBehaviour_False;
[AssetSelector(DrawDropdownForListElements = true)]
public List<GameObject> DisableListElementBehaviour_True;
7.【ExcludeExistingValuesInList】去除已经含有的Item
[PropertySpace(40)]
[AssetSelector(ExcludeExistingValuesInList = true)]
public List<GameObject> ExcludeExistingValuesInList_True;
[AssetSelector(ExcludeExistingValuesInList = false)]
public List<GameObject> ExcludeExistingValuesInList_False;
8.【IsUniqueList】开启列表勾选模式(这个关键字在Odin的很多特性中都有)
[PropertySpace(40)]
[AssetSelector(IsUniqueList = true)]
public List<GameObject> DisableUniqueListBehaviour_True;
[AssetSelector(IsUniqueList = false)]
public List<GameObject> DisableUniqueListBehaviour_False;
9.【ExpandAllMenuItems】下拉列表是否强制展开
[PropertySpace(40)]
[AssetSelector(ExpandAllMenuItems = true)]//下拉条是否展开
public List<GameObject> ExpandAllMenuItems_True;
[AssetSelector(ExpandAllMenuItems = false)]
public List<GameObject> ExpandAllMenuItems_False;
10.【DropdownTitle】下拉列表标题
[PropertySpace(40)]
[AssetSelector(DropdownTitle = "最定义下拉列表标题")]
public List<GameObject> CustomDropdownTitle;
完整示例代码
using UnityEngine;
using Sirenix.OdinInspector;
using System;
using System.Collections.Generic;
public class AssetSelectorAttributeExample : MonoBehaviour
{
[AssetSelector]
public Material AnyAllMaterials;
[AssetSelector]
public Material[] ListOfAllMaterials;
[PropertySpace(40)]
[AssetSelector(FlattenTreeView = false)]//默认树状显示
public PhysicMaterial TreeView;
[AssetSelector(FlattenTreeView = true)]//非默认树状显示
public PhysicMaterial NoTreeView;
[PropertySpace(40)]
[AssetSelector(Paths = "Assets/TutorialAsset/ExampleScriptableObjects")]
public ScriptableObject ScriptableObjectsFromFolder;
[AssetSelector(Paths = "Assets/TutorialAsset/ExampleScriptableObjects|Assets/Plugins/Sirenix/Odin Inspector")]
public ScriptableObject ScriptableObjectsFromMultipleFolders;
[PropertySpace(40)]
[AssetSelector(Filter = "New Animation t:AnimationClip l:自定义标签")]
public UnityEngine.Object AssetDatabaseSearchFilters;
[Title("辅助性功能")]
[AssetSelector(DisableListAddButtonBehaviour = true)] //开启后加号不会出现树形下拉条以弹窗形式出现
public List<GameObject> DisableListAddButtonBehaviour;
[PropertySpace(40)]
[AssetSelector(DrawDropdownForListElements = false)]
public List<GameObject> DisableListElementBehaviour_False;
[AssetSelector(DrawDropdownForListElements = true)]
public List<GameObject> DisableListElementBehaviour_True;
[PropertySpace(40)]
[AssetSelector(ExcludeExistingValuesInList = true)]
public List<GameObject> ExcludeExistingValuesInList_True;
[AssetSelector(ExcludeExistingValuesInList = false)]
public List<GameObject> ExcludeExistingValuesInList_False;
[PropertySpace(40)]
[AssetSelector(IsUniqueList = true)]
public List<GameObject> DisableUniqueListBehaviour_True;
[AssetSelector(IsUniqueList = false)]
public List<GameObject> DisableUniqueListBehaviour_False;
[PropertySpace(40)]
[AssetSelector(ExpandAllMenuItems = true)]//下拉条是否展开
public List<GameObject> ExpandAllMenuItems_True;
[AssetSelector(ExpandAllMenuItems = false)]
public List<GameObject> ExpandAllMenuItems_False;
[PropertySpace(40)]
[AssetSelector(DropdownTitle = "最定义下拉列表标题")]
public List<GameObject> CustomDropdownTitle;
}