protected override AdvancedDropdownItem FetchData()
        {
            var rootGroup = new AdvancedDropdownItem(m_Label);

            m_SearchableElements = new List <AdvancedDropdownItem>();

            for (int i = 0; i < m_DisplayedOptions.Length; i++)
            {
                var menuPath = m_DisplayedOptions[i];
                var paths    = menuPath.Split('/');

                AdvancedDropdownItem parent = rootGroup;
                for (var j = 0; j < paths.Length; j++)
                {
                    var path = paths[j];
                    if (j == paths.Length - 1)
                    {
                        var element = new MultiLevelItem(path, menuPath);
                        element.elementIndex = i;
                        parent.AddChild(element);
                        m_SearchableElements.Add(element);

                        if (i == m_SelectedIndex)
                        {
                            selectedIDs.Add(element.id);
//                            var tempParent = parent;
//                            AdvancedDropdownItem searchedItem = element;
                            //TODO fix selecting
//                            while (tempParent != null)
//                            {
//                                state.SetSelectedIndex(tempParent, tempParent.children.IndexOf(searchedItem));
//                                searchedItem = tempParent;
//                                tempParent = tempParent.parent;
//                            }
                        }
                        continue;
                    }

                    var groupPathId = paths[0];
                    for (int k = 1; k <= j; k++)
                    {
                        groupPathId += "/" + paths[k];
                    }

                    var group = parent.children.SingleOrDefault(c => ((MultiLevelItem)c).stringId == groupPathId);
                    if (group == null)
                    {
                        group = new MultiLevelItem(path, groupPathId);
                        parent.AddChild(group);
                    }
                    parent = group;
                }
            }
            return(rootGroup);
        }
Ejemplo n.º 2
0
        protected virtual AdvancedDropdownItem Search(string searchString)
        {
            if (m_SearchableElements == null)
            {
                BuildSearchableElements();
            }
            if (string.IsNullOrEmpty(searchString))
            {
                return(null);
            }

            // Support multiple search words separated by spaces.
            var searchWords = searchString.ToLower().Split(' ');

            // We keep two lists. Matches that matches the start of an item always get first priority.
            var matchesStart  = new List <AdvancedDropdownItem>();
            var matchesWithin = new List <AdvancedDropdownItem>();

            foreach (var e in m_SearchableElements)
            {
                var name = e.name.ToLower().Replace(" ", "");
                AddMatchItem(e, name, searchWords, matchesStart, matchesWithin);
            }

            var searchTree = new AdvancedDropdownItem(kSearchHeader);

            matchesStart.Sort();
            foreach (var element in matchesStart)
            {
                searchTree.AddChild(element);
            }
            matchesWithin.Sort();
            foreach (var element in matchesWithin)
            {
                searchTree.AddChild(element);
            }
            return(searchTree);
        }
        protected override AdvancedDropdownItem FetchData()
        {
            var rootGroup = new AdvancedDropdownItem(string.Empty);

            for (var i = 0; i < m_OptionNames.Length; i++)
            {
                if (i == 2)
                {
                    rootGroup.AddSeparator();
                }
                var element = new AdvancedDropdownItem(m_OptionNames[i]);
                element.elementIndex = i;
                rootGroup.AddChild(element);
            }

            RebuildSelection(rootGroup);
            return(rootGroup);
        }
Ejemplo n.º 4
0
        protected override AdvancedDropdownItem FetchData()
        {
            selectedIDs.Clear();
            var rootGroup = new AdvancedDropdownItem("");

            for (int i = 0; i < m_DisplayedOptions.Length; i++)
            {
                var element = new AdvancedDropdownItem(m_DisplayedOptions[i].text)
                {
                    icon = (Texture2D)m_DisplayedOptions[i].image
                };
                element.elementIndex = i;
                rootGroup.AddChild(element);
                if (i == m_SelectedIndex)
                {
                    selectedIDs.Add(element.id);
                    if (m_State != null)
                    {
                        m_State.SetSelectedIndex(rootGroup, i);
                    }
                }
            }
            return(rootGroup);
        }