행동 핸들러 등록
Create action handlers for the search provider.
읽는 시간 2분최근 업데이트: 한 달 전
검색 공급자의 행동을 등록할 수 있습니다. 사용자는 검색 결과의 More Options (⋮) 아이콘을 통해 등록된 행동에 액세스할 수 있습니다.
참고: 행동 핸들러 등록과 검색 공급자 등록은 서로 다른 프로세스입니다. 기존 검색 공급자에 새로운 행동 핸들러를 등록할 수 있습니다.
행동을 등록하려면 속성으로 태그된 함수를 만듭니다. 이 함수는 을 반환해야 합니다.
SearchActionsProviderIEnumerable<SearchAction>다음 예제는 에셋 검색 공급자의 행동을 등록하는 방법을 보여줍니다.
[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다음은 에셋 검색 공급자의 예입니다.
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); } }}