Пример #1
0
 /// <summary>
 /// 获取ABManifest系统类的依赖项
 /// </summary>
 /// <param name="abName"></param>
 /// <returns></returns>
 public string[] RetrivalDependce(string abName)
 {
     if (!string.IsNullOrEmpty(abName))
     {
         return(manifest?.GetAllDependencies(abName));
     }
     return(null);
 }
Пример #2
0
        public T LoadAsset <T>(string path) where T : class
        {
            string absolutepath = path;

            path = PathUtils.NormalizePath(path);

            Debug.Log("[LoadAsset]: " + path);
            //打的ab包都资源名称和文件名都是小写的
            string assetBundleName = PathUtils.GetAssetBundleNameWithPath(path, assetRootPath);

            //加载Manifest文件
            LoadManifest();

            //获取文件依赖列表
            string[] dependencies = manifest.GetAllDependencies(assetBundleName);

            //加载依赖资源
            List <AssetBundle> assetbundleList = new List <AssetBundle>();

            foreach (string fileName in dependencies)
            {
                string dependencyPath = assetRootPath + "/" + fileName;
                Debug.Log("[AssetBundle]加载依赖资源: " + dependencyPath);
                assetbundleList.Add(AssetBundle.LoadFromFile(dependencyPath));
            }
            //4加载目标资源
            AssetBundle assetBundle = null;

            Debug.Log("[AssetBundle]加载目标资源: " + path);
            assetBundle = AssetBundle.LoadFromFile(path);
            assetbundleList.Insert(0, assetBundle);

            Object obj = assetBundle.LoadAsset(Path.GetFileNameWithoutExtension(path), typeof(T));

            //释放依赖资源
            UnloadAssetbundle(assetbundleList);

            //加入缓存
            AssetManager.Instance.pushCache(absolutepath, obj);

            return(obj as T);
        }
Пример #3
0
 /// <summary>
 /// 依存直取得
 /// </summary>
 public static string[] TryGetDependencies(this AssetBundleManifest self, string abName)
 {
     if (!self)
     {
         return(new string[0]);
     }
     return(self
            .GetAllDependencies(abName)
            .OrderBy(c => c)
            .ToArray());
 }
Пример #4
0
        /// <summary>
        /// 获取依赖列表
        /// </summary>
        /// <param name="abName">Ab name.</param>
        public string[] GetDependencies(string abName)
        {
            string[] dependencies = manifest.GetAllDependencies(abName);

            if (dependencies != null && dependencies.Length > 0)
            {
                return(dependencies);
            }

            for (int i = 0; assetBundleManifestArr != null && i < assetBundleManifestArr.Length; i++)
            {
                dependencies = assetBundleManifestArr[i].GetAllDependencies(abName);

                if (dependencies != null && dependencies.Length > 0)
                {
                    return(dependencies);
                }
            }
            return(null);
        }
Пример #5
0
        public AssetBundleUnit Load(string name)
        {
            if (!caches.ContainsKey(name))
            {
                AssetBundleUnit assetBundleUnit = new AssetBundleUnit();
                assetBundleUnit.name        = name;
                assetBundleUnit.assetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, name));
                assetBundleUnit.referenceCount++;
                if (assetBundleManifest != null)
                {
                    assetBundleUnit.dependencies = assetBundleManifest.GetAllDependencies(name);
                    assetBundleUnit.dependencies.ForEach((index, it) => {
                        Load(it);
                    });
                }
                caches.Add(name, assetBundleUnit);
            }

            return(caches[name]);
        }
Пример #6
0
        private static void LoadDependencyAssetBundles(string bundleName, AssetBundleManifest asset)
        {
            asset.GetAllDependencies(bundleName).ToList().ForEach(depBundle =>
            {
#if HS2
                AssetBundleManager.LoadAssetBundle(depBundle);
#else
                AssetBundleManager.LoadAssetBundle(depBundle, false);
#endif
            });
        }
