NextWithDepthCheck() private méthode

private NextWithDepthCheck ( int expanded, int minDepth ) : bool
expanded int
minDepth int
Résultat bool
Exemple #1
0
        void SearchInFolders(HierarchyProperty property)
        {
            List <FilterResult> list = new List <FilterResult>();

            string[] baseFolders = ProjectWindowUtil.GetBaseFolders(m_SearchFilter.folders);

            foreach (string folderPath in baseFolders)
            {
                // Ensure we do not have a filter when finding folder
                property.SetSearchFilter(new SearchFilter());

                int folderInstanceID = AssetDatabase.GetMainAssetInstanceID(folderPath);
                if (property.Find(folderInstanceID, null))
                {
                    // Set filter after we found the folder
                    property.SetSearchFilter(m_SearchFilter);
                    int   folderDepth = property.depth;
                    int[] expanded    = null; // enter all children of folder
                    while (property.NextWithDepthCheck(expanded, folderDepth + 1))
                    {
                        FilterResult result = new FilterResult();
                        CopyPropertyData(ref result, property);
                        list.Add(result);
                    }
                }
            }
            m_Results = list.ToArray();
        }
        private static string[] SearchInFolders(SearchFilter searchFilter)
        {
            HierarchyProperty hierarchyProperty = new HierarchyProperty(HierarchyType.Assets);
            List <string>     list = new List <string>();

            string[] folders = searchFilter.folders;
            for (int i = 0; i < folders.Length; i++)
            {
                string text = folders[i];
                hierarchyProperty.SetSearchFilter(new SearchFilter());
                int mainAssetInstanceID = AssetDatabase.GetMainAssetInstanceID(text);
                if (hierarchyProperty.Find(mainAssetInstanceID, null))
                {
                    hierarchyProperty.SetSearchFilter(searchFilter);
                    int   depth    = hierarchyProperty.depth;
                    int[] expanded = null;
                    while (hierarchyProperty.NextWithDepthCheck(expanded, depth + 1))
                    {
                        list.Add(hierarchyProperty.guid);
                    }
                }
                else
                {
                    Debug.LogWarning("AssetDatabase.FindAssets: Folder not found: '" + text + "'");
                }
            }
            return(list.ToArray());
        }
Exemple #3
0
        private static string[] SearchInFolders(SearchFilter searchFilter)
        {
            var property = new HierarchyProperty(HierarchyType.Assets);
            var guids    = new List <string>();

            foreach (string folderPath in searchFilter.folders)
            {
                // Set empty filter to ensure we search all assets to find folder
                property.SetSearchFilter(new SearchFilter());
                int folderInstanceID = GetMainAssetInstanceID(folderPath);
                if (property.Find(folderInstanceID, null))
                {
                    // Set filter after we found the folder
                    property.SetSearchFilter(searchFilter);
                    int   folderDepth = property.depth;
                    int[] expanded    = null; // enter all children of folder
                    while (property.NextWithDepthCheck(expanded, folderDepth + 1))
                    {
                        guids.Add(property.guid);
                    }
                }
                else
                {
                    Debug.LogWarning("AssetDatabase.FindAssets: Folder not found: '" + folderPath + "'");
                }
            }
            return(guids.ToArray());
        }
Exemple #4
0
        private static IEnumerator <T> FindInFolders <T>(SearchFilter searchFilter, Func <HierarchyProperty,  T> selector)
        {
            foreach (string folderPath in searchFilter.folders)
            {
                var folderInstanceID = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID(folderPath);
                var rootPath         = "Assets";

                var pathComponents = folderPath.Split('/');
                // Find the right rootPath if folderPath is part of a package
                if (pathComponents.Length > 1 && pathComponents[0] == UnityEditor.PackageManager.Folders.GetPackagesMountPoint())
                {
                    rootPath = pathComponents[0] + "/" + pathComponents[1];
                }

                // Set empty filter to ensure we search all assets to find folder
                var property = new HierarchyProperty(rootPath);
                property.SetSearchFilter(new SearchFilter());
                if (property.Find(folderInstanceID, null))
                {
                    // Set filter after we found the folder
                    property.SetSearchFilter(searchFilter);
                    int   folderDepth = property.depth;
                    int[] expanded    = null; // enter all children of folder
                    while (property.NextWithDepthCheck(expanded, folderDepth + 1))
                    {
                        yield return(selector(property));
                    }
                }
                else
                {
                    Debug.LogWarning("AssetDatabase.FindAssets: Folder not found: '" + folderPath + "'");
                }
            }
        }
        private static string[] SearchInFolders(SearchFilter searchFilter)
        {
            HierarchyProperty hierarchyProperty = new HierarchyProperty(HierarchyType.Assets);
            List <string>     stringList        = new List <string>();

            foreach (string folder in searchFilter.folders)
            {
                hierarchyProperty.SetSearchFilter(new SearchFilter());
                int mainAssetInstanceId = AssetDatabase.GetMainAssetInstanceID(folder);
                if (hierarchyProperty.Find(mainAssetInstanceId, (int[])null))
                {
                    hierarchyProperty.SetSearchFilter(searchFilter);
                    int   depth    = hierarchyProperty.depth;
                    int[] expanded = (int[])null;
                    while (hierarchyProperty.NextWithDepthCheck(expanded, depth + 1))
                    {
                        stringList.Add(hierarchyProperty.guid);
                    }
                }
                else
                {
                    Debug.LogWarning((object)("AssetDatabase.FindAssets: Folder not found: '" + folder + "'"));
                }
            }
            return(stringList.ToArray());
        }
