protected override AdvancedDropdownItem FetchData()
        {
            selectedIds.Clear();
            var rootGroup = new AdvancedDropdownItem("", -1);

            for (int i = 0; i < m_DisplayedOptions.Length; i++)
            {
                var option = m_DisplayedOptions[i];

                var element = new AdvancedDropdownItem(option, i);
                element.SetParent(rootGroup);
                rootGroup.AddChild(element);

                if (i == m_SelectedIndex)
                {
                    selectedIds.Add(element.id);
                    rootGroup.selectedItem = i;
                }
            }
            return(rootGroup);
        }
Пример #2
0
        private void DrawDropdown(float anim, AdvancedDropdownItem group)
        {
            // Start of animated area (the part that moves left and right)
            var areaPosition = new Rect(0, 0, position.width, position.height);

            // Adjust to the frame
            areaPosition.x      += kBorderThickness;
            areaPosition.y      += kBorderThickness;
            areaPosition.height -= kBorderThickness * 2;
            areaPosition.width  -= kBorderThickness * 2;

            GUILayout.BeginArea(gui.GetAnimRect(areaPosition, anim));
            // Header
            if (showHeader)
            {
                gui.DrawHeader(group, GoToParent);
            }

            DrawList(group);
            GUILayout.EndArea();
        }
        private bool AddMatchItem(AdvancedDropdownItem e, string name, string[] searchWords, SortedList <string, AdvancedDropdownItem> matchesStart, SortedList <string, AdvancedDropdownItem> matchesWithin)
        {
            var didMatchAll   = true;
            var didMatchStart = false;

            // See if we match ALL the seaarch words.
            for (var w = 0; w < searchWords.Length; w++)
            {
                var search = searchWords[w];
                if (name.Contains(search))
                {
                    // If the start of the item matches the first search word, make a note of that.
                    if (w == 0 && name.StartsWith(search))
                    {
                        didMatchStart = true;
                    }
                }
                else
                {
                    // As soon as any word is not matched, we disregard this item.
                    didMatchAll = false;
                    break;
                }
            }
            // We always need to match all search words.
            // If we ALSO matched the start, this item gets priority.
            if (didMatchAll)
            {
                if (didMatchStart)
                {
                    matchesStart.Add(e.id, e);
                }
                else
                {
                    matchesWithin.Add(e.id, e);
                }
            }
            return(didMatchAll);
        }
Пример #4
0
        public override void DrawItem(AdvancedDropdownItem item, bool selected, bool hasSearch)
        {
            var newScriptItem = item as NewScriptDropdownItem;

            if (newScriptItem == null)
            {
                base.DrawItem(item, selected, hasSearch);
                return;
            }

            GUILayout.Label(L10n.Tr("Name"), EditorStyles.label);

            EditorGUI.FocusTextInControl("NewScriptName");
            GUI.SetNextControlName("NewScriptName");

            newScriptItem.m_ClassName = EditorGUILayout.TextField(newScriptItem.m_ClassName);

            EditorGUILayout.Space();

            var canCreate = newScriptItem.CanCreate();

            if (!canCreate && newScriptItem.m_ClassName != "")
            {
                GUILayout.Label(newScriptItem.GetError(), EditorStyles.helpBox);
            }

            GUILayout.FlexibleSpace();

            using (new EditorGUI.DisabledScope(!canCreate))
            {
                if (GUILayout.Button(L10n.Tr("Create and Add")))
                {
                    newScriptItem.Create(AddComponentWindow.s_AddComponentWindow.m_GameObjects);
                }
            }

            EditorGUILayout.Space();
        }
 public void RebuildSearch(string search)
 {
     m_SearchTree = Search(search);
 }
 public virtual void UpdateSelectedId(AdvancedDropdownItem item)
 {
 }
 public void ReloadData()
 {
     m_MainTree = FetchData();
 }
 internal void SetParent(AdvancedDropdownItem item)
 {
     m_Parent = item;
 }
 internal void AddChild(AdvancedDropdownItem item)
 {
     children.Add(item);
 }
Пример #10
0
        private void DrawList(AdvancedDropdownItem item)
        {
            // Start of scroll view list
            item.m_Scroll = GUILayout.BeginScrollView(item.m_Scroll, GUIStyle.none, GUI.skin.verticalScrollbar);
            EditorGUIUtility.SetIconSize(gui.iconSize);
            Rect selectedRect = new Rect();

            for (var i = 0; i < item.children.Count; i++)
            {
                var  child    = item.children[i];
                bool selected = item.selectionExists && i == item.selectedItem;
                gui.DrawItem(child, selected, hasSearch);
                var r = GUILayoutUtility.GetLastRect();
                if (selected)
                {
                    selectedRect = r;
                }

                // Select the element the mouse cursor is over.
                // Only do it on mouse move - keyboard controls are allowed to overwrite this until the next time the mouse moves.
                if (Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDrag)
                {
                    if (!selected && r.Contains(Event.current.mousePosition))
                    {
                        item.selectedItem = i;
                        Event.current.Use();
                    }
                }
                if (Event.current.type == EventType.MouseUp && r.Contains(Event.current.mousePosition))
                {
                    item.selectedItem = i;
                    if (m_CurrentlyRenderedTree.GetSelectedChild().children.Any())
                    {
                        GoToChild(m_CurrentlyRenderedTree);
                    }
                    else
                    {
                        if (m_CurrentlyRenderedTree.GetSelectedChild().OnAction())
                        {
                            if (selectionChanged != null)
                            {
                                selectionChanged(m_CurrentlyRenderedTree.GetSelectedChild());
                            }
                            if (closeOnSelection)
                            {
                                CloseWindow();
                                GUIUtility.ExitGUI();
                            }
                        }
                    }
                    Event.current.Use();
                }
            }
            EditorGUIUtility.SetIconSize(Vector2.zero);
            GUILayout.EndScrollView();

            // Scroll to selected on windows creation
            if (m_ScrollToSelected && m_InitialSelectionPosition != 0)
            {
                float diffOfPopupAboveTheButton = m_ButtonRectScreenPos.y - position.y;
                diffOfPopupAboveTheButton -= gui.searchHeight + gui.headerHeight;
                item.m_Scroll.y            = m_InitialSelectionPosition - diffOfPopupAboveTheButton;
                m_ScrollToSelected         = false;
                m_InitialSelectionPosition = 0;
            }
            // Scroll to show selected
            else if (m_ScrollToSelected && Event.current.type == EventType.Repaint)
            {
                m_ScrollToSelected = false;
                Rect scrollRect = GUILayoutUtility.GetLastRect();
                if (selectedRect.yMax - scrollRect.height > item.m_Scroll.y)
                {
                    item.m_Scroll.y = selectedRect.yMax - scrollRect.height;
                    Repaint();
                }
                if (selectedRect.y < item.m_Scroll.y)
                {
                    item.m_Scroll.y = selectedRect.y;
                    Repaint();
                }
            }
        }