Пример #7
0
    private IEnumerator Start()
    {
        //AssetBundle ab = AssetBundle.LoadFromFile("AssetBundles/wall.unity3d");
        //while (!Caching.ready)
        //{
        //    yield return null;
        //}

        //WWW www = WWW.LoadFromCacheOrDownload("http://localhost/AssetBundles/wall.unity3d", 1);
        //yield return www;
        //if (!string.IsNullOrEmpty(www.error))
        //{
        //    Debug.Log(www.error);
        //    yield return null;
        //}
        //AssetBundle ab= www.assetBundle;

        string          url      = "http://localhost/AssetBundles/Cube.unity3d";
        string          url2     = "http://localhost/AssetBundles/texture.unity3d";
        UnityWebRequest request  = UnityWebRequestAssetBundle.GetAssetBundle(url);
        UnityWebRequest request2 = UnityWebRequestAssetBundle.GetAssetBundle(url2);

        yield return(request.SendWebRequest());

        yield return(request2.SendWebRequest());

        AssetBundle ab         = (request.downloadHandler as DownloadHandlerAssetBundle).assetBundle;
        AssetBundle abMaterial = (request2.downloadHandler as DownloadHandlerAssetBundle).assetBundle;
        GameObject  wallGo     = ab.LoadAsset <GameObject>("Cube");

        //GameObject maGo = ab.LoadAsset<GameObject>("Hand_Painted_Grass");
        GameObject.Instantiate(wallGo);


        #region 获取AssetBundle下的Manifest文件并获取里面的依赖关系
        string          url3     = "http://localhost/AssetBundles/AssetBundles";
        UnityWebRequest request3 = UnityWebRequestAssetBundle.GetAssetBundle(url3);
        yield return(request3.SendWebRequest());

        AssetBundle         manifest  = (request3.downloadHandler as DownloadHandlerAssetBundle).assetBundle;
        AssetBundleManifest manifest2 = manifest.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
        string[]            bundles   = manifest2.GetAllAssetBundles();
        string[]            dependon  = manifest2.GetAllDependencies("cube.unity3d");
        foreach (var item in bundles)
        {
            Debug.Log(item);
        }

        foreach (var item in dependon)
        {
            Debug.Log(item);
        }
        #endregion
    }
Пример #8
0
 private static void m_CheckCircularReference(CircularReferenceSet set, AssetBundleManifest manifest)
 {
     HFLog.C("--------------------------------------");
     HFLog.C("开始检测 " + set.name);
     string[] str = manifest.GetAllDependencies(set.name);
     foreach (var item in str)
     {
         m_CheckCircularReference(set, item, manifest);
     }
     HFLog.C("检测完成√ " + set.name);
 }
Пример #9
0
    private IEnumerator LoadIEnumerator(string assetBundleDir, string assetBundleName, OnLoadAssetBundleFinish onLoadFinish)
    {
        //首先加载总Manifest文件;
        WWW wwwAll = new WWW(assetBundleDir + "AB");

        yield return(wwwAll);

        if (!string.IsNullOrEmpty(wwwAll.error))
        {
            Debug.LogError(wwwAll.error);
        }
        else
        {
            AssetBundle         ab       = wwwAll.assetBundle;
            AssetBundleManifest manifest = (AssetBundleManifest)ab.LoadAsset("AssetBundleManifest");
            ab.Unload(false);

            //获取依赖文件列表;
            string[]      depends            = manifest.GetAllDependencies(assetBundleName);
            AssetBundle[] dependsAssetBundle = new AssetBundle[depends.Length];

            for (int index = 0; index < depends.Length; index++)
            {
                //加载所有的依赖文件;
                WWW dwww = WWW.LoadFromCacheOrDownload(assetBundleDir + depends[index], 0);
                yield return(dwww);

                dependsAssetBundle[index] = dwww.assetBundle;
            }

            //加载我们需要的文件;
            WWW www = new WWW(assetBundleDir + assetBundleName);
            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.LogError(www.error);
            }
            else
            {
                string      name        = assetBundleName.Substring(0, assetBundleName.IndexOf("."));
                AssetBundle assetBundle = www.assetBundle;
                onLoadFinish(assetBundle, name);

                assetBundle.Unload(false);
            }

            //卸载依赖文件的包
            for (int index = 0; index < depends.Length; index++)
            {
                dependsAssetBundle[index].Unload(false);
            }
        }
    }