Exemple #6
0
        private void SearchInFolders(HierarchyProperty property)
        {
            List <FilteredHierarchy.FilterResult> list = new List <FilteredHierarchy.FilterResult>();

            string[] baseFolders = ProjectWindowUtil.GetBaseFolders(this.m_SearchFilter.folders);
            string[] array       = baseFolders;
            for (int i = 0; i < array.Length; i++)
            {
                string assetPath = array[i];
                property.SetSearchFilter(new SearchFilter());
                int mainAssetInstanceID = AssetDatabase.GetMainAssetInstanceID(assetPath);
                if (property.Find(mainAssetInstanceID, null))
                {
                    property.SetSearchFilter(this.m_SearchFilter);
                    int   depth    = property.depth;
                    int[] expanded = null;
                    while (property.NextWithDepthCheck(expanded, depth + 1))
                    {
                        FilteredHierarchy.FilterResult item = new FilteredHierarchy.FilterResult();
                        this.CopyPropertyData(ref item, property);
                        list.Add(item);
                    }
                }
            }
            this.m_Results = list.ToArray();
        }
Exemple #7
0
        // Used for search results, sub tree view (of e.g. a prefab) and custom sorting
        void InitializeProgressivly(HierarchyProperty property, bool subTreeWanted, bool isSearching)
        {
            AllocateBackingArrayIfNeeded();

            int minAllowedDepth = subTreeWanted ? property.depth + 1 : 0;

            if (!isSearching)
            {
                // Subtree setup
                int   row           = 0;
                int[] expanded      = expandedIDs.ToArray();
                int   subtractDepth = subTreeWanted ? property.depth + 1 : 0;

                while (property.NextWithDepthCheck(expanded, minAllowedDepth))
                {
                    var item = EnsureCreatedItem(row);
                    InitTreeViewItem(item, property, property.hasChildren, property.depth - subtractDepth);
                    row++;
                }
                m_RowCount = row;
            }
            else // Searching
            {
                m_RowCount = InitializeSearchResults(property, minAllowedDepth);
            }

            // Now shrink to fit if needed
            ResizeItemList(m_RowCount);
        }
        private int InitializeSearchResults(HierarchyProperty property, int minAllowedDepth)
        {
            int currentSceneHandle = -1;
            int row = 0;

            while (property.NextWithDepthCheck((int[])null, minAllowedDepth))
            {
                GameObjectTreeViewItem objectTreeViewItem = this.EnsureCreatedItem(row);
                if (this.AddSceneHeaderToSearchIfNeeded(objectTreeViewItem, property, ref currentSceneHandle))
                {
                    ++row;
                    if (!this.IsSceneHeader(property))
                    {
                        objectTreeViewItem = this.EnsureCreatedItem(row);
                    }
                    else
                    {
                        continue;
                    }
                }
                this.InitTreeViewItem(objectTreeViewItem, property, false, 0);
                ++row;
            }
            return(row);
        }
Exemple #9
0
        private static string[] SearchInFolders(SearchFilter searchFilter)
        {
            HierarchyProperty property = new HierarchyProperty(HierarchyType.Assets);
            List <string>     list     = new List <string>();

            foreach (string str in searchFilter.folders)
            {
                property.SetSearchFilter(new SearchFilter());
                int mainAssetInstanceID = GetMainAssetInstanceID(str);
                if (property.Find(mainAssetInstanceID, null))
                {
                    property.SetSearchFilter(searchFilter);
                    int   depth    = property.depth;
                    int[] expanded = null;
                    while (property.NextWithDepthCheck(expanded, depth + 1))
                    {
                        list.Add(property.guid);
                    }
                }
                else
                {
                    Debug.LogWarning("AssetDatabase.FindAssets: Folder not found: '" + str + "'");
                }
            }
            return(list.ToArray());
        }
        private static IEnumerator <T> FindInFolders <T>(SearchFilter searchFilter, Func <HierarchyProperty,  T> selector)
        {
            var folders = new List <string>();

            folders.AddRange(searchFilter.folders);
            if (folders.Remove(PackageManager.Folders.GetPackagesMountPoint()))
            {
                var packages = PackageManager.Packages.GetAll();
                foreach (var package in packages)
                {
                    if (package.source == PackageManager.PackageSource.BuiltIn)
                    {
                        continue;
                    }

                    if (!folders.Contains(package.assetPath))
                    {
                        folders.Add(package.assetPath);
                    }
                }
            }

            foreach (string folderPath in folders)
            {
                var folderInstanceID = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID(folderPath);
                var rootPath         = "Assets";

                // Find the right rootPath if folderPath is part of a package
                var packageInfo = PackageManager.Packages.GetForAssetPath(folderPath);
                if (packageInfo != null)
                {
                    rootPath = packageInfo.assetPath;
                }

                // Set empty filter to ensure we search all assets to find folder
                var property = new HierarchyProperty(rootPath);
                property.SetSearchFilter(new SearchFilter());
                if (property.Find(folderInstanceID, null))
                {
                    // Set filter after we found the folder
                    property.SetSearchFilter(searchFilter);
                    int   folderDepth = property.depth;
                    int[] expanded    = null; // enter all children of folder
                    while (property.NextWithDepthCheck(expanded, folderDepth + 1))
                    {
                        yield return(selector(property));
                    }
                }
                else
                {
                    Debug.LogWarning("AssetDatabase.FindAssets: Folder not found: '" + folderPath + "'");
                }
            }
        }
