Library/PackageCache/com.unity.quicksearch@1.6.0-preview.8/Editor/QuickSearch.cs
/// <summary>
/// Use Quick Search to as an object picker to select any object based on the specified filter type.
/// </summary>
/// <param name="selectHandler">Callback to trigger when a user selects an item.</param>
/// <param name="trackingHandler">Callback to trigger when the user is modifying QuickSearch selection (i.e. tracking the currently selected item)</param>
/// <param name="pickerConstraintHandler">Callback that is called to provide additionnal filtering when QuickSearch is populating its object list.</param>
/// <param name="searchText">Initial search text for QuickSearch.</param>
/// <param name="typeName">Type name of the object to select. Can be used to replace filterType.</param>
/// <param name="filterType">Type of the object to select.</param>
/// <param name="defaultWidth">Initial width of the window.</param>
/// <param name="defaultHeight">Initial height of the window.</param>
/// <param name="dockable">If true, creates a dockable QuickSearch Window (that will be closed when an item is activated). If false, it will create a DropDown (borderless, undockable and unmovable) version of QuickSearch.</param>
/// <returns></returns>
Use Quick Search to as an object picker to select any object based on the specified filter type.
Use Quick Search to as an object picker to select any object based on the specified filter type .
public static QuickSearch ShowObjectPicker(
            Action<UnityEngine.Object, bool> selectHandler,
            Action<UnityEngine.Object> trackingHandler,
            Func<ObjectSelectorTargetInfo, bool> pickerConstraintHandler,
            string searchText, string typeName, Type filterType,
            float defaultWidth = 850, float defaultHeight = 539, bool dockable  = false)
        {
            if (selectHandler == null || typeName == null)
                return null;
            if (filterType == null)
                filterType = TypeCache.GetTypesDerivedFrom<UnityEngine.Object>()
                    .FirstOrDefault(t => t.Name == typeName) ?? typeof(UnityEngine.Object);
            var qs = Create();
            qs.saveFilters = false;
            qs.searchTopic = "object";
            qs.sendAnalyticsEvent = true;
            qs.titleContent.text = $"Select {filterType?.Name ?? typeName}...";
            qs.itemIconSize = 64;
            qs.multiselect = false;
            #if USE_SEARCH_ENGINE_API
            qs.filterCallback = (item) => item == SearchItem.none || (IsObjectMatchingType(item ?? SearchItem.none, filterType) );
            #else
            qs.filterCallback = (item) => IsObjectMatchingType(item ?? SearchItem.none, filterType);
            #endif
            qs.selectCallback = (item, canceled) => selectHandler?.Invoke(Utils.ToObject(item, filterType), canceled);
            qs.trackingCallback = (item) => trackingHandler?.Invoke(Utils.ToObject(item, filterType));
            qs.context.wantsMore = true;
            qs.context.filterType = filterType;
            qs.SetSearchText(searchText, TextCursorPlacement.MoveToStartOfNextWord);
            if (!dockable)
                qs.ShowAuxWindow();
            else
                qs.Show();
            qs.position = Utils.GetMainWindowCenteredPosition(new Vector2(defaultWidth, defaultHeight));
            qs.Focus();
            return qs;
        }
public static QuickSearch ShowObjectPicker ( Action < UnityEngine . Object , bool > selectHandler , Action < UnityEngine . Object > trackingHandler , Func < ObjectSelectorTargetInfo , bool > pickerConstraintHandler , string searchText , string typeName , Type filterType , float defaultWidth = 850 , float defaultHeight = 539 , bool dockable = false ) { if ( selectHandler == null || typeName == null ) return null ; if ( filterType == null ) filterType = TypeCache . GetTypesDerivedFrom < UnityEngine . Object > ( ) . FirstOrDefault ( t => t . Name == typeName ) ?? typeof ( UnityEngine . Object ) ; var qs = Create ( ) ; qs . saveFilters = false ; qs . searchTopic = " " ; qs . sendAnalyticsEvent = true ; qs . titleContent . text = $" Select  { filterType ? . Name ?? typeName } ... " ; qs . itemIconSize = 64 ; qs . multiselect = false ; if USE_SEARCH_ENGINE_API qs . filterCallback = ( item ) => item == SearchItem . none || ( IsObjectMatchingType ( item ?? SearchItem . none , filterType ) ) ; else qs . filterCallback = ( item ) => IsObjectMatchingType ( item ?? SearchItem . none , filterType ) ; endif qs . selectCallback = ( item , canceled ) => selectHandler ? . Invoke ( Utils . ToObject ( item , filterType ) , canceled ) ; qs . trackingCallback = ( item ) => trackingHandler ? . Invoke ( Utils . ToObject ( item , filterType ) ) ; qs . context . wantsMore = true ; qs . context . filterType = filterType ; qs . SetSearchText ( searchText , TextCursorPlacement . MoveToStartOfNextWord ) ; if ( ! dockable ) qs . ShowAuxWindow ( ) ; else qs . Show ( ) ; qs . position = Utils . GetMainWindowCenteredPosition ( new Vector2 ( defaultWidth , defaultHeight ) ) ; qs . Focus ( ) ; return qs ; }
Use Quick Search to as an object picker to select any object based on the specified filter type.
Use Quick Search to as an object picker to select any object based on the specified filter type .
/*&& (pickerConstraintHandler?.Invoke(Utils.ToObject(item, filterType)) ?? true)*/
None
selectHandler
Action<UnityEngine.Object, bool>
Callback to trigger when a user selects an item.
Callback to trigger when a user selects an item .
trackingHandler
Action<UnityEngine.Object>
Callback to trigger when the user is modifying QuickSearch selection
Callback to trigger when the user is modifying QuickSearch selection
pickerConstraintHandler
Func<ObjectSelectorTargetInfo, bool>
Callback that is called to provide additionnal filtering when QuickSearch is populating its object list.
Callback that is called to provide additionnal filtering when QuickSearch is populating its object list .
searchText
string
Initial search text for QuickSearch.
Initial search text for QuickSearch .
typeName
string
Type name of the object to select. Can be used to replace filterType.
Type name of the object to select . Can be used to replace filterType .
filterType
Type
Type of the object to select.
Type of the object to select .
defaultWidth
float
Initial width of the window.
Initial width of the window .
defaultHeight
float
Initial height of the window.
Initial height of the window .
dockable
bool
If true, creates a dockable QuickSearch Window (that will be closed when an item is activated). If false, it will create a DropDown (borderless, undockable and unmovable) version of QuickSearch.
If true creates a dockable QuickSearch Window ( that will be closed when an item is activated ) . If false it will create a DropDown ( borderless undockable and unmovable ) version of QuickSearch .