示例#1
0
        private void CreateTrees(SelectionTree tree)
        {
            for (var t = 0; t < tree.Labels.Count; t++)
            {
                var items = tree.Items[t];
                var label = tree.Labels[t];

                var root     = TreeItem.Branch(string.Empty, label, null);
                var rootPath = label.text + "/";
                var leaves   = new List <TreeItem>();

                for (var index = 0; index < items.Length; index++)
                {
                    var node     = items[index];
                    var fullPath = rootPath + node.text;
                    var submenus = fullPath.Split('/');

                    var path  = rootPath;
                    var child = root;

                    for (var i = 1; i < submenus.Length - 1; i++)
                    {
                        var menu = submenus[i];
                        path += menu + "/";

                        var previousChild = child;
                        child = GetChild(child, path);

                        if (child == null)
                        {
                            child = TreeItem.Branch(path, new GUIContent(menu, _folderIcon.Content.image), previousChild);
                        }
                    }

                    leaves.Add(TreeItem.Leaf(index, path, new GUIContent(submenus.Last(), node.image ?? _defaultTypeIcon.Content.image), child));
                }

                _roots.Add(root);
                _searchList.Add(leaves);
            }
        }
示例#2
0
        private void RebuildSearch()
        {
            _searchRoot = TreeItem.Branch("Search", new GUIContent("Search"), null);

            _searchRoot.Children.Clear();
            _searchRoot.SelectedIndex = -1;

            if (!_hasSearch)
            {
                _animationTarget = 1;
                _lastTime        = DateTime.Now.Ticks;
            }
            else
            {
                var subwords = _search.ToLower().Split(' ').Where(subword => !string.IsNullOrEmpty(subword)).ToArray();
                var starts   = new List <TreeItem>();
                var contains = new List <TreeItem>();

                foreach (var item in _currentLeaves)
                {
                    if (subwords.Length > 0 && item.SearchName.StartsWith(subwords.First()))
                    {
                        starts.Add(item);
                    }
                    else
                    {
                        foreach (var subword in subwords)
                        {
                            if (item.SearchName.Contains(subword))
                            {
                                contains.Add(item);
                            }
                        }
                    }
                }

                _searchRoot.Children.AddRange(starts);
                _searchRoot.Children.AddRange(contains);
            }
        }