Exemple #11
0
        private static IEnumerator <T> FindInFolders <T>(SearchFilter searchFilter, Func <HierarchyProperty,  T> selector)
        {
            var folders = new List <string>();

            folders.AddRange(searchFilter.folders);
            if (folders.Remove(PackageManager.Folders.GetPackagesPath()))
            {
                var packages = PackageManagerUtilityInternal.GetAllVisiblePackages(searchFilter.skipHidden);
                foreach (var package in packages)
                {
                    if (!folders.Contains(package.assetPath))
                    {
                        folders.Add(package.assetPath);
                    }
                }
            }

            foreach (var folderPath in folders)
            {
                var sanitizedFolderPath = folderPath.ConvertSeparatorsToUnity().TrimTrailingSlashes();
                var folderInstanceID    = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID(sanitizedFolderPath);
                var rootPath            = "Assets";

                // Find the right rootPath if folderPath is part of a package
                var packageInfo = PackageManager.PackageInfo.FindForAssetPath(sanitizedFolderPath);
                if (packageInfo != null)
                {
                    rootPath = packageInfo.assetPath;
                    if (searchFilter.skipHidden && !PackageManagerUtilityInternal.IsPathInVisiblePackage(rootPath))
                    {
                        continue;
                    }
                }

                // Set empty filter to ensure we search all assets to find folder
                var property = new HierarchyProperty(rootPath);
                property.SetSearchFilter(new SearchFilter());
                if (property.Find(folderInstanceID, null))
                {
                    // Set filter after we found the folder
                    property.SetSearchFilter(searchFilter);
                    int   folderDepth = property.depth;
                    int[] expanded    = null; // enter all children of folder
                    while (property.NextWithDepthCheck(expanded, folderDepth + 1))
                    {
                        yield return(selector(property));
                    }
                }
                else
                {
                    Debug.LogWarning("AssetDatabase.FindAssets: Folder not found: '" + sanitizedFolderPath + "'");
                }
            }
        }
 private List<TreeViewItem> CalcVisibleItems(HierarchyProperty property, bool hasSearchString)
 {
     int depth = property.depth;
     int[] expanded = base.expandedIDs.ToArray();
     List<TreeViewItem> list = new List<TreeViewItem>();
     while (property.NextWithDepthCheck(expanded, depth))
     {
         int num = this.GetAdjustedItemDepth(hasSearchString, depth, property.depth);
         GameObjectTreeViewItem item = this.CreateTreeViewItem(property, hasSearchString, num, true);
         list.Add(item);
     }
     return list;
 }
