검색 공급자의 행동을 등록할 수 있습니다. 등록된 행동은 검색 결과의 More Options (⋮) 아이콘을 통해 사용자가 액세스할 수 있습니다.
참고: 행동 핸들러 등록과 검색 공급자 등록은 서로 다른 프로세스입니다. 기존 검색 공급자에 새로운 행동 핸들러를 등록할 수 있습니다.
행동을 등록하려면 SearchActionsProvider
속성으로 태그된 함수를 만듭니다. 이 함수는 IEnumerable<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);
}
}
};
}
SearchAction
클래스는 행동을 설명하고 특정 SearchItem
에 대해 행동을 실행하기 위한 핸들러를 제공합니다.
public class SearchAction
{
public SearchAction(string providerType, string name,
Texture2D icon = null,
string tooltip = null);
public ActionHandler handler;
public EnabledHandler isEnabled;
}
providerType
은 행동을 등록할 공급자의 고유 ID입니다.
’ActionHandler’의 서명은 다음과 같습니다.
// 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);
}
}
}
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.