| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using UnityEngine;
- #if UNITY_EDITOR
- using UnityEditor;
- #endif
- namespace Model
- {
- public static class ResourcesHelper
- {
- public static string[] GetDependencies(string assetBundleName)
- {
- string[] dependencies = new string[0];
- if (!Define.IsAsync)
- {
- #if UNITY_EDITOR
- dependencies = AssetDatabase.GetAssetBundleDependencies(assetBundleName, true);
- #endif
- }
- else
- {
- dependencies = ResourcesComponent.AssetBundleManifestObject.GetAllDependencies(assetBundleName);
- }
- return dependencies;
- }
- public static string[] GetSortedDependencies(string assetBundleName)
- {
- Dictionary<string, int> info = new Dictionary<string, int>();
- List<string> parents = new List<string>();
- CollectDependencies(parents, assetBundleName, info);
- info.Remove(assetBundleName);
- string[] ss = info.OrderByDescending(x => x.Value).Select(x => x.Key).ToArray();
- return ss;
- }
- public static void CollectDependencies(List<string> parents, string assetBundleName, Dictionary<string, int> info)
- {
- parents.Add(assetBundleName);
- string[] deps = GetDependencies(assetBundleName);
- foreach (string parent in parents)
- {
- if (!info.ContainsKey(parent))
- {
- info[parent] = 0;
- }
- info[parent] += deps.Length;
- }
- foreach (string dep in deps)
- {
- if (parents.Contains(dep))
- {
- throw new Exception($"包有循环依赖,请重新标记: {assetBundleName} {dep}");
- }
- CollectDependencies(parents, dep, info);
- }
- parents.RemoveAt(parents.Count - 1);
- }
- }
- }
|