Exemple #13
0
        // Returns number of rows in search result
        int InitializeSearchResults(HierarchyProperty property, int minAllowedDepth)
        {
            // Search setup
            const bool kShowItemHasChildren = false;
            const int  kItemDepth           = 0;
            int        currentSceneHandle   = -1;
            int        row = 0;

            var headerRows = new List <int>();

            while (property.NextWithDepthCheck(null, minAllowedDepth))
            {
                var item = EnsureCreatedItem(row);
                // Add scene headers when encountering a new scene (and it's not a header in itself)
                if (AddSceneHeaderToSearchIfNeeded(item, property, ref currentSceneHandle))
                {
                    row++;
                    headerRows.Add(row);

                    if (IsSceneHeader(property))
                    {
                        continue;                  // no need to add it
                    }
                    item = EnsureCreatedItem(row); // prepare for item below
                }
                InitTreeViewItem(item, property, kShowItemHasChildren, kItemDepth);
                row++;
            }

            int numRows = row;

            // Now sort scene section
            if (headerRows.Count > 0)
            {
                int currentSortStart = headerRows[0];
                for (int i = 1; i < headerRows.Count; i++)
                {
                    int count = headerRows[i] - currentSortStart - 1;
                    m_ListOfRows.Sort(currentSortStart, count, new TreeViewItemAlphaNumericSort());
                    currentSortStart = headerRows[i];
                }

                // last section
                m_ListOfRows.Sort(currentSortStart, numRows - currentSortStart, new TreeViewItemAlphaNumericSort());
            }


            return(numRows);
        }
        private List <TreeViewItem> CalcVisibleItems(HierarchyProperty property, bool hasSearchString)
        {
            int depth = property.depth;

            int[] expanded           = base.expandedIDs.ToArray();
            List <TreeViewItem> list = new List <TreeViewItem>();

            while (property.NextWithDepthCheck(expanded, depth))
            {
                int num = this.GetAdjustedItemDepth(hasSearchString, depth, property.depth);
                GameObjectTreeViewItem item = this.CreateTreeViewItem(property, hasSearchString, num, true);
                list.Add(item);
            }
            return(list);
        }
        void SearchInFolders()
        {
            List <FilterResult> list        = new List <FilterResult>();
            List <string>       baseFolders = new List <string>();

            baseFolders.AddRange(ProjectWindowUtil.GetBaseFolders(m_SearchFilter.folders));
            if (baseFolders.Remove(PackageManager.Folders.GetPackagesMountPoint()))
            {
                var packages = PackageManager.Packages.GetAll();
                foreach (var package in packages)
                {
                    if (package.source == PackageManager.PackageSource.BuiltIn)
                    {
                        continue;
                    }

                    if (!baseFolders.Contains(package.assetPath))
                    {
                        baseFolders.Add(package.assetPath);
                    }
                }
            }

            m_SearchFilter.searchArea = SearchFilter.SearchArea.SelectedFolders;
            foreach (string folderPath in baseFolders)
            {
                // Ensure we do not have a filter when finding folder
                HierarchyProperty property = new HierarchyProperty(folderPath);
                property.SetSearchFilter(m_SearchFilter);

                // Set filter after we found the folder
                int   folderDepth = property.depth;
                int[] expanded    = null; // enter all children of folder
                while (property.NextWithDepthCheck(expanded, folderDepth + 1))
                {
                    FilterResult result = new FilterResult();
                    CopyPropertyData(ref result, property);
                    list.Add(result);
                }
            }
            m_Results = list.ToArray();
        }
        private int InitializeSearchResults(HierarchyProperty property, int minAllowedDepth)
        {
            int num  = -1;
            int num2 = 0;

            while (property.NextWithDepthCheck(null, minAllowedDepth))
            {
                GameObjectTreeViewItem item = this.EnsureCreatedItem(num2);
                if (this.AddSceneHeaderToSearchIfNeeded(item, property, ref num))
                {
                    num2++;
                    if (this.IsSceneHeader(property))
                    {
                        continue;
                    }
                    item = this.EnsureCreatedItem(num2);
                }
                this.InitTreeViewItem(item, property, false, 0);
                num2++;
            }
            return(num2);
        }
        private void InitializeProgressivly(HierarchyProperty property, bool subTreeWanted, bool isSearching)
        {
            this.AllocateBackingArrayIfNeeded();
            int num1 = !subTreeWanted ? 0 : property.depth + 1;

            if (!isSearching)
            {
                int   row   = 0;
                int[] array = this.expandedIDs.ToArray();
                int   num2  = !subTreeWanted ? 0 : property.depth + 1;
                while (property.NextWithDepthCheck(array, num1))
                {
                    this.InitTreeViewItem(this.EnsureCreatedItem(row), property, property.hasChildren, property.depth - num2);
                    ++row;
                }
                this.m_RowCount = row;
            }
            else
            {
                this.m_RowCount = this.InitializeSearchResults(property, num1);
            }
            this.ResizeItemList(this.m_RowCount);
        }
