bool BuildDirectoryRecursive(DirectoryInfo dir_info, TreeViewItem parent) { bool needExpend = false; DirectoryInfo[] dir_arr = dir_info.GetDirectories(); parent.children = new List <TreeViewItem>(dir_arr.Length); for (int i = 0; i < dir_arr.Length; i++) { DirectoryInfo current_dir = dir_arr[i]; DirectoryTreeItem item = new DirectoryTreeItem(parent.depth + 1, current_dir); parent.children.Add(item); if (item.isExport) { needExpend = true; } if (BuildDirectoryRecursive(current_dir, item)) { needExpend = true; ExpandedItems.Add(item.id); } item.Check(); } return(needExpend); }
//指定フォルダまですべて展開 private void ExpandAll(DirectoryInfo info) { //ルートドライブ群取得 ObservableCollection <DirectoryTreeItem> subTrees = GetDrives(); //フォルダをさかのぼってすべてのフォルダ名取得 List <DirectoryInfo> dirInfos = GetAllDirectoryInfo(info); //上から順番に展開していく DirectoryTreeItem subTree = null; for (int i = dirInfos.Count - 1; i >= 0; i--) { for (int ii = 0; ii < subTrees.Count; ii++) { //名前一致で、そのツリーを展開 if (subTrees[ii].DirectoryInfo.Name == dirInfos[i].Name) { subTree = subTrees[ii]; subTree.IsExpanded = true; //ツリー展開、ここでサブフォルダが追加される subTree.IsSelected = true; subTree.BringIntoView(); //見えるところまでスクロール subTree.Focus(); subTrees = subTree.SubDirectorys; //次のサブフォルダ群 break; } } } //指定フォルダのサブフォルダは展開しない(どっちでもいい) if (subTree != null) { subTree.IsExpanded = false; } }
//サブフォルダツリー追加 public void AddSubDirectory() { Items.Remove(Dummy);//ダミーのTreeViewItemを削除 //すべてのサブフォルダを追加 System.IO.DirectoryInfo[] directories = DirectoryInfo.GetDirectories(); for (int i = 0; i < directories.Length; i++) { ////隠しフォルダ、システムフォルダは除外する var fileAttributes = directories[i].Attributes; if ((fileAttributes & System.IO.FileAttributes.Hidden) == System.IO.FileAttributes.Hidden || (fileAttributes & System.IO.FileAttributes.System) == System.IO.FileAttributes.System) { continue; } //サブフォルダにもアクセスできるフォルダのみItem追加 try { //これが通れば directories[i].GetDirectories(); //追加 var item = new DirectoryTreeItem(directories[i]); Items.Add(item); SubDirectorys.Add(item); } catch (Exception) { } } IsAdd = true;//サブフォルダ作成済みフラグ }
protected override void DoubleClickedItem(int id) { DirectoryTreeItem item = FindItem(id, rootItem) as DirectoryTreeItem; if (item.isExport) { AssetBundleBrowserMain.instance.ShowAssetBundle(item.assetBundle); } }
void CheckRecursive(List <string> abs, DirectoryTreeItem parent) { var files = parent.directoryInfo.GetFiles("*.*", SearchOption.TopDirectoryOnly); foreach (var file in files) { string path = file.FullName.Replace('\\', '/').Replace(Application.dataPath, "Assets"); AssetImporter ai = AssetImporter.GetAtPath(path); if (ai != null && ai.assetBundleName != String.Empty) { abs.Add(string.Format("[{0}-{1}]", file.Name, ai.assetBundleName)); } } foreach (DirectoryTreeItem child in parent.children) { if (!child.isExport) { CheckRecursive(abs, child); } } }
void CellGUI(Rect cellRect, DirectoryTreeItem item, Columns column, ref RowGUIArgs args) { // Center cell rect vertically (makes it easier to place controls, icons etc in the cells) CenterRectUsingSingleLineHeight(ref cellRect); Event evt = Event.current; switch (column) { case Columns.Folder: Rect toggleRect = cellRect; cellRect.width -= 4; toggleRect.x += GetContentIndent(args.item); toggleRect.width = 16f; EditorGUI.BeginChangeCheck(); bool isExport = EditorGUI.Toggle(toggleRect, item.isExport); if (EditorGUI.EndChangeCheck()) { item.SetExport(isExport); ReloadData(); AssetBundleBrowserMain.instance.FreshManageTab(); } args.rowRect = cellRect; if (evt.type == EventType.MouseDown && cellRect.Contains(evt.mousePosition)) { SelectionClick(args.item, false); } base.RowGUI(args); break; //case Columns.Export: // Rect toggleRect = cellRect; // toggleRect.x += (cellRect.width - kToggleWidth) * 0.5f; // toggleRect.width = kToggleWidth; // bool isExport = EditorGUI.Toggle(toggleRect, item.isExport); // if(isExport != item.isExport) // { // } //DrawRect(cellRect.x, cellRect.y,1, cellRect.height,Color.gray); //DrawRect(cellRect.x + cellRect.width, cellRect.y , 1, cellRect.height, Color.gray); //break; case Columns.Bundle: Rect labelRect = cellRect; Color oldColor = GUI.color; bool NameError = item.isExport && item.curAssetBundle != item.assetBundle; if (NameError) { //命名规范检测 labelRect.x += cellRect.height; Rect messageRect = new Rect(cellRect.x, cellRect.y, cellRect.height, cellRect.height); GUI.Label(messageRect, new GUIContent(MessageSystem.GetIcon(MessageType.Error), "Incorrect name detected")); } else if (item.warnningMsg != string.Empty) { //检测是否包含自定义命名的ab包 labelRect.x += cellRect.height; Rect messageRect = new Rect(cellRect.x, cellRect.y, cellRect.height, cellRect.height); GUI.Label(messageRect, new GUIContent(MessageSystem.GetIcon(MessageType.Warning), item.warnningMsg)); } GUI.color = NameError ? Color.red : oldColor; EditorGUI.LabelField(labelRect, item.curAssetBundle); GUI.color = oldColor; //DrawRect(cellRect.x - 4, cellRect.y, 1, cellRect.height, Color.gray); break; } }
private void GetAlbumInfoInternal() { _logger.LogInformation("Scanning album {_albumRootPath} structure", _albumRootPath); _cache.Clear(); Queue <TreeItem> directoryQueue = new Queue <TreeItem>(); var tempRoot = new DirectoryTreeItem("\\", null, "the album", _albumRootPath); directoryQueue.Enqueue(tempRoot); _cache[tempRoot.Id] = tempRoot; while (directoryQueue.Count > 0) { var currentNode = directoryQueue.Dequeue(); bool errorLogged = false; try { var files = Directory.GetFiles(currentNode.FullPath, "*", SearchOption.TopDirectoryOnly); foreach (var filepath in files) { if (MediaFileTreeItem.IsAnInstance(filepath)) { var relpath = Path.GetRelativePath(_albumRootPath, filepath); var item = MediaFileTreeItem.GetNew( relpath, currentNode, Path.GetFileName(filepath), filepath); _cache[item.Id] = item; } } } catch (Exception ex) { _logger.LogError(ex, $"Error enumerating files in {currentNode.FullPath}: {ex.Message}"); errorLogged = true; } try { var directories = Directory.EnumerateDirectories(currentNode.FullPath, "*", SearchOption.TopDirectoryOnly); foreach (var dir in directories) { var relpath = Path.GetRelativePath(_albumRootPath, dir); var childNode = new DirectoryTreeItem(relpath, currentNode, dir); _cache[childNode.Id] = childNode; directoryQueue.Enqueue(childNode); if (currentNode == tempRoot && childNode.Name == RemovedFilesDirectory) { _albumTrash = currentNode; } } } catch (Exception ex) { if (!errorLogged) { _logger.LogError(ex, $"Error enumerating subdirectories in {currentNode.FullPath}: {ex.Message}"); } } currentNode.SortChildren(); } CutTheTree(tempRoot); _albumInfoRoot = tempRoot; }