예제 #1
0
        public static List <string> EnumerateAddressableFolder(string path, AddressableAssetSettings settings, bool recurseAll, IBuildLogger logger = null)
        {
            if (!AssetDatabase.IsValidFolder(path))
            {
                throw new Exception($"Path {path} cannot be enumerated because it does not exist");
            }

            AddressableAssetTree tree = m_PrecomputedTree != null ? m_PrecomputedTree : BuildAddressableTree(settings, logger);

            if (tree == null)
            {
                return(new List <string>());
            }

            AddLocalFilesToTreeIfNotEnumerated(tree, path, logger);

            List <string> files = new List <string>();

            using (logger.ScopedStep(LogLevel.Info, $"Enumerating Addressables Tree {path}"))
            {
                foreach (string file in tree.Enumerate(path, recurseAll))
                {
                    if (BuiltinSceneCache.Contains(file))
                    {
                        continue;
                    }
                    files.Add(file);
                }
            }
            return(files);
        }
예제 #2
0
        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;
                }
            }
        }
예제 #3
0
 static void BeginPrecomputedEnumerationSession(AddressableAssetSettings settings, bool prepopulateAssetsFolder, IBuildLogger logger)
 {
     using (logger.ScopedStep(LogLevel.Info, "AddressablesFileEnumeration.BeginPrecomputedEnumerationSession"))
     {
         m_PrecomputedTree = BuildAddressableTree(settings, logger);
         if (m_PrecomputedTree != null && prepopulateAssetsFolder)
         {
             AddLocalFilesToTreeIfNotEnumerated(m_PrecomputedTree, "Assets", logger);
         }
     }
 }
예제 #4
0
        internal static AddressableAssetTree BuildAddressableTree(AddressableAssetSettings settings, IBuildLogger logger = null)
        {
            using (logger.ScopedStep(LogLevel.Verbose, "BuildAddressableTree"))
            {
                if (!ExtractAddressablePaths(settings, out HashSet <string> paths))
                {
                    return(null);
                }

                AddressableAssetTree tree = new AddressableAssetTree();
                foreach (string path in paths)
                {
                    AddressableAssetTree.TreeNode node = tree.FindNode(path, true);
                    node.IsAddressable = true;
                }
                return(tree);
            }
        }
예제 #5
0
        public AddressableAssetSettingsLocator(AddressableAssetSettings settings)
        {
            m_Settings             = settings;
            LocatorId              = m_Settings.name;
            m_AddressableAssetTree = BuildAddressableTree(m_Settings);
            m_Cache        = new Dictionary <CacheKey, IList <IResourceLocation> >();
            m_keyToEntries = new Dictionary <object, HashSet <AddressableAssetEntry> >(m_Settings.labelTable.labelNames.Count);
            using (new AddressablesFileEnumerationScope(m_AddressableAssetTree))
            {
                foreach (AddressableAssetGroup g in m_Settings.groups)
                {
                    if (g == null)
                    {
                        continue;
                    }

                    foreach (AddressableAssetEntry e in g.entries)
                    {
                        if (e.guid == AddressableAssetEntry.EditorSceneListName)
                        {
                            if (e.parentGroup.GetSchema <GroupSchemas.PlayerDataGroupSchema>().IncludeBuildSettingsScenes)
                            {
                                e.GatherAllAssets(null, false, false, false, s =>
                                {
                                    AddEntriesToTables(m_keyToEntries, s);
                                    return(false);
                                });
                            }
                        }
                        else if (e.guid == AddressableAssetEntry.ResourcesName)
                        {
                            m_includeResourcesFolders = e.parentGroup.GetSchema <GroupSchemas.PlayerDataGroupSchema>().IncludeResourcesFolders;
                        }
                        else
                        {
                            AddEntriesToTables(m_keyToEntries, e);
                        }
                    }
                }
            }
        }
예제 #6
0
 static void EndPrecomputedEnumerationSession()
 {
     m_PrecomputedTree = null;
 }
예제 #7
0
 internal AddressablesFileEnumerationScope(AddressableAssetTree tree)
 {
     m_PrevTree        = m_PrecomputedTree;
     m_PrecomputedTree = tree;
 }
예제 #8
0
 static void GatherEntryLocations(AddressableAssetEntry entry, Type type, IList <IResourceLocation> locations, AddressableAssetTree assetTree)
 {
     if (!string.IsNullOrEmpty(entry.address) && entry.address.Contains("[") && entry.address.Contains("]"))
     {
         Debug.LogErrorFormat("Address '{0}' cannot contain '[ ]'.", entry.address);
         return;
     }
     using (new AddressablesFileEnumerationScope(assetTree))
     {
         entry.GatherAllAssets(null, true, true, false, e =>
         {
             if (e.IsScene)
             {
                 if (type == null || type == typeof(object) || type == typeof(SceneInstance) || AddressableAssetUtility.MapEditorTypeToRuntimeType(e.MainAssetType, false) == type)
                 {
                     locations.Add(new ResourceLocationBase(e.address, e.AssetPath, typeof(SceneProvider).FullName, typeof(SceneInstance)));
                 }
             }
             else if (type == null || (type.IsAssignableFrom(e.MainAssetType) && type != typeof(object)))
             {
                 locations.Add(new ResourceLocationBase(e.address, e.AssetPath, typeof(AssetDatabaseProvider).FullName, e.MainAssetType));
                 return(true);
             }
             else
             {
                 ObjectIdentifier[] ids = ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(new GUID(e.guid), EditorUserBuildSettings.activeBuildTarget);
                 if (ids.Length > 0)
                 {
                     foreach (var t in AddressableAssetEntry.GatherSubObjectTypes(ids, e.guid))
                     {
                         if (type.IsAssignableFrom(t))
                         {
                             locations.Add(new ResourceLocationBase(e.address, e.AssetPath, typeof(AssetDatabaseProvider).FullName, AddressableAssetUtility.MapEditorTypeToRuntimeType(t, false)));
                         }
                     }
                     return(true);
                 }
             }
             return(false);
         });
     }
 }