Exemple #18
0
        private void SearchInFolders(HierarchyProperty property)
        {
            List <FilteredHierarchy.FilterResult> filterResultList = new List <FilteredHierarchy.FilterResult>();

            foreach (string baseFolder in ProjectWindowUtil.GetBaseFolders(this.m_SearchFilter.folders))
            {
                property.SetSearchFilter(new SearchFilter());
                int mainAssetInstanceId = AssetDatabase.GetMainAssetInstanceID(baseFolder);
                if (property.Find(mainAssetInstanceId, (int[])null))
                {
                    property.SetSearchFilter(this.m_SearchFilter);
                    int   depth    = property.depth;
                    int[] expanded = (int[])null;
                    while (property.NextWithDepthCheck(expanded, depth + 1))
                    {
                        FilteredHierarchy.FilterResult result = new FilteredHierarchy.FilterResult();
                        this.CopyPropertyData(ref result, property);
                        filterResultList.Add(result);
                    }
                }
            }
            this.m_Results = filterResultList.ToArray();
        }
        private int InitializeSearchResults(HierarchyProperty property, int minAllowedDepth)
        {
            int        num  = -1;
            int        num2 = 0;
            List <int> list = new List <int>();

            while (property.NextWithDepthCheck(null, minAllowedDepth))
            {
                GameObjectTreeViewItem item = this.EnsureCreatedItem(num2);
                if (this.AddSceneHeaderToSearchIfNeeded(item, property, ref num))
                {
                    num2++;
                    list.Add(num2);
                    if (this.IsSceneHeader(property))
                    {
                        continue;
                    }
                    item = this.EnsureCreatedItem(num2);
                }
                this.InitTreeViewItem(item, property, false, 0);
                num2++;
            }
            int num3 = num2;

            if (list.Count > 0)
            {
                int num4 = list[0];
                for (int i = 1; i < list.Count; i++)
                {
                    int count = list[i] - num4 - 1;
                    this.m_ListOfRows.Sort(num4, count, new TreeViewItemAlphaNumericSort());
                    num4 = list[i];
                }
                this.m_ListOfRows.Sort(num4, num3 - num4, new TreeViewItemAlphaNumericSort());
            }
            return(num3);
        }
        private void InitializeProgressivly(HierarchyProperty property, bool subTreeWanted, bool isSearching)
        {
            this.AllocateBackingArrayIfNeeded();
            int num = (!subTreeWanted) ? 0 : (property.depth + 1);

            if (!isSearching)
            {
                int   num2     = 0;
                int[] expanded = base.expandedIDs.ToArray();
                int   num3     = (!subTreeWanted) ? 0 : (property.depth + 1);
                while (property.NextWithDepthCheck(expanded, num))
                {
                    GameObjectTreeViewItem item = this.EnsureCreatedItem(num2);
                    this.InitTreeViewItem(item, property, property.hasChildren, property.depth - num3);
                    num2++;
                }
                this.m_RowCount = num2;
            }
            else
            {
                this.m_RowCount = this.InitializeSearchResults(property, num);
            }
            this.ResizeItemList(this.m_RowCount);
        }
