/// <summary> /// 获取一个AB包文件 /// </summary> /// <param name="path">相对路径</param> /// <returns></returns> private AssetBundle LoadAssetBundle(string path) { path = Path2Key(path); if (!m_ABDic.TryGetValue(path, out AssetBundle ab)) { string fullName = Convert2FullPath(path); ab = AssetBundle.LoadFromFile(fullName); m_ABDic.Add(path, ab); //加载当前AB包的依赖包 //string[] dependencies = m_Mainfest.GetAllDependencies(ab.name); string[] dependencies = m_DependenceInfo.GetAllDependencies(ab.name); foreach (var item in dependencies) { string key = GetNoVariantName(item); // 对key去除.ab if (!m_ABDic.ContainsKey(key)) { LoadAssetBundle(key); } } } return(ab); }
/// <summary> /// 获取一个AB包文件 /// </summary> /// <param name="path">相对路径</param> /// <returns></returns> public AssetBundle GetAssetBundle(string path) { path = Path2Key(path); path = path.Replace('\\', '/'); if (!m_ABDic.TryGetValue(path, out AssetBundle ab)) { string abName = string.IsNullOrEmpty(path) ? "" : "/" + path; ab = AssetBundle.LoadFromFile(m_ABPath + abName + m_Variant); if (ab == null) { Debug.LogError(path + " 为空"); } m_ABDic.Add(path, ab); } //加载当前AB包的依赖包 //string[] dependencies = m_Mainfest.GetAllDependencies(ab.name); string[] dependencies = m_DependenceInfo.GetAllDependencies(ab.name); foreach (var item in dependencies) { string key = Name2Key(item); // 对key去除.ab if (!m_ABDic.ContainsKey(key)) { AssetBundle dependAb = GetAssetBundle(key); } } return(ab); }