private IEnumerator LoadBundleByWWW(string bundleName, DependencsLoader callback, LoadFromType loadFromType, ELoadType loadType = ELoadType.Max) { if (string.IsNullOrEmpty(bundleName)) { yield break; } int nHashCode = bundleName.GetHashCode(); LoadedAssetBundle loaded = ABManager.Instance.GetLoadedBundle(nHashCode); if (loaded != null) { loaded.Count(); yield break; } if (!mLoadingReqs.Contains(nHashCode)) { mLoadingReqs.Add(nHashCode); string strBundleUrl = "file://"; if (loadFromType == LoadFromType.LoadFromDownLoad) { strBundleUrl += ABPathHelper.AssetsURL; } else { strBundleUrl = ABPathHelper.AssetsLocalABURL; } strBundleUrl += bundleName; WWW www = new WWW(strBundleUrl); if (www != null) { while (!www.isDone && string.IsNullOrEmpty(www.error)) { yield return(null); } if (string.IsNullOrEmpty(www.error)) { Debug.Log("<color=yellow>AddLoadedBundle:" + bundleName + "</color> " + Time.realtimeSinceStartup); ABManager.Instance.AddLoadedBundle(nHashCode, www.assetBundle); if (callback != null) { ++callback.mDoneCnt; } } www.Dispose(); } mLoadingReqs.Remove(nHashCode); } yield return(null); }
public IEnumerator LoadAsync(string strFullName) { if (AssetBundleManifest == null || string.IsNullOrEmpty(strFullName)) { yield break; } InitAsync(); int nHashCode = strFullName.GetHashCode(); LoadedAssetBundle loaded = ABManager.Instance.GetLoadedBundle(nHashCode); if (loaded != null) { loaded.Count(); yield break; } if (mLoadingReqs.Contains(nHashCode)) { yield break; } LoadFromType loadFromType = LoadFromType.LoadFromNone; string[] dependencies = null; if (AssetBundleManifest != null && AssetBundleHashSet.Contains(strFullName)) { loadFromType = LoadFromType.LoadFromDownLoad; dependencies = AssetBundleManifest.GetAllDependencies(strFullName); } else if (LocalABBundleManifest != null && LocalABBundleHashSet.Contains(strFullName)) { loadFromType = LoadFromType.LoadFromLocalAB; dependencies = LocalABBundleManifest.GetAllDependencies(strFullName); } int nLength = dependencies.Length; if (nLength > 0) { DependencsLoader dependCallBack = mDependItemPool.GetObject(); if (dependCallBack != null) { dependCallBack.Reset(); dependCallBack.mLength = nLength; } for (int i = 0; i < nLength; ++i) { ResourceManager.Instance.StartCoroutine(LoadBundleByWWW(dependencies[i], dependCallBack, loadFromType)); } while (!dependCallBack.AllDone) { yield return(null); } mDependItemPool.RemoveObject(dependCallBack); } yield return(ResourceManager.Instance.StartCoroutine(LoadBundleByWWW(strFullName, null, loadFromType))); loaded = ABManager.Instance.GetLoadedBundle(nHashCode); if (loaded != null) { if (nLength > 0) { loaded.AddDpendences(dependencies); } loaded.MapAssets(); ABManager.Instance.AfterLoad(loaded); } yield return(null); }