Exemple #21
0
        public override void FetchData()
        {
            // Create root Item
            int depth = 0;

            m_RootItem = new TreeViewItem(m_RootInstanceID, depth, null, CreateDisplayName(m_RootInstanceID));
            if (!showRootItem)
            {
                SetExpanded(m_RootItem, true);
            }

            // Find start Item
            var property = new HierarchyProperty(k_HierarchyType, false);

            property.Reset();
            bool found = property.Find(m_RootInstanceID, null);

            if (!found)
            {
                Debug.LogError("Root Asset with id " + m_RootInstanceID + " not found!!");
            }

            int minDepth = property.depth + (showRootItem ? 0 : 1);

            int[]     expanded        = expandedIDs.ToArray();
            Texture2D emptyFolderIcon = EditorGUIUtility.FindTexture(EditorResources.emptyFolderIconName);

            // Fetch visible items
            m_Rows = new List <TreeViewItem>();
            while (property.NextWithDepthCheck(expanded, minDepth))
            {
                if (!foldersOnly || property.isFolder)
                {
                    depth = property.depth - minDepth;
                    TreeViewItem item;
                    if (property.isFolder)
                    {
                        item = new FolderTreeItem(property.instanceID, depth, null, property.name);
                    }
                    else
                    {
                        item = new NonFolderTreeItem(property.instanceID, depth, null, property.name);
                    }

                    if (property.isFolder && !property.hasChildren)
                    {
                        item.icon = emptyFolderIcon;
                    }
                    else
                    {
                        item.icon = property.icon;
                    }

                    if (property.hasChildren)
                    {
                        item.AddChild(null); // add a dummy child in children list to ensure we show the collapse arrow (because we do not fetch data for collapsed items)
                    }
                    m_Rows.Add(item);
                }
            }

            // Setup reference between child and parent items
            TreeViewUtility.SetChildParentReferences(m_Rows, m_RootItem);

            if (foldersFirst)
            {
                FoldersFirstRecursive(m_RootItem);
                m_Rows.Clear();
                GetVisibleItemsRecursive(m_RootItem, m_Rows);
            }

            // Must be called before InitSelection (it calls GetVisibleItems)
            m_NeedRefreshRows = false;

            // We want to reset selection on copy/duplication/delete
            bool frameLastSelected = false; // use false because we might just be expanding/collapsing a Item (which would prevent collapsing a Item with a selected child)

            m_TreeView.SetSelection(Selection.instanceIDs, frameLastSelected);
        }
        public override void FetchData()
        {
            // Create root Item
            int depth     = 0;
            var multiRoot = (m_Roots.Count > 1);

            if (multiRoot)
            {
                m_RootItem = new TreeViewItem(-1, depth, null, "Invisible Root Item");
                SetExpanded(m_RootItem, true);
            }
            else
            {
                var rootInstanceID = m_Roots[0].instanceID;
                var displayName    = m_Roots[0].displayName ?? CreateDisplayName(rootInstanceID);
                m_RootItem = new TreeViewItem(rootInstanceID, depth, null, displayName);
                SetExpanded(m_RootItem, true);
            }

            m_Rows = new List <TreeViewItem>(m_Roots.Count * 256);
            Texture2D emptyFolderIcon   = EditorGUIUtility.FindTexture(EditorResources.emptyFolderIconName);
            Texture2D folderIcon        = EditorGUIUtility.FindTexture(EditorResources.folderIconName);
            var       assetsInstanceIDs = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID("Assets");
            var       projectPath       = Path.GetFileName(Directory.GetCurrentDirectory());

            // Fetch root Items
            m_RootsTreeViewItem = new Dictionary <string, TreeViewItem>(m_Roots.Count);
            foreach (var root in m_Roots)
            {
                var rootInstanceID = root.instanceID;
                var displayName    = root.displayName ?? CreateDisplayName(rootInstanceID);
                var rootPath       = root.path ?? AssetDatabase.GetAssetPath(rootInstanceID);

                var property = new HierarchyProperty(rootPath);
                if (!root.skipValidation && !property.Find(rootInstanceID, null))
                {
                    Debug.LogError("Root Asset with id " + rootInstanceID + " not valid!!");
                    continue;
                }

                var          minDepth = property.depth;
                var          subDepth = multiRoot ? 0 : -1;
                TreeViewItem rootItem;
                if (multiRoot)
                {
                    var parentItem = m_RootItem;
                    var rootDepth  = minDepth;
                    rootDepth++;

                    // Find parent treeView item
                    var parentPath = Directory.GetParent(rootPath).Name;
                    if (parentPath != projectPath)
                    {
                        if (!m_RootsTreeViewItem.TryGetValue(parentPath, out parentItem))
                        {
                            Debug.LogError("Cannot find parent for " + rootInstanceID);
                            continue;
                        }

                        rootDepth++;
                        subDepth++;
                    }

                    // Create root item TreeView item
                    if (subDepth > 0)
                    {
                        rootItem = new FolderTreeItem(rootInstanceID, rootDepth, parentItem, displayName);
                    }
                    else
                    {
                        rootItem = new RootTreeItem(rootInstanceID, rootDepth, parentItem, displayName);
                    }
                    rootItem.icon = folderIcon;
                    parentItem.AddChild(rootItem);
                }
                else
                {
                    rootItem = m_RootItem;
                }

                m_RootsTreeViewItem[rootPath] = rootItem;

                var  expandIDs      = GetExpandedIDs();
                var  rows           = new List <TreeViewItem>();
                bool shouldExpandIt = m_ExpandAtFirstTime && (rootItem.id == assetsInstanceIDs);
                if (IsExpanded(rootItem.id) && (rootItem == m_RootItem || IsExpanded(rootItem.parent.id)) || shouldExpandIt)
                {
                    m_ExpandAtFirstTime = false;

                    while (property.NextWithDepthCheck(expandIDs, minDepth))
                    {
                        if (!foldersOnly || property.isFolder)
                        {
                            depth = property.depth - minDepth;
                            TreeViewItem item;
                            if (property.isFolder)
                            {
                                item = new FolderTreeItem(property.instanceID, depth + subDepth, null, property.name);
                            }
                            else
                            {
                                item = new NonFolderTreeItem(property.instanceID, depth + subDepth, null, property.name);
                            }

                            if (property.isFolder && !property.hasChildren)
                            {
                                item.icon = emptyFolderIcon;
                            }
                            else
                            {
                                item.icon = property.icon;
                            }

                            if (property.hasChildren)
                            {
                                item.AddChild(null); // add a dummy child in children list to ensure we show the collapse arrow (because we do not fetch data for collapsed items)
                            }
                            rows.Add(item);
                        }
                    }

                    // Setup reference between child and parent items
                    TreeViewUtility.SetChildParentReferences(rows, rootItem);
                }
                else
                {
                    rootItem.AddChild(null);
                }

                if (shouldExpandIt && !IsExpanded(rootItem))
                {
                    SetExpanded(rootItem, true);
                }

                if (multiRoot && IsExpanded(rootItem.parent.id))
                {
                    m_Rows.Add(rootItem);
                }

                ((List <TreeViewItem>)m_Rows).AddRange(rows);
            }

            if (foldersFirst)
            {
                FoldersFirstRecursive(m_RootItem);
                m_Rows.Clear();
                GetVisibleItemsRecursive(m_RootItem, m_Rows);
            }

            // Must be called before InitSelection (it calls GetVisibleItems)
            m_NeedRefreshRows = false;

            // We want to reset selection on copy/duplication/delete
            bool frameLastSelected = false; // use false because we might just be expanding/collapsing a Item (which would prevent collapsing a Item with a selected child)

            m_TreeView.SetSelection(Selection.instanceIDs, frameLastSelected);
        }
