アクションハンドラーの登録
Create action handlers for the search provider.
読み終わるまでの所要時間 3 分最終更新 1ヶ月前
検索プロバイダーにアクションを登録することができます。ユーザーは、検索結果の More Options (⋮) アイコンから、登録したアクションにアクセスできます。
注意アクションハンドラーの登録と検索プロバイダーの登録は異なる処理です。既存の検索プロバイダーに新しいアクションハンドラーを登録できます。
アクションを登録するには、 属性でタグ付けされた関数を作成します。この関数は を返す必要があります。
SearchActionsProviderIEnumerable<SearchAction>以下の例は、Asset 検索プロバイダーにアクションを登録する方法を示しています。
[SearchActionsProvider]internal static IEnumerable<SearchAction> ActionHandlers(){ return new[] { new SearchAction("asset", "select", Icons.@goto, "Select asset...") { handler = (item, context) => { var asset = AssetDatabase.LoadAssetAtPath<Object>(item.id); if (asset != null) { Selection.activeObject = asset; EditorGUIUtility.PingObject(asset); EditorWindow.FocusWindowIfItsOpen( Utils.GetProjectBrowserWindowType()); } } }, new SearchAction("asset", "open", SearchIcon.open, "Open asset... (Alt+Enter)") { handler = (item, context) => { var asset = AssetDatabase.LoadAssetAtPath<Object>(item.id); if (asset != null) AssetDatabase.OpenAsset(asset); } }, new SearchAction("asset", "reveal", SearchIcon.folder, "Show in Explorer") { handler = (item, context) => { EditorUtility.RevealInFinder(item.id); } } };}
検索アクション
SearchActionSearchItempublic class SearchAction{ public SearchAction(string providerType, string name, Texture2D icon = null, string tooltip = null); public ActionHandler handler; public EnabledHandler isEnabled;}
providerTypeActionHandler// item: item that needs the action to be executed.// context: search context of the SearchTool when the item is executed.public delegate void ActionHandler(SearchItem item, SearchContext context);
isEnabledコンテクスト検索アクション
検索結果の特定の種類のアイテムに対してコンテキスト依存 (右クリック) アクションを提供するには、検索プロバイダーに という名前のアクションを登録します。
context以下の例は、Asset 検索プロバイダーのものです。
new SearchAction(type, "context", null, "Context"){ handler = (item, context) => { var asset = AssetDatabase.LoadAssetAtPath<Object>(item.id); if (asset != null) { Selection.activeObject = asset; EditorUtility.DisplayPopupMenu( QuickSearchTool.ContextualActionPosition, "Assets/", null); } }}