Пример #10
0
        IEnumerator OnLoadAssetBundle(string abName, Type type)
        {
            string url = m_BaseDownloadingURL + abName;
            // Debug.Log("OnLoadAssetBundle : url:"+url+" m_AssetBundleManifest:"+(m_AssetBundleManifest!=null) + new System.Diagnostics.StackTrace().ToString());
            UnityWebRequest webRequest = null;

            if (type == typeof(AssetBundleManifest))
            {
                webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url);
            }
            else
            {
                Hash128 hash = new Hash128();
                if (m_AssetBundleManifest != null)
                {
                    string[] dependencies = m_AssetBundleManifest.GetAllDependencies(abName);
                    if (dependencies.Length > 0)
                    {
                        m_Dependencies.Add(abName, dependencies);
                        for (int i = 0; i < dependencies.Length; i++)
                        {
                            string          depName    = dependencies[i];
                            AssetBundleInfo bundleInfo = null;
                            if (m_LoadedAssetBundles.TryGetValue(depName, out bundleInfo))
                            {
                                bundleInfo.m_ReferencedCount++;
                            }
                            else if (m_LoadRequests.ContainsKey(depName))
                            {
                                yield return(WaitForAssetBundleLoaded(depName));
                            }
                            else
                            {
                                m_LoadRequests.Add(depName, null);
                                yield return(StartCoroutine(OnLoadAssetBundle(depName, type)));

                                m_LoadRequests.Remove(depName);
                            }
                        }
                    }
                    hash = m_AssetBundleManifest.GetAssetBundleHash(abName);
                }
                webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, hash, 0);
            }
            yield return(webRequest.SendWebRequest());

            AssetBundle assetObj = DownloadHandlerAssetBundle.GetContent(webRequest);

            // Debug.Log("assetObj : "+(assetObj!=null)+" abName:"+abName+" isDone:"+webRequest.isDone);
            if (assetObj != null)
            {
                m_LoadedAssetBundles.Add(abName, new AssetBundleInfo(assetObj));
            }
        }
Пример #11
0
    /// <summary>
    /// 读取Manifest文件,获取它们的依赖关系并且加载出来
    /// </summary>
    private void Func()
    {
        AssetBundle         manifestAB = AssetBundle.LoadFromFile("AssetBundles/AssetBundles");
        AssetBundleManifest manifest   = manifestAB.LoadAsset <AssetBundleManifest>("AssetBundleManifest");

        string[] strArr = manifest.GetAllDependencies("scene/cubewall.ab");
        foreach (var item in strArr)
        {
            AssetBundle.LoadFromFile("AssetBundles/" + item);
        }
    }
Пример #12
0
    //依赖项递归查找,查找所有依赖项
    private void LoadAssetBundleDependenciesAsync(string bundleResName)
    {
        string[] dependBundles = mAssetBundleManifest.GetAllDependencies(bundleResName);
        int      dependCount   = dependBundles.Length;

        for (int i = 0; i < dependCount; ++i)
        {
            if (string.IsNullOrEmpty(dependBundles[i]))
            {
                continue;
            }
            if (mBundleLoaderSharedObjectDict.ContainsKey(dependBundles[i]) == false)
            {
                BundleLoaderSharedObject blso = new BundleLoaderSharedObject();
                mBundleLoaderSharedObjectDict.Add(dependBundles[i], blso);
                LoadAssetBundleDependenciesAsync(dependBundles[i]);
                BundleManager.Instance.StartCoroutine(blso.LoadAsync(this, blso, dependBundles[i], null, null, null, false));
            }
        }
    }
