static void AddLocalFilesToTreeIfNotEnumerated(AddressableAssetTree tree, string path, IBuildLogger logger) { AddressableAssetTree.TreeNode pathNode = tree.FindNode(path, true); if (pathNode == null || pathNode.HasEnumerated) // Already enumerated { return; } pathNode.HasEnumerated = true; using (logger.ScopedStep(LogLevel.Info, $"Enumerating {path}")) { foreach (string filename in Directory.EnumerateFileSystemEntries(path, "*.*", SearchOption.AllDirectories)) { if (!AddressableAssetUtility.IsPathValidForEntry(filename)) { continue; } string convertedPath = filename.Replace('\\', '/'); var node = tree.FindNode(convertedPath, true); node.IsFolder = AssetDatabase.IsValidFolder(filename); node.HasEnumerated = true; } } }
IEnumerable <string> GetAllValidAssetPathsFromDirectory(string path, bool recurseAll) { var files = from file in Directory.EnumerateFiles(path, "*.*", recurseAll ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly) where AddressableAssetUtility.IsPathValidForEntry(file) let convertedPath = file.Replace('\\', '/') where !BuiltinSceneCache.Contains(convertedPath) select convertedPath; return(files); }
/// <summary> /// Gets an entry for this folder entry /// </summary> /// <param name="subAssetGuid"></param> /// <param name="subAssetPath"></param> /// <returns></returns> /// <remarks>Assumes that this asset entry is a valid folder asset</remarks> internal AddressableAssetEntry GetFolderSubEntry(string subAssetGuid, string subAssetPath) { string assetPath = AssetPath; if (string.IsNullOrEmpty(assetPath) || !subAssetPath.StartsWith(assetPath)) { return(null); } var settings = parentGroup.Settings; AddressableAssetEntry assetEntry = settings.FindAssetEntry(subAssetGuid); if (assetEntry != null) { if (assetEntry.IsSubAsset && assetEntry.ParentEntry == this) { return(assetEntry); } return(null); } string relativePath = subAssetPath.Remove(0, assetPath.Length + 1); string[] splitRelativePath = relativePath.Split('/'); string folderPath = assetPath; for (int i = 0; i < splitRelativePath.Length - 1; ++i) { folderPath = folderPath + "/" + splitRelativePath[i]; string folderGuid = AssetDatabase.AssetPathToGUID(folderPath); if (!AddressableAssetUtility.IsPathValidForEntry(folderPath)) { return(null); } var folderEntry = settings.CreateSubEntryIfUnique(folderGuid, address + "/" + folderPath.Remove(assetPath.Length), this); if (folderEntry != null) { folderEntry.IsInResources = IsInResources; folderEntry.m_Labels = m_Labels; folderEntry.IsFolder = true; } else { return(null); } } assetEntry = settings.CreateSubEntryIfUnique(subAssetGuid, address + relativePath, this); if (assetEntry == null || assetEntry.IsSubAsset == false) { return(null); } return(assetEntry); }
internal void GatherResourcesEntries(List <AddressableAssetEntry> assets, bool recurseAll, Func <AddressableAssetEntry, bool> entryFilter) { var settings = parentGroup.Settings; var pd = parentGroup.GetSchema <GroupSchemas.PlayerDataGroupSchema>(); if (pd.IncludeResourcesFolders) { foreach (var resourcesDir in GetResourceDirectories()) { foreach (var file in Directory.GetFiles(resourcesDir, "*.*", recurseAll ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)) { if (AddressableAssetUtility.IsPathValidForEntry(file)) { var g = AssetDatabase.AssetPathToGUID(file); var addr = GetResourcesPath(file); var entry = settings.CreateSubEntryIfUnique(g, addr, this); if (entry != null) //TODO - it's probably really bad if this is ever null. need some error detection { entry.IsInResources = true; entry.m_Labels = m_Labels; if (entryFilter == null || entryFilter(entry)) { assets.Add(entry); } } } } if (!recurseAll) { foreach (var folder in Directory.GetDirectories(resourcesDir)) { if (AssetDatabase.IsValidFolder(folder)) { var entry = settings.CreateSubEntryIfUnique(AssetDatabase.AssetPathToGUID(folder), GetResourcesPath(folder), this); if (entry != null) //TODO - it's probably really bad if this is ever null. need some error detection { entry.IsInResources = true; entry.m_Labels = m_Labels; if (entryFilter == null || entryFilter(entry)) { assets.Add(entry); } } } } } } } }
/// <summary> /// Gathers all asset entries. Each explicit entry may contain multiple sub entries. For example, addressable folders create entries for each asset contained within. /// </summary> /// <param name="assets">The generated list of entries. For simple entries, this will contain just the entry itself if specified.</param> /// <param name="includeSelf">Determines if the entry should be contained in the result list or just sub entries.</param> /// <param name="recurseAll">Determines if full recursion should be done when gathering entries.</param> /// <param name="includeSubObjects">Determines if sub objects such as sprites should be included.</param> /// <param name="entryFilter">Optional predicate to run against each entry, only returning those that pass. A null filter will return all entries</param> public void GatherAllAssets(List <AddressableAssetEntry> assets, bool includeSelf, bool recurseAll, bool includeSubObjects, Func <AddressableAssetEntry, bool> entryFilter = null) { var settings = parentGroup.Settings; if (guid == EditorSceneListName) { foreach (var s in BuiltinSceneCache.scenes) { if (s.enabled) { var entry = settings.CreateSubEntryIfUnique(s.guid.ToString(), Path.GetFileNameWithoutExtension(s.path), this); if (entry != null) //TODO - it's probably really bad if this is ever null. need some error detection { entry.IsInSceneList = true; entry.m_Labels = m_Labels; if (entryFilter == null || entryFilter(entry)) { assets.Add(entry); } } } } } else if (guid == ResourcesName) { foreach (var resourcesDir in Directory.GetDirectories("Assets", "Resources", SearchOption.AllDirectories)) { foreach (var file in Directory.GetFiles(resourcesDir, "*.*", recurseAll ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)) { if (AddressableAssetUtility.IsPathValidForEntry(file)) { var g = AssetDatabase.AssetPathToGUID(file); var addr = GetResourcesPath(file); var entry = settings.CreateSubEntryIfUnique(g, addr, this); if (entry != null) //TODO - it's probably really bad if this is ever null. need some error detection { entry.IsInResources = true; entry.m_Labels = m_Labels; if (entryFilter == null || entryFilter(entry)) { assets.Add(entry); } } } } if (!recurseAll) { foreach (var folder in Directory.GetDirectories(resourcesDir)) { if (AssetDatabase.IsValidFolder(folder)) { var entry = settings.CreateSubEntryIfUnique(AssetDatabase.AssetPathToGUID(folder), GetResourcesPath(folder), this); if (entry != null) //TODO - it's probably really bad if this is ever null. need some error detection { entry.IsInResources = true; entry.m_Labels = m_Labels; if (entryFilter == null || entryFilter(entry)) { assets.Add(entry); } } } } } } } else { var path = AssetPath; if (string.IsNullOrEmpty(path)) { return; } if (AssetDatabase.IsValidFolder(path)) { foreach (var fi in Directory.GetFiles(path, "*.*", recurseAll ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)) { var file = fi.Replace('\\', '/'); if (AddressableAssetUtility.IsPathValidForEntry(file)) { var subGuid = AssetDatabase.AssetPathToGUID(file); if (!BuiltinSceneCache.Contains(new GUID(subGuid))) { var entry = settings.CreateSubEntryIfUnique(subGuid, address + GetRelativePath(file, path), this); if (entry != null) { entry.IsInResources = IsInResources; //if this is a sub-folder of Resources, copy it on down entry.m_Labels = m_Labels; if (entryFilter == null || entryFilter(entry)) { assets.Add(entry); } } } } } if (!recurseAll) { foreach (var fo in Directory.GetDirectories(path, "*.*", SearchOption.TopDirectoryOnly)) { var folder = fo.Replace('\\', '/'); if (AssetDatabase.IsValidFolder(folder)) { var entry = settings.CreateSubEntryIfUnique(AssetDatabase.AssetPathToGUID(folder), address + GetRelativePath(folder, path), this); if (entry != null) { entry.IsInResources = IsInResources; //if this is a sub-folder of Resources, copy it on down entry.m_Labels = m_Labels; if (entryFilter == null || entryFilter(entry)) { assets.Add(entry); } } } } } } else { if (MainAssetType == typeof(AddressableAssetEntryCollection)) { var col = AssetDatabase.LoadAssetAtPath <AddressableAssetEntryCollection>(AssetPath); if (col != null) { foreach (var e in col.Entries) { var entry = settings.CreateSubEntryIfUnique(e.guid, e.address, this); if (entry != null) { entry.IsInResources = e.IsInResources; foreach (var l in e.labels) { entry.SetLabel(l, true, false); } foreach (var l in m_Labels) { entry.SetLabel(l, true, false); } if (entryFilter == null || entryFilter(entry)) { assets.Add(entry); } } } } } else { if (includeSelf) { if (entryFilter == null || entryFilter(this)) { assets.Add(this); } } if (includeSubObjects) { var mainType = AssetDatabase.GetMainAssetTypeAtPath(AssetPath); if (mainType == typeof(SpriteAtlas)) { var atlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(AssetPath); var sprites = new Sprite[atlas.spriteCount]; atlas.GetSprites(sprites); for (int i = 0; i < atlas.spriteCount; i++) { var spriteName = sprites[i].name; if (spriteName.EndsWith("(Clone)")) { spriteName = spriteName.Replace("(Clone)", ""); } var namedAddress = string.Format("{0}[{1}]", address, spriteName); var newEntry = new AddressableAssetEntry("", namedAddress, parentGroup, true); newEntry.IsSubAsset = true; newEntry.ParentEntry = this; newEntry.IsInResources = IsInResources; assets.Add(newEntry); } } var objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(AssetPath); for (int i = 0; i < objs.Length; i++) { var o = objs[i]; var t = o.GetType(); var namedAddress = string.Format("{0}[{1}]", address, o.name); var newEntry = new AddressableAssetEntry("", namedAddress, parentGroup, true); newEntry.IsSubAsset = true; newEntry.ParentEntry = this; newEntry.IsInResources = IsInResources; assets.Add(newEntry); } } } } } }
public void GatherAllAssets(List <AddressableAssetEntry> assets, bool includeSelf, bool recurseAll, Func <AddressableAssetEntry, bool> entryFilter = null) { var settings = parentGroup.Settings; if (guid == EditorSceneListName) { foreach (var s in BuiltinSceneCache.scenes) { if (s.enabled) { var entry = settings.CreateSubEntryIfUnique(s.guid.ToString(), Path.GetFileNameWithoutExtension(s.path), this); if (entry != null) //TODO - it's probably really bad if this is ever null. need some error detection { entry.IsInSceneList = true; entry.m_Labels = m_Labels; if (entryFilter == null || entryFilter(entry)) { assets.Add(entry); } } } } } else if (guid == ResourcesName) { foreach (var resourcesDir in Directory.GetDirectories("Assets", "Resources", SearchOption.AllDirectories)) { foreach (var file in Directory.GetFiles(resourcesDir, "*.*", recurseAll ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)) { if (AddressableAssetUtility.IsPathValidForEntry(file)) { var g = AssetDatabase.AssetPathToGUID(file); var addr = GetResourcesPath(file); var entry = settings.CreateSubEntryIfUnique(g, addr, this); if (entry != null) //TODO - it's probably really bad if this is ever null. need some error detection { entry.IsInResources = true; entry.m_Labels = m_Labels; if (entryFilter == null || entryFilter(entry)) { assets.Add(entry); } } } } if (!recurseAll) { foreach (var folder in Directory.GetDirectories(resourcesDir)) { if (AssetDatabase.IsValidFolder(folder)) { var entry = settings.CreateSubEntryIfUnique(AssetDatabase.AssetPathToGUID(folder), GetResourcesPath(folder), this); if (entry != null) //TODO - it's probably really bad if this is ever null. need some error detection { entry.IsInResources = true; entry.m_Labels = m_Labels; if (entryFilter == null || entryFilter(entry)) { assets.Add(entry); } } } } } } } else { var path = AssetDatabase.GUIDToAssetPath(guid); if (string.IsNullOrEmpty(path)) { return; } if (AssetDatabase.IsValidFolder(path)) { foreach (var fi in Directory.GetFiles(path, "*.*", recurseAll ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)) { var file = fi.Replace('\\', '/'); if (AddressableAssetUtility.IsPathValidForEntry(file)) { var subGuid = AssetDatabase.AssetPathToGUID(file); if (!BuiltinSceneCache.Contains(new GUID(subGuid))) { var entry = settings.CreateSubEntryIfUnique(subGuid, address + GetRelativePath(file, path), this); if (entry != null) { entry.IsInResources = IsInResources; //if this is a sub-folder of Resources, copy it on down entry.m_Labels = m_Labels; if (entryFilter == null || entryFilter(entry)) { assets.Add(entry); } } } } } if (!recurseAll) { foreach (var fo in Directory.GetDirectories(path, "*.*", SearchOption.TopDirectoryOnly)) { var folder = fo.Replace('\\', '/'); if (AssetDatabase.IsValidFolder(folder)) { var entry = settings.CreateSubEntryIfUnique(AssetDatabase.AssetPathToGUID(folder), address + GetRelativePath(folder, path), this); if (entry != null) { entry.IsInResources = IsInResources; //if this is a sub-folder of Resources, copy it on down entry.m_Labels = m_Labels; if (entryFilter == null || entryFilter(entry)) { assets.Add(entry); } } } } } } else { if (AssetDatabase.GetMainAssetTypeAtPath(path) == typeof(AddressableAssetEntryCollection)) { var col = AssetDatabase.LoadAssetAtPath <AddressableAssetEntryCollection>(AssetPath); if (col != null) { foreach (var e in col.Entries) { var entry = settings.CreateSubEntryIfUnique(e.guid, e.address, this); if (entry != null) { entry.IsInResources = e.IsInResources; foreach (var l in e.labels) { entry.SetLabel(l, true, false); } foreach (var l in m_Labels) { entry.SetLabel(l, true, false); } if (entryFilter == null || entryFilter(entry)) { assets.Add(entry); } } } } } else { if (includeSelf) { if (entryFilter == null || entryFilter(this)) { assets.Add(this); } } } } } }