Exemple #23
0
        public override void FetchData()
        {
            int depth = 0;

            this.m_RootItem = new TreeViewItem(this.m_RootInstanceID, depth, null, AssetsTreeViewDataSource.CreateDisplayName(this.m_RootInstanceID));
            if (!base.showRootNode)
            {
                this.SetExpanded(this.m_RootItem, true);
            }
            IHierarchyProperty hierarchyProperty = new HierarchyProperty(HierarchyType.Assets);

            hierarchyProperty.Reset();
            if (!hierarchyProperty.Find(this.m_RootInstanceID, null))
            {
                Debug.LogError("Root Asset with id " + this.m_RootInstanceID + " not found!!");
            }
            int num = hierarchyProperty.depth + ((!base.showRootNode) ? 1 : 0);

            int[]     expanded = base.expandedIDs.ToArray();
            Texture2D icon     = EditorGUIUtility.FindTexture(EditorResourcesUtility.emptyFolderIconName);

            this.m_VisibleRows = new List <TreeViewItem>();
            while (hierarchyProperty.NextWithDepthCheck(expanded, num))
            {
                if (!this.foldersOnly || hierarchyProperty.isFolder)
                {
                    depth = hierarchyProperty.depth - num;
                    TreeViewItem treeViewItem;
                    if (hierarchyProperty.isFolder)
                    {
                        treeViewItem = new AssetsTreeViewDataSource.FolderTreeItem(hierarchyProperty.instanceID, depth, null, hierarchyProperty.name);
                    }
                    else
                    {
                        treeViewItem = new AssetsTreeViewDataSource.NonFolderTreeItem(hierarchyProperty.instanceID, depth, null, hierarchyProperty.name);
                    }
                    if (hierarchyProperty.isFolder && !hierarchyProperty.hasChildren)
                    {
                        treeViewItem.icon = icon;
                    }
                    else
                    {
                        treeViewItem.icon = hierarchyProperty.icon;
                    }
                    if (hierarchyProperty.hasChildren)
                    {
                        treeViewItem.AddChild(null);
                    }
                    this.m_VisibleRows.Add(treeViewItem);
                }
            }
            TreeViewUtility.SetChildParentReferences(this.m_VisibleRows, this.m_RootItem);
            if (this.foldersFirst)
            {
                AssetsTreeViewDataSource.FoldersFirstRecursive(this.m_RootItem);
                this.m_VisibleRows.Clear();
                base.GetVisibleItemsRecursive(this.m_RootItem, this.m_VisibleRows);
            }
            this.m_NeedRefreshVisibleFolders = false;
            bool revealSelectionAndFrameLastSelected = false;

            this.m_TreeView.SetSelection(Selection.instanceIDs, revealSelectionAndFrameLastSelected);
        }
 private void InitializeProgressivly(HierarchyProperty property, bool subTreeWanted, bool isSearching)
 {
   this.AllocateBackingArrayIfNeeded();
   int num1 = !subTreeWanted ? 0 : property.depth + 1;
   if (!isSearching)
   {
     int row = 0;
     int[] array = this.expandedIDs.ToArray();
     int num2 = !subTreeWanted ? 0 : property.depth + 1;
     while (property.NextWithDepthCheck(array, num1))
     {
       this.InitTreeViewItem(this.EnsureCreatedItem(row), property, property.hasChildren, property.depth - num2);
       ++row;
     }
     this.m_RowCount = row;
   }
   else
     this.m_RowCount = this.InitializeSearchResults(property, num1);
   this.ResizeItemList(this.m_RowCount);
 }
 private int InitializeSearchResults(HierarchyProperty property, int minAllowedDepth)
 {
   int currentSceneHandle = -1;
   int row = 0;
   while (property.NextWithDepthCheck((int[]) null, minAllowedDepth))
   {
     GameObjectTreeViewItem objectTreeViewItem = this.EnsureCreatedItem(row);
     if (this.AddSceneHeaderToSearchIfNeeded(objectTreeViewItem, property, ref currentSceneHandle))
     {
       ++row;
       if (!this.IsSceneHeader(property))
         objectTreeViewItem = this.EnsureCreatedItem(row);
       else
         continue;
     }
     this.InitTreeViewItem(objectTreeViewItem, property, false, 0);
     ++row;
   }
   return row;
 }
