private void ReadAssetDatabase(string assetFolderRootPath, TreeViewItem parent, int baseDepth, IList <TreeViewItem> allRows) { // Read from Assets directory IHierarchyProperty property = new HierarchyProperty(assetFolderRootPath); property.Reset(); if (!IsExpanded(parent)) { if (HasSubFolders(property)) { parent.children = CreateChildListForCollapsedParent(); } return; } Texture2D folderIcon = EditorGUIUtility.FindTexture(EditorResources.folderIconName); List <TreeViewItem> allFolders = new List <TreeViewItem>(); var expandedIDs = m_TreeView.state.expandedIDs.ToArray(); while (property.Next(expandedIDs)) { if (property.isFolder) { AssetsTreeViewDataSource.FolderTreeItem folderItem = new AssetsTreeViewDataSource.FolderTreeItem(property.guid, !property.hasChildren, property.GetInstanceIDIfImported(), baseDepth + property.depth, null, property.name); folderItem.icon = folderIcon; allFolders.Add(folderItem); allRows.Add(folderItem); if (!IsExpanded(folderItem)) { if (HasSubFolders(property)) { folderItem.children = CreateChildListForCollapsedParent(); } } else // expanded status does not get updated when deleting/moving folders. We need to check if the expanded folder still has subFolders when reading the AssetDatabase { if (!HasSubFolders(property)) { SetExpanded(folderItem, false); } } } } // Fix references TreeViewUtility.SetChildParentReferences(allFolders, parent); }
private void ReadAssetDatabase(string assetFolderRootPath, TreeViewItem parent, int baseDepth) { // Read from Assets directory IHierarchyProperty property = new HierarchyProperty(assetFolderRootPath); property.Reset(); Texture2D folderIcon = EditorGUIUtility.FindTexture(EditorResources.folderIconName); List <TreeViewItem> allFolders = new List <TreeViewItem>(); while (property.Next(null)) { if (property.isFolder) { AssetsTreeViewDataSource.FolderTreeItem folderItem = new AssetsTreeViewDataSource.FolderTreeItem(property.guid, !property.hasChildren, property.instanceID, baseDepth + property.depth, null, property.name); folderItem.icon = folderIcon; allFolders.Add(folderItem); } } // Fix references TreeViewUtility.SetChildParentReferences(allFolders, parent); }
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); }