Пример #13
0
            private Bundle Load(string bundleName, bool loadManifest, bool isAsync)
            {
                if (!loadManifest)
                {
                    if (manifest == null)
                    {
                        throw new Exception("Bundles , Please initialize AssetBundleManifest by calling Bundles.Initialize()");
                    }
                }
                string bundlePath = rootPath.CombinePath(bundleName);
                Bundle bundle;

                if (!bundles.TryGetValue(bundleName, out bundle))
                {
                    Hash128 version = loadManifest ? new Hash128(1, 0, 0, 0) : manifest.GetAssetBundleHash(bundleName);
                    if (bundle == null)
                    {
                        List <Bundle> dpdenceBundles = new List <Bundle>();
                        if (!loadManifest)
                        {
                            string[] dps = manifest.GetAllDependencies(bundleName);
                            if (dps.Length > 0)
                            {
                                for (int i = 0; i < dps.Length; i++)
                                {
                                    dpdenceBundles.Add(Load(dps[i], false, isAsync));
                                }
                            }
                        }
                        if (bundlePath.StartsWith("http://") ||
                            bundlePath.StartsWith("https://") ||
                            bundlePath.StartsWith("file://") ||
                            bundlePath.StartsWith("ftp://"))
                        {
                            bundle = new WebRequestBundle(bundlePath, bundleName, dpdenceBundles, version);
                        }
                        else
                        {
                            if (isAsync)
                            {
                                bundle = new AsyncBundle(bundlePath, bundleName, dpdenceBundles, version);
                            }
                            else
                            {
                                bundle = new Bundle(bundlePath, bundleName, dpdenceBundles, version);
                            }
                        }
                        bundles.Add(bundleName, bundle);
                        bundle.Load();
                    }
                }
                bundle.Retain();
                return(bundle);
            }
Пример #14
0
 // マニフェストバンドルを利用してアセットバンドルのダウンロードをする。
 private IEnumerator LoadAssetBundle(string urlBase, string abname)
 {
     // 依存するアセットバンドルを先に(ダウン)ロード
     // manifest は起動時に先にロード済みのマニフェストオブジェクト。
     foreach (var dep in manifest.GetAllDependencies(abname))
     {
         yield return(Download(urlBase, dep));
     }
     // 引数で指定された本体をロード
     yield return(Download(urlBase, abname));
 }
Пример #15
0
        public IEnumerator InitLoadMainifestFile()
        {
            if (mNeedLoadBundleList.Count == 0)
            {
                string path = AssetBundlePath.Instance.ExternalStorePathUrl;
                string url  = path + "/" + AssetBundlePath.AssetDependentFileBundleName;
                WWW    www  = new WWW(url);
                yield return(www);

                if (www.isDone)
                {
                    if (!string.IsNullOrEmpty(www.error))
                    {
                        DebugSystem.LogError("初始化 MainifestFile 失败:" + www.error);
                        www.Dispose();
                        yield break;
                    }
                }
                AssetBundle asset = www.assetBundle;
                www.Dispose();
                if (asset == null)
                {
                    DebugSystem.LogError("MainifestFile Bundle is Null");
                    yield break;
                }

                AssetBundleManifest mAllBundleMainifest = asset.LoadAsset <AssetBundleManifest>(AssetBundlePath.AssetDependentFileAssetName);
                if (mAllBundleMainifest == null)
                {
                    DebugSystem.LogError("Mainifest is Null");
                    yield break;
                }
                string[] mAssetNames = mAllBundleMainifest.GetAllAssetBundles();
                if (mAssetNames != null)
                {
                    foreach (var v in mAssetNames)
                    {
                        string          bundleName          = v;
                        string[]        bundleDependentList = mAllBundleMainifest.GetAllDependencies(v);
                        Hash128         mHash   = mAllBundleMainifest.GetAssetBundleHash(v);
                        AssetBundleInfo mABInfo = new AssetBundleInfo(bundleName, mHash, bundleDependentList);
                        mNeedLoadBundleList.Add(mABInfo);
                    }
                }
                else
                {
                    DebugSystem.Log("初始化资源依赖文件: Null");
                }
                asset.Unload(false);
                DebugSystem.Log("初始化资源管理器全局Bundle信息成功");

                yield return(InitLoadExternalStoreVersionConfig());
            }
        }