Exemple #26
0
        // Returns number of rows in search result
        int InitializeSearchResults(HierarchyProperty property, int minAllowedDepth)
        {
            // Search setup
            const bool kShowItemHasChildren = false;
            const int  kItemDepth           = 0;
            int        currentSceneHandle   = -1;
            int        row           = 0;
            var        searchFilter  = SearchableEditorWindow.CreateFilter(searchString, (SearchableEditorWindow.SearchMode)m_SearchMode);
            var        searchContext = (SearchService.HierarchySearchContext)m_SearchSessionHandler.context;

            searchContext.filter       = searchFilter;
            searchContext.rootProperty = property;

            m_SearchSessionHandler.BeginSearch(searchString);

            var headerRows = new List <int>();

            while (property.NextWithDepthCheck(null, minAllowedDepth))
            {
                if (!SearchService.Scene.Filter(m_SearchString, property, searchContext))
                {
                    property.SetFilteredVisibility(false);
                    continue;
                }

                property.SetFilteredVisibility(true);
                var item = EnsureCreatedItem(row);
                // Add scene headers when encountering a new scene (and it's not a header in itself)
                if (AddSceneHeaderToSearchIfNeeded(item, property, ref currentSceneHandle))
                {
                    row++;
                    headerRows.Add(row);

                    if (IsSceneHeader(property))
                    {
                        continue;                  // no need to add it
                    }
                    item = EnsureCreatedItem(row); // prepare for item below
                }
                InitTreeViewItem(item, property, kShowItemHasChildren, kItemDepth);
                row++;
            }

            m_SearchSessionHandler.EndSearch();

            int numRows = row;

            // Now sort scene section
            if (headerRows.Count > 0)
            {
                int currentSortStart = headerRows[0];
                for (int i = 1; i < headerRows.Count; i++)
                {
                    int count = headerRows[i] - currentSortStart - 1;
                    m_ListOfRows.Sort(currentSortStart, count, new TreeViewItemAlphaNumericSort());
                    currentSortStart = headerRows[i];
                }

                // last section
                m_ListOfRows.Sort(currentSortStart, numRows - currentSortStart, new TreeViewItemAlphaNumericSort());
            }


            return(numRows);
        }
        public override void FetchData()
        {
            int depth = 0;

            base.m_RootItem = new TreeViewItem(this.m_RootInstanceID, depth, null, CreateDisplayName(this.m_RootInstanceID));
            if (!base.showRootNode)
            {
                this.SetExpanded(base.m_RootItem, true);
            }
            IHierarchyProperty property = new HierarchyProperty(HierarchyType.Assets);

            property.Reset();
            if (!property.Find(this.m_RootInstanceID, null))
            {
                Debug.LogError("Root Asset with id " + this.m_RootInstanceID + " not found!!");
            }
            int minDepth = property.depth + (!base.showRootNode ? 1 : 0);

            int[]     expanded = base.expandedIDs.ToArray();
            Texture2D textured = EditorGUIUtility.FindTexture(EditorResourcesUtility.emptyFolderIconName);

            base.m_VisibleRows = new List <TreeViewItem>();
            while (property.NextWithDepthCheck(expanded, minDepth))
            {
                if (!this.foldersOnly || property.isFolder)
                {
                    TreeViewItem item;
                    depth = property.depth - minDepth;
                    if (property.isFolder)
                    {
                        item = new FolderTreeItem(property.instanceID, depth, null, property.name);
                    }
                    else
                    {
                        item = new NonFolderTreeItem(property.instanceID, depth, null, property.name);
                    }
                    if (property.isFolder && !property.hasChildren)
                    {
                        item.icon = textured;
                    }
                    else
                    {
                        item.icon = property.icon;
                    }
                    if (property.hasChildren)
                    {
                        item.AddChild(null);
                    }
                    base.m_VisibleRows.Add(item);
                }
            }
            TreeViewUtility.SetChildParentReferences(base.m_VisibleRows, base.m_RootItem);
            if (this.foldersFirst)
            {
                FoldersFirstRecursive(base.m_RootItem);
                base.m_VisibleRows.Clear();
                base.GetVisibleItemsRecursive(base.m_RootItem, base.m_VisibleRows);
            }
            base.m_NeedRefreshVisibleFolders = false;
            bool revealSelectionAndFrameLastSelected = false;

            base.m_TreeView.SetSelection(Selection.instanceIDs, revealSelectionAndFrameLastSelected);
        }
		private void SearchInFolders(HierarchyProperty property)
		{
			List<FilteredHierarchy.FilterResult> list = new List<FilteredHierarchy.FilterResult>();
			string[] baseFolders = ProjectWindowUtil.GetBaseFolders(this.m_SearchFilter.folders);
			string[] array = baseFolders;
			for (int i = 0; i < array.Length; i++)
			{
				string assetPath = array[i];
				property.SetSearchFilter(new SearchFilter());
				int mainAssetInstanceID = AssetDatabase.GetMainAssetInstanceID(assetPath);
				if (property.Find(mainAssetInstanceID, null))
				{
					property.SetSearchFilter(this.m_SearchFilter);
					int depth = property.depth;
					int[] expanded = null;
					while (property.NextWithDepthCheck(expanded, depth + 1))
					{
						FilteredHierarchy.FilterResult item = new FilteredHierarchy.FilterResult();
						this.CopyPropertyData(ref item, property);
						list.Add(item);
					}
				}
			}
			this.m_Results = list.ToArray();
		}
 private void SearchInFolders(HierarchyProperty property)
 {
   List<FilteredHierarchy.FilterResult> filterResultList = new List<FilteredHierarchy.FilterResult>();
   foreach (string baseFolder in ProjectWindowUtil.GetBaseFolders(this.m_SearchFilter.folders))
   {
     property.SetSearchFilter(new SearchFilter());
     int mainAssetInstanceId = AssetDatabase.GetMainAssetInstanceID(baseFolder);
     if (property.Find(mainAssetInstanceId, (int[]) null))
     {
       property.SetSearchFilter(this.m_SearchFilter);
       int depth = property.depth;
       int[] expanded = (int[]) null;
       while (property.NextWithDepthCheck(expanded, depth + 1))
       {
         FilteredHierarchy.FilterResult result = new FilteredHierarchy.FilterResult();
         this.CopyPropertyData(ref result, property);
         filterResultList.Add(result);
       }
     }
   }
   this.m_Results = filterResultList.ToArray();
 }