public override void FetchData() { m_RootItem = new TreeViewItem(0, 0, null, "Invisible Root Item"); SetExpanded(m_RootItem, true); // ensure always visible Texture2D folderIcon = EditorGUIUtility.FindTexture(EditorResources.folderIconName); // We want three roots: Favorites, Assets, and Saved Filters List <TreeViewItem> visibleRoots = new List <TreeViewItem>(); // Fetch asset folders int assetsFolderInstanceID = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID("Assets"); int depth = 0; string displayName = "Assets"; //CreateDisplayName (assetsFolderInstanceID); AssetsTreeViewDataSource.RootTreeItem assetRootItem = new AssetsTreeViewDataSource.RootTreeItem(assetsFolderInstanceID, depth, m_RootItem, displayName); assetRootItem.icon = folderIcon; ReadAssetDatabase("Assets", assetRootItem, depth + 1); // Fetch packages folder displayName = PackageManager.Folders.GetPackagesPath(); AssetsTreeViewDataSource.RootTreeItem packagesRootItem = new AssetsTreeViewDataSource.RootTreeItem(ProjectBrowser.kPackagesFolderInstanceId, depth, m_RootItem, displayName); depth++; packagesRootItem.icon = folderIcon; var packages = PackageManagerUtilityInternal.GetAllVisiblePackages(skipHiddenPackages); foreach (var package in packages) { var packageFolderInstanceId = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID(package.assetPath); displayName = !string.IsNullOrEmpty(package.displayName) ? package.displayName : package.name; AssetsTreeViewDataSource.PackageTreeItem packageItem = new AssetsTreeViewDataSource.PackageTreeItem(packageFolderInstanceId, depth, packagesRootItem, displayName); packageItem.icon = folderIcon; packagesRootItem.AddChild(packageItem); ReadAssetDatabase(package.assetPath, packageItem, depth + 1); } // Fetch saved filters TreeViewItem savedFiltersRootItem = SavedSearchFilters.ConvertToTreeView(); savedFiltersRootItem.parent = m_RootItem; // Order visibleRoots.Add(savedFiltersRootItem); visibleRoots.Add(assetRootItem); visibleRoots.Add(packagesRootItem); m_RootItem.children = visibleRoots; // Get global expanded state of roots foreach (TreeViewItem item in m_RootItem.children) { // Do not expand Packages root item if (item.id == ProjectBrowser.kPackagesFolderInstanceId) { continue; } bool expanded = EditorPrefs.GetBool(kProjectBrowserString + item.displayName, true); SetExpanded(item, expanded); } m_NeedRefreshRows = true; }
public override void FetchData() { bool firstInitialize = !isInitialized; m_RootItem = new TreeViewItem(0, 0, null, "Invisible Root Item"); SetExpanded(m_RootItem, true); // ensure always visible // We want three roots: Favorites, Assets, and Packages List <TreeViewItem> visibleRoots = new List <TreeViewItem>(); // Favorites root TreeViewItem savedFiltersRootItem = SavedSearchFilters.ConvertToTreeView(); visibleRoots.Add(savedFiltersRootItem); // Assets root int assetsFolderInstanceID = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID("Assets"); int depth = 0; string displayName = "Assets"; AssetsTreeViewDataSource.RootTreeItem assetRootItem = new AssetsTreeViewDataSource.RootTreeItem(assetsFolderInstanceID, depth, m_RootItem, displayName); assetRootItem.icon = s_FolderIcon; visibleRoots.Add(assetRootItem); // Packages root displayName = PackageManager.Folders.GetPackagesPath(); AssetsTreeViewDataSource.RootTreeItem packagesRootItem = new AssetsTreeViewDataSource.RootTreeItem(ProjectBrowser.kPackagesFolderInstanceId, depth, m_RootItem, displayName); packagesRootItem.icon = s_FolderIcon; visibleRoots.Add(packagesRootItem); m_RootItem.children = visibleRoots; // Set global expanded state for roots from EditorPrefs (must be before building the rows) if (firstInitialize) { foreach (TreeViewItem item in m_RootItem.children) { bool expanded = EditorPrefs.GetBool(kProjectBrowserString + item.displayName, true); SetExpanded(item, expanded); } } // Build rows //----------- m_Rows = new List <TreeViewItem>(100); // Favorites savedFiltersRootItem.parent = m_RootItem; m_Rows.Add(savedFiltersRootItem); if (IsExpanded(savedFiltersRootItem)) { foreach (var f in savedFiltersRootItem.children) { m_Rows.Add(f); } } else { savedFiltersRootItem.children = CreateChildListForCollapsedParent(); } // Asset folders m_Rows.Add(assetRootItem); ReadAssetDatabase("Assets", assetRootItem, depth + 1, m_Rows); // Individual Package folders (under the Packages root item) m_Rows.Add(packagesRootItem); var packages = PackageManagerUtilityInternal.GetAllVisiblePackages(skipHiddenPackages); if (IsExpanded(packagesRootItem)) { depth++; foreach (var package in packages) { var packageFolderInstanceId = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID(package.assetPath); displayName = !string.IsNullOrEmpty(package.displayName) ? package.displayName : package.name; AssetsTreeViewDataSource.PackageTreeItem packageItem = new AssetsTreeViewDataSource.PackageTreeItem(packageFolderInstanceId, depth, packagesRootItem, displayName); packageItem.icon = s_FolderIcon; packagesRootItem.AddChild(packageItem); m_Rows.Add(packageItem); ReadAssetDatabase(package.assetPath, packageItem, depth + 1, m_Rows); } } else { if (packages.Length > 0) { packagesRootItem.children = CreateChildListForCollapsedParent(); } } m_NeedRefreshRows = false; }