Пример #16
0
    // 创建一个资源对象
    private ResourceInfo CreateResource(string assetBundleName)
    {
        ResourceInfo mainRes = new ResourceInfo();

        // 加载该AssetBundle所有依赖的资源
        string[] dps = abMainfest.GetAllDependencies(assetBundleName);
        for (int i = 0; i < dps.Length; i++)
        {
            ResourceInfo dpRes = LoadResource(dps[i]);
            mainRes.depends.Add(dpRes);
        }
        // 从磁盘上加载主体AssetBundle到内存
        string path = ResourceConfig.ABPath + assetBundleName;

        mainRes.assetBundle     = AssetBundle.LoadFromFile(path);
        mainRes.assetBundleName = assetBundleName;
        // 缓存下来
        loadedResources.Add(assetBundleName, mainRes);
        return(mainRes);
    }
    /// <summary>
    /// 查看AssetBundleManifest的AssetBundle的资源列表
    /// </summary>
    void LookAssetBundleManifest_AssetBundleAssets()
    {
        AssetBundle         assetBundleMain     = AssetBundle.LoadFromFile(assetbundleMain);
        AssetBundleManifest assetBundleManifest = assetBundleMain.LoadAsset <AssetBundleManifest>("AssetBundleManifest");

        string[] assetBundles = assetBundleManifest.GetAllAssetBundles();

        StringWriter sw = new StringWriter();

        for (int i = 0; i < assetBundles.Length; i++)
        {
            string[] dependencies = assetBundleManifest.GetAllDependencies(assetBundles[i]);
            sw.WriteLine(assetBundles[i]);
            if (dependencies.Length > 0)
            {
                sw.WriteLine("[依赖列表]");
                sw.Write("        ");
                sw.Write(String.Join("\n        ", dependencies));
                sw.Write("\n");
            }


            String abpath = Path.Combine(assetbundleRoot, assetBundles[i]);
            if (File.Exists(abpath))
            {
                AssetBundle ab         = AssetBundle.LoadFromFile(abpath);
                string[]    assetNames = ab.GetAllAssetNames();
                if (assetNames.Length > 0)
                {
                    sw.WriteLine("[资源列表]");
                    sw.Write("        ");
                    sw.Write(String.Join("\n        ", assetNames));
                    sw.WriteLine();
                }

                ab.Unload(false);
            }
            else
            {
                sw.WriteLine("不存在该AssetBundle文件");
            }

            sw.WriteLine();
            sw.WriteLine();
            sw.WriteLine();
        }

        assetBundleMain.Unload(true);
        string path = "../Logs/AssetBundleManifest的AssetBundle的资源列表.txt";

        CheckPath(path);
        File.WriteAllText(path, sw.ToString());
        Shell.RevealInFinder(path);
    }
Пример #18
0
        public void LoadAssetBundle(string assetBundleName)
        {
            if (assetBundleMaps.ContainsKey(assetBundleName))
            {
                AssetBundleMap map = assetBundleMaps[assetBundleName];
                map.count++;
                foreach (string s in map.dependencies)
                {
                    if (assetBundleMaps.ContainsKey(s))
                    {
                        AssetBundleMap map0 = assetBundleMaps[s];
                        map0.count++;
                    }
                }
                return;
            }
            string[] dependencies = manifest.GetAllDependencies(assetBundleName);
            for (int i = 0; i < dependencies.Length; i++)
            {
                if (assetBundleMaps.ContainsKey(dependencies[i]))
                {
                    AssetBundleMap map = assetBundleMaps[dependencies[i]];
                    map.count++;
                    continue;
                }
                assetBundleMaps.Add(dependencies[i], new AssetBundleMap {
                    assetBundleName = dependencies[i],
                    assetBundle     = AssetBundle.LoadFromFile(pathPrefix + dependencies[i]),
                    dependencies    = manifest.GetAllDependencies(dependencies[i]),
                    count           = 1
                });
            }
            AssetBundle assetBundle = AssetBundle.LoadFromFile(pathPrefix + assetBundleName);

            assetBundleMaps.Add(assetBundleName, new AssetBundleMap {
                assetBundleName = assetBundleName,
                assetBundle     = assetBundle,
                dependencies    = dependencies,
                count           = 1
            });
        }
Пример #19
0
    void LoadDependencies()
    {
        string              manifestFilePath = Path.Combine(Application.dataPath, "AssetBundles/AssetBundles.manifest");
        AssetBundle         bundle           = AssetBundle.LoadFromFile(manifestFilePath);
        AssetBundleManifest manifest         = bundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");

        string[] dependencies = manifest.GetAllDependencies("cube");
        foreach (string dependency in dependencies)
        {
            AssetBundle.LoadFromFile(Path.Combine(Application.dataPath, "AssetBundles/" + dependency));
        }
    }
