static void LoadAssets() { // Get all assets that contained in different Resources folders var rootPaths = AssetDatabase.FindAssets("Resources").Select(item => AssetDatabase.GUIDToAssetPath(item)); _assets = new List <AssetItem>(); foreach (var path in rootPaths) { var dirInfo = new DirectoryInfo(path); // Exclude temporary folder if it contains "Resources" word if (!string.Equals(dirInfo.Name, _tempFolderName)) { var rootItem = new AssetItem(); rootItem.path = path; rootItem.name = dirInfo.Name; rootItem.isFolder = true; rootItem.AddChild(GetSubAssets(rootItem.path)); _assets.Add(rootItem); } } if (File.Exists(GetAbsolutePath(_saveDataPath))) { if (!cleared) { LoadData(); } } init = true; }
/// <summary> /// Add childs array. /// </summary> /// <returns><c>true</c>, if child was added, <c>false</c> otherwise.</returns> /// <param name="child">Child.</param> public bool AddChild(AssetItem[] child) { childAssetItems = new List <AssetItem>(); for (int i = 0; i < child.Length; i++) { AssetItem item = new AssetItem(); item.name = child[i].name; item.path = child[i].path; item.enabled = child[i].enabled; item.opened = child[i].opened; item.isFolder = child[i].isFolder; if (child[i].childAssetItems != null) { item.AddChild(child[i].childAssetItems.ToArray()); } childAssetItems.Add(item); } return(childAssetItems.Count > 0); }
/// <summary> /// Add childs array. /// </summary> /// <returns><c>true</c>, if child was added, <c>false</c> otherwise.</returns> /// <param name="child">Child.</param> public bool AddChild(AssetItem[] child) { childAssetItems = new List<AssetItem>(); for (int i = 0; i < child.Length; i++) { AssetItem item = new AssetItem(); item.name = child[i].name; item.path = child[i].path; item.enabled = child[i].enabled; item.opened = child[i].opened; item.isFolder = child[i].isFolder; if (child[i].childAssetItems != null) { item.AddChild(child[i].childAssetItems.ToArray()); } childAssetItems.Add(item); } return childAssetItems.Count > 0; }
static AssetItem[] GetSubAssets(string path) { // Get all assets contains in folder with "path" path var allSubAssets = AssetDatabase.FindAssets("", new string[] { path }).Select(item => AssetDatabase.GUIDToAssetPath(item)); //Select assets that are in current folder (path) only. No subfolders and other folders allSubAssets = allSubAssets.Where(item => string.Equals(Path.GetDirectoryName(item), path)).Distinct <string>(); var subAssets = new List <AssetItem>(); //Find content foreach (var asset in allSubAssets) { FileAttributes attr = File.GetAttributes(@asset); bool isDirectory = (attr & FileAttributes.Directory) == FileAttributes.Directory; var item = new AssetItem(); item.isFolder = isDirectory; if (isDirectory) { var dirInfo = new DirectoryInfo(@asset); item.path = asset; item.name = dirInfo.Name; //Add items recursively (folders and content) item.AddChild(GetSubAssets(item.path)); } else { var fileInfo = new FileInfo(@asset); item.path = asset; item.name = fileInfo.Name; } subAssets.Add(item); } return(subAssets.ToArray()); }
static void LoadAssets() { // Get all assets that contained in different Resources folders var rootPaths = AssetDatabase.FindAssets("Resources").Select(item => AssetDatabase.GUIDToAssetPath(item)); _assets = new List<AssetItem>(); foreach(var path in rootPaths) { var dirInfo = new DirectoryInfo(path); // Exclude temporary folder if it contains "Resources" word if (!string.Equals(dirInfo.Name, _tempFolderName)) { var rootItem = new AssetItem(); rootItem.path = path; rootItem.name = dirInfo.Name; rootItem.isFolder = true; rootItem.AddChild(GetSubAssets(rootItem.path)); _assets.Add(rootItem); } } if (File.Exists(GetAbsolutePath(_saveDataPath))) { if (!cleared) { LoadData(); } } init = true; }
static AssetItem[] GetSubAssets(string path) { // Get all assets contains in folder with "path" path var allSubAssets = AssetDatabase.FindAssets("", new string[] { path }).Select(item => AssetDatabase.GUIDToAssetPath(item)); //Select assets that are in current folder (path) only. No subfolders and other folders allSubAssets = allSubAssets.Where(item => string.Equals(Path.GetDirectoryName(item), path)).Distinct<string>(); var subAssets = new List<AssetItem>(); //Find content foreach(var asset in allSubAssets) { FileAttributes attr = File.GetAttributes(@asset); bool isDirectory = (attr & FileAttributes.Directory) == FileAttributes.Directory; var item = new AssetItem(); item.isFolder = isDirectory; if (isDirectory) { var dirInfo = new DirectoryInfo(@asset); item.path = asset; item.name = dirInfo.Name; //Add items recursively (folders and content) item.AddChild(GetSubAssets(item.path)); } else { var fileInfo = new FileInfo(@asset); item.path = asset; item.name = fileInfo.Name; } subAssets.Add(item); } return subAssets.ToArray(); }