Asset Selector Attribute 特性用于:在對象字段旁邊添加一個小按鈕柏蘑,該按鈕將向用戶顯示資產(chǎn)下拉列表,以便從屬性中進行選擇规伐。
【AssetSelector】添加到對應的字段上即可
[AssetSelector]
public Material AnyAllMaterials;
[AssetSelector]
public Material[] ListOfAllMaterials;
【FlattenTreeView】是否開啟樹狀圖
[PropertySpace(40)]
[AssetSelector(FlattenTreeView = false)]//默認樹狀顯示
public PhysicMaterial TreeView;
[AssetSelector(FlattenTreeView = true)]//非默認樹狀顯示
public PhysicMaterial NoTreeView;
【Paths】單路徑或多路徑查找
[PropertySpace(40)]
[AssetSelector(Paths = "Assets/TutorialAsset/ExampleScriptableObjects")]
public ScriptableObject ScriptableObjectsFromFolder;
[AssetSelector(Paths = "Assets/TutorialAsset/ExampleScriptableObjects|Assets/Plugins/Sirenix/Odin Inspector")]
public ScriptableObject ScriptableObjectsFromMultipleFolders;
【Filter】自定義過濾條件
[PropertySpace(40)]
[AssetSelector(Filter = "New Animation t:AnimationClip l:自定義標簽")]
public UnityEngine.Object AssetDatabaseSearchFilters;
【DisableListAddButtonBehaviour】開啟后加號不會出現(xiàn)樹形下拉條以彈窗形式出現(xiàn)
[Title("輔助性功能")]
[AssetSelector(DisableListAddButtonBehaviour = true)] //開啟后加號不會出現(xiàn)樹形下拉條以彈窗形式出現(xiàn)
public List<GameObject> DisableListAddButtonBehaviour;
【DrawDropdownForListElements】控制已經(jīng)添加的Item是否含有下拉列表
[PropertySpace(40)]
[AssetSelector(DrawDropdownForListElements = false)]
public List<GameObject> DisableListElementBehaviour_False;
[AssetSelector(DrawDropdownForListElements = true)]
public List<GameObject> DisableListElementBehaviour_True;
【ExcludeExistingValuesInList】去除已經(jīng)含有的Item
[PropertySpace(40)]
[AssetSelector(ExcludeExistingValuesInList = true)]
public List<GameObject> ExcludeExistingValuesInList_True;
[AssetSelector(ExcludeExistingValuesInList = false)]
public List<GameObject> ExcludeExistingValuesInList_False;
【IsUniqueList】開啟列表勾選模式(這個關鍵字在Odin的很多特性中都有)
[PropertySpace(40)]
[AssetSelector(IsUniqueList = true)]
public List<GameObject> DisableUniqueListBehaviour_True;
[AssetSelector(IsUniqueList = false)]
public List<GameObject> DisableUniqueListBehaviour_False;
【ExpandAllMenuItems】下拉列表是否強制展開
[PropertySpace(40)]
[AssetSelector(ExpandAllMenuItems = true)]//下拉條是否展開
public List<GameObject> ExpandAllMenuItems_True;
[AssetSelector(ExpandAllMenuItems = false)]
public List<GameObject> ExpandAllMenuItems_False;
【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)] //開啟后加號不會出現(xiàn)樹形下拉條以彈窗形式出現(xiàn)
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;
}