Пример #20
0
        /// <summary>
        /// 开始加载资源
        /// </summary>
        /// <param name="abName"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        IEnumerator OnLoadAssetBundle(string abName, Type type)
        {
            string          url        = m_BaseDownloadingUrl + abName;
            UnityWebRequest webRequest = null;

            if (type == typeof(AssetBundleManifest))
            {
                //url = url + ".manifest";
                webRequest = UnityWebRequest.GetAssetBundle(url, 0);
            }
            else
            {
                Hash128 hash128 = new Hash128();
                if (m_AssetBundleManifest != null)
                {
                    string[] dependencies = m_AssetBundleManifest.GetAllDependencies(abName);
                    for (int i = 0; i < dependencies.Length; i++)
                    {
                        string          dependenciesName = dependencies[i];
                        AssetBundleInfo assetBundleInfo;
                        if (m_LoadedAssetBundle.TryGetValue(dependenciesName, out assetBundleInfo))
                        {
                            assetBundleInfo.m_ReferencedCount++;
                        }
                        else if (m_LoadRequest.ContainsKey(dependenciesName))
                        {
                            yield return(WaitForAssetBundleLoaded(dependenciesName));
                        }
                        else
                        {
                            m_LoadRequest.Add(dependenciesName, null);
                            yield return(StartCoroutine(OnLoadAssetBundle(dependenciesName, type)));

                            m_LoadRequest.Remove(dependenciesName);
                        }
                    }
                    hash128 = m_AssetBundleManifest.GetAssetBundleHash(abName);
                }
                webRequest = UnityWebRequest.GetAssetBundle(url, hash128, 0);
            }
            yield return(webRequest.Send());

            AssetBundle assetBundle = DownloadHandlerAssetBundle.GetContent(webRequest);

            if (assetBundle != null)
            {
                m_LoadedAssetBundle.Add(abName, new AssetBundleInfo(assetBundle));
            }
            else
            {
                Debug.LogWarning(string.Format("加载失败:{0} :{1}", abName, url));
            }
        }
Пример #21
0
 /// <summary>
 /// 获取指定ab包所有依赖关系
 /// </summary>
 /// <param name="abName">ab包名</param>
 /// <returns></returns>
 public string[] GetAllDependices(string abName)
 {
     if (m_manifest != null && !string.IsNullOrEmpty(abName))
     {
         return(m_manifest.GetAllDependencies(abName));
     }
     else
     {
         LogHelperLSK.LogError("m_manifest is null");
     }
     return(null);
 }
Пример #22
0
        //先载入依赖
        private static void LoadDependencies(string name)
        {
            if (Manifest != null)
            {
                string[] dependbundleNames = Manifest.GetAllDependencies(name);

                foreach (string _name in dependbundleNames)
                {
                    AssetManager.loadBundle(_name, (Bundle b) => { });
                }
            }
        }
 /// <summary>
 /// 查询指定包的依赖项
 /// </summary>
 public string[] RetrivalDependece(string abName)
 {
     if (_manifest != null && !string.IsNullOrEmpty(abName))
     {
         return(_manifest.GetAllDependencies(abName));
     }
     else
     {
         Debug.Log("获取指定包依赖项失败:" + abName);
         return(null);
     }
 }
Пример #24
0
 IEnumerator LoadAssetBundle(string abName)
 {
     string[] dependencies = manifest.GetAllDependencies(abName);
     for (int i = 0; i < dependencies.Length; i++)
     {
         string depABName = dependencies[i];
         //GLog.Log("AssetBundleHash " + depABName + ":" + manifest.GetAssetBundleHash(depABName));
         yield return(StartCoroutine(OnLoadAssetBundle(depABName, true)));
     }
     //GLog.Log("AssetBundleHash " + abName + ":" + manifest.GetAssetBundleHash(abName));
     yield return(StartCoroutine(OnLoadAssetBundle(abName, false)));
 }
