public static void ShowValues(GraphToolState graphToolState, string title, IEnumerable <string> values, Vector2 position, Action <string, int> callback) { var searcherSize = graphToolState.GetSearcherSize(Usage.k_Values); position += EditorWindow.focusedWindow.position.position; var rect = new Rect(position, searcherSize.Size); var items = values.Select(v => new SearcherItem(v)).ToList(); var database = new SearcherDatabase(items); var adapter = new SimpleSearcherAdapter(title); adapter.SetInitialSplitterDetailRatio(searcherSize.RightLeftRatio); var searcher = new Searcher.Searcher(database, adapter); Searcher.SearcherWindow.Show(EditorWindow.focusedWindow, searcher, item => { if (item == null) { return(false); } callback(item.Name, item.Id); return(true); }, null, rect); ListenToSearcherSize(graphToolState, Usage.k_Values); }
static void Main(string[] args) { var executor = new Executor(); var searcher = new Searcher.Searcher(); // Create the sets executor.RunGenerateComparison(); executor.RunGenerateOppositeOrderComparison(); // Query the Sets executor.RunSearchComparison(); executor.RunOppositeOrderSearchComparison(); }
// Used to display data that is not meant to be persisted. The database will be overwritten after each call to SearcherWindow.Show(...). internal static void ShowTransientData(EditorWindow host, IEnumerable <SearcherItem> items, ISearcherAdapter adapter, Action <SearcherItem> selectionDelegate, Vector2 pos) { var database = SearcherDatabase.Create(items.ToList(), "", false); var searcher = new Searcher.Searcher(database, adapter); SearcherWindow.Show(host, searcher, x => { host.Focus(); selectionDelegate(x); return(!(Event.current?.modifiers.HasFlag(EventModifiers.Control)).GetValueOrDefault()); }, pos, null); }
internal static void ShowCriteria(ComponentQueryDeclarationModel query, string title, Vector2 position, Action <TypeHandle, TypeMember, BinaryOperatorKind> onComponentSelected) { var provider = (EcsSearcherDatabaseProvider)query.GraphModel.Stencil.GetSearcherDatabaseProvider(); var databases = provider.GetCriteriaSearcherDatabases(query); var criteriaAdapter = new SimpleSearcherAdapter(title); var searcher = new Searcher.Searcher(databases, criteriaAdapter); SearcherWindow.Show( EditorWindow.focusedWindow, searcher, item => OnItemSelected(item, onComponentSelected), position, null); }
public static void ShowTypes(Stencil stencil, Vector2 position, Action <TypeHandle, int> callback, SearcherFilter userFilter = null) { var databases = stencil.GetSearcherDatabaseProvider().GetTypesSearcherDatabases(); foreach (var database in databases) { database.MatchFilter = (query, item) => { if (!(item is TypeSearcherItem typeItem)) { return(false); } var filter = stencil.GetSearcherFilterProvider()?.GetTypeSearcherFilter(); var res = true; if (filter != null) { res &= GetFilterResult(filter, typeItem.Data); } if (userFilter != null) { res &= GetFilterResult(userFilter, typeItem.Data); } return(res); }; } var searcher = new Searcher.Searcher(databases, k_TypeAdapter) { SortComparison = k_TypeSort }; SearcherWindow.Show(EditorWindow.focusedWindow, searcher, item => { if (!(item is TypeSearcherItem typeItem)) { return(false); } callback(typeItem.Type, 0); return(true); }, position, null);
internal static void ShowValues(string title, IEnumerable <string> values, Vector2 position, Action <string, int> callback) { var items = values.Select(v => new SearcherItem(v)).ToList(); var database = SearcherDatabase.Create(items, "", false); var searcher = new Searcher.Searcher(database, new SimpleSearcherAdapter(title)); SearcherWindow.Show(EditorWindow.focusedWindow, searcher, item => { if (item == null) { return(false); } callback(item.Name, item.Id); return(true); }, position, null); }
static void PromptSearcherPopup <T>(List <SearcherDatabaseBase> databases, SearcherFilter filter, ISearcherAdapter adapter, Rect rect, Action <T> callback) where T : ISearcherItemDataProvider { var searcher = new Searcher.Searcher(databases, adapter, filter) { SortComparison = k_GraphElementSort }; Searcher.SearcherWindow.Show(EditorWindow.focusedWindow, searcher, item => { if (item is T dataProvider) { callback(dataProvider); return(true); } return(false); }, null, rect); }
internal static void ShowEnumValues(string title, Type enumType, Vector2 position, Action <Enum, int> callback) { var items = Enum.GetValues(enumType) .Cast <Enum>() .Select(v => new EnumValuesAdapter.EnumValueSearcherItem(v) as SearcherItem) .ToList(); var database = SearcherDatabase.Create(items, "", false); var searcher = new Searcher.Searcher(database, new EnumValuesAdapter(title)); SearcherWindow.Show(EditorWindow.focusedWindow, searcher, item => { if (item == null) { return(false); } callback(((EnumValuesAdapter.EnumValueSearcherItem)item).value, 0); return(true); }, position, null); }
static void PromptSearcher <T>(List <SearcherDatabase> databases, SearcherFilter filter, ISearcherAdapter adapter, Vector2 position, Action <T> callback) where T : ISearcherItemDataProvider { ApplyDatabasesFilter <T>(databases, filter); var searcher = new Searcher.Searcher(databases, adapter) { SortComparison = k_GraphElementSort }; var ctx = typeof(T) == typeof(GraphNodeModelSearcherItem) ? SearcherContext.Graph : SearcherContext.Stack; SearcherWindow.Show(EditorWindow.focusedWindow, searcher, item => { if (item is T dataProvider) { callback(dataProvider); return(true); } return(false); }, position, e => AnalyticsDataDelegate(e, ctx)); }
internal static void FindInGraph( EditorWindow host, VSGraphModel graph, Action <FindInGraphAdapter.FindSearcherItem> highlightDelegate, Action <FindInGraphAdapter.FindSearcherItem> selectionDelegate ) { var items = graph.GetAllNodes() .Where(x => !string.IsNullOrEmpty(x.Title)) .Select(MakeFindItems) .ToList(); var database = SearcherDatabase.Create(items, "", false); var searcher = new Searcher.Searcher(database, new FindInGraphAdapter(highlightDelegate)); var position = new Vector2(host.rootVisualElement.layout.center.x, 0); SearcherWindow.Show(host, searcher, item => { selectionDelegate(item as FindInGraphAdapter.FindSearcherItem); return(true); }, position, null, k_FindAlignment); }
static EditorWindow PromptSearcherInOwnWindow <T>(List <SearcherDatabaseBase> databases, SearcherFilter filter, ISearcherAdapter adapter, Action <T> callback, Rect rect) where T : ISearcherItemDataProvider { var searcher = new Searcher.Searcher(databases, adapter, filter) { SortComparison = k_GraphElementSort }; Type searcherControlType = Type.GetType("UnityEditor.Searcher.SearcherControl, Unity.Searcher.Editor"); bool windowExists = EditorWindow.HasOpenInstances <SearcherWindow>(); var window = EditorWindow.GetWindow <SearcherWindow>(); if (!windowExists) { window.position = rect; } var searcherControl = Activator.CreateInstance(searcherControlType) as VisualElement; Action <SearcherItem> action = item => { if (item is T dataProvider) { callback(dataProvider); } }; var setupMethod = searcherControlType.GetMethod("Setup"); setupMethod?.Invoke(searcherControl, new object[] { searcher, action, null }); window.rootVisualElement.Add(searcherControl); return(window); }
public static void FindInGraph( EditorWindow host, IGraphModel graph, Action <FindInGraphAdapter.FindSearcherItem> highlightDelegate, Action <FindInGraphAdapter.FindSearcherItem> selectionDelegate ) { var items = graph.NodeModels .Where(x => x is IHasTitle titled && !string.IsNullOrEmpty(titled.Title)) .Select(x => MakeFindItems(x, (x as IHasTitle)?.Title)) .ToList(); var database = new SearcherDatabase(items); var searcher = new Searcher.Searcher(database, new FindInGraphAdapter(highlightDelegate)); var position = new Vector2(host.rootVisualElement.layout.center.x, 0); Searcher.SearcherWindow.Show(host, searcher, item => { selectionDelegate(item as FindInGraphAdapter.FindSearcherItem); return(true); }, position, null, k_FindAlignment); }
public static void ShowTypes(GraphToolState graphToolState, List <SearcherDatabaseBase> databases, Vector2 position, Action <TypeHandle, int> callback) { var searcherSize = graphToolState.GetSearcherSize(Usage.k_Types); position += EditorWindow.focusedWindow.position.position; var rect = new Rect(position, searcherSize.Size); k_TypeAdapter.SetInitialSplitterDetailRatio(searcherSize.RightLeftRatio); var searcher = new Searcher.Searcher(databases, k_TypeAdapter) { SortComparison = TypeComparison }; Searcher.SearcherWindow.Show(EditorWindow.focusedWindow, searcher, item => { if (!(item is TypeSearcherItem typeItem)) { return(false); } callback(typeItem.Type, 0); return(true); }, null, rect);
public Executor() { _setGenerator = new InMemorySetGenerator(); _searcher = new Searcher.Searcher(); Console.ForegroundColor = ConsoleColor.Cyan; }