private static void OnExecute(ISearchableElement element) { if (window_ != null) { window_.CloseWithoutRestoreSelection(); } element.Execute(); }
private static void OnSelect(ISearchableElement element) { element.Select(); EditorApplication.delayCall += () => { if (window_ != null) { window_.Focus(); } }; }
public void DrawSearchElement(ISearchableElement element, bool selected, Action <ISearchableElement> onMouseDown, Action <ISearchableElement> onDrag) { var bgRect = new Rect(0f, lastRect_.yMax, WIDTH, ELEM_HEIGHT); var isHover = bgRect.Contains(Event.current.mousePosition); var bgStyle = guiSkin.GetStyle("elem_bg_normal"); if (selected) { bgStyle = guiSkin.GetStyle("elem_bg_selected"); } else if (isHover) { bgStyle = guiSkin.GetStyle("elem_bg_hover"); } GUI.Box(bgRect, new GUIContent(), bgStyle); lastRect_ = bgRect; if (element.Icon != null) { var iconRect = new Rect(bgRect.x + 5f, bgRect.y + 9f, 26f, 26f); GUI.DrawTexture(iconRect, element.Icon, ScaleMode.ScaleToFit); } var titleRect = new Rect(bgRect.x + 35f, bgRect.y + 2f, WIDTH, 25f); var titleStyle = guiSkin.GetStyle(selected ? "title_selected" : "title_normal"); GUI.Label(titleRect, element.Title, titleStyle); var descRect = new Rect(bgRect.x + 35f, bgRect.y + 23f, WIDTH, 25f); var descStyle = guiSkin.GetStyle(selected ? "desc_selected" : "desc_normal"); GUI.Label(descRect, element.Description, descStyle); // Process mouse event if (isHover) { var evt = Event.current; if (evt.type == EventType.MouseDown && onMouseDown != null) { onMouseDown(element); evt.Use(); } else if (evt.type == EventType.MouseDrag && onDrag != null) { onDrag(element); evt.Use(); } } }
private void OnElementClick(ISearchableElement elem) { var idx = List.IndexOf(elem); if (idx < 0) { return; } SetSelectedIndex(idx); Repaint(); }
private void OnElementDrag(ISearchableElement elem) { if (!elem.SupportDrag || elem.DragObject == null) { return; } DragAndDrop.PrepareStartDrag(); DragAndDrop.objectReferences = new[] { elem.DragObject }; DragAndDrop.StartDrag("Dragging Object"); isDragging_ = true; }
private float CalculateMatchScore(ISearchableElement element, string query_lower) { var score = CalculateMatchScore(element.PrimaryContents.ToLowerInvariant(), query_lower); if (element.SecondaryContents != null) { var secondaryScore = CalculateMatchScore(element.SecondaryContents.ToLowerInvariant(), query_lower) * 0.9f; score = Mathf.Max(score, secondaryScore); } if (element is AssetSearchableElement assetElement) { if (assetElement.Extensions == "asset") { score *= 1.5f; } if (!assetElement.IsFolder) { score *= 2f; } } return(score); }
public MatchPair(ISearchableElement element, float score) { this.element = element; this.score = score; }