Пример #25
0
 /// <summary>
 /// 卸载指定资源包
 /// </summary>
 /// <param name="assetbundlePath">资源包路径</param>
 public bool UnloadAssetBundle(string assetbundlePath)
 {
     if (protectedList.ContainsKey(assetbundlePath))
     {
         return(false);
     }
     if (loadAssetBundles.ContainsKey(assetbundlePath))
     {
         foreach (string dependencies in assetBundleManifest.GetAllDependencies(assetbundlePath))
         {
             UnloadDependenciesAssetBundle(dependencies);
         }
         //如果除了作为主包外还被其他包引用那么就不释放
         if (!dependenciesBundles.ContainsKey(assetbundlePath))
         {
             loadAssetBundles[assetbundlePath].Bundle.Unload(true);
         }
         loadAssetBundles.Remove(assetbundlePath);
     }
     return(true);
 }
Пример #26
0
 /**
  * 如果依赖环形 则会死循环(理论不会出现)
  */
 private void dependLoad(AssetBundleManifest abm, string dir, string[] depends)
 {
     for (int i = 0; i < depends.Length; ++i)
     {
         string[] cdepends = abm.GetAllDependencies(depends[i]);
         for (int j = 0; j < cdepends.Length; ++j)
         {
             dependLoad(abm, dir, cdepends);
         }
         addDependToCache(depends[i], dir);
     }
 }
Пример #27
0
        private void SetManifest(AssetBundleManifest manifest)
        {
            foreach (var v in manifest.GetAllAssetBundles())
            {
                if (_allDependencies.ContainsKey(v))
                {
                    throw new ArgumentException("duplicate assetbundle");
                }

                _allDependencies.Add(v, manifest.GetAllDependencies(v));
            }
        }
Пример #28
0
        /// <summary>
        /// 加载依赖资源
        /// </summary>
        private void LoadDependencies(string _abname)
        {
            string[] _dependencies = abManifest.GetAllDependencies(_abname);
            if (_dependencies.Length == 0)
            {
                return;
            }

            for (int i = 0; i < _dependencies.Length; i++)
            {
                AssetData _asset = null;
                if (dAssetCache.TryGetValue(_dependencies[i], out _asset))
                {
                    _asset.Used();
                }
                else
                {
                    LoadSourceAssetBundle(_dependencies[i]);
                }
            }
        }
        public AssetBundleInfo(string assetBundleName, string outPutPath, AssetBundleManifest manifest)
        {
            AssetBundleName = assetBundleName;
            Hash            = manifest.GetAssetBundleHash(assetBundleName).ToString();
            Dependencies    = manifest.GetAllDependencies(assetBundleName);
            var file = new FileInfo(Path.Combine(outPutPath, assetBundleName));

            if (file.Exists)
            {
                Size = file.Length;
            }
        }
Пример #30
0
    public static IEnumerator AssetBundleLoop(){
        while(true){
            while (hasTaskToFinish == false){
                yield return new WaitForEndOfFrame();
            }
            //处理Task
            while(assetTaskQueue.Count>0){
                AssetRequestTask current = assetTaskQueue.Dequeue();
                //AssetBundle已经被读取 
                if(LoadedAssets.ContainsKey(current.GetABName())){
                    string assetPath = LoadedAssets[current.GetABName()].GetAllAssetNames()[0];

                    AssetBundleRequest abRequest = LoadedAssets[current.GetABName()].LoadAssetAsync(assetPath);

                    yield return abRequest;

                    current.onAssetLoaded(abRequest.asset);
                }
                //AssetBundle尚未读取
                else {
                    //依赖包 Loop
                    string[] DependenciesInfo = assetBundleManifest.GetAllDependencies(current.GetABName());
                    for (int i = 0; i < DependenciesInfo.Length;i++){
                        if(LoadedAssets.ContainsKey(DependenciesInfo[i])){
                            continue;
                        }
                        bool isDependenceAssetLoaded = false;

                        MonoActiveObject.StartCoroutine(LoadAsset(DependenciesInfo[i],()=>{
                            isDependenceAssetLoaded = true;
                        }));

                        while(!isDependenceAssetLoaded){
                            yield return new WaitForFixedUpdate();
                        }
                    }
                    //主AB
                    bool isMainLoaded = false;

                    MonoActiveObject.StartCoroutine(LoadAsset(current.GetABName(), () => {
                        isMainLoaded = true;
                    }));

                    while (!isMainLoaded)
                        yield return new WaitForFixedUpdate();

                    //添加回队列 等待队列回调
                    assetTaskQueue.Enqueue(current);
                }
            }
            hasTaskToFinish = false;
        }
    }