private LoadedAssetBundle LoadBundleByFileStream(string bundleName, LoadFromType loadFromType, AssetEncryptMode encript = AssetEncryptMode.None) { if (string.IsNullOrEmpty(bundleName)) { return(null); } int nHashCode = bundleName.GetHashCode(); LoadedAssetBundle loaded = ABManager.Instance.GetLoadedBundle(nHashCode); if (loaded != null) { loaded.Count(); return(loaded); } //在对应目录里进行AB创建 m_strFullName.Length = 0; if (loadFromType == LoadFromType.LoadFromDownLoad) { m_strFullName.Append(ABPathHelper.AssetsURL); } else { m_strFullName.Append(ABPathHelper.AssetsLocalABURL); } m_strFullName.Append(bundleName); string path = m_strFullName.ToString(); if (File.Exists(path)) { AssetBundle ab = AssetBundle.LoadFromFile(path); if (ab != null) { loaded = ABManager.Instance.AddLoadedBundle(nHashCode, ab); } } else { if (GameUtils.OnlyShowInInner) { Debug.Log("<color=red>资源: " + m_strFullName + "不存在</color>"); } } return(loaded); }
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); }
public LoadedAssetBundle LoadSyn(string strFullName, UpdateProgress updateFunc = null, bool bSend = false) { LoadedAssetBundle loaded = ABManager.Instance.GetLoadedBundle(strFullName.GetHashCode()); if (loaded != null) { loaded.Count(); return(loaded); } AssetManageInfo info = AssetManageConfigManager.Instance.GetInfo(strFullName); //资源是从DownLoad包里还是StreamAsset的包里读取的 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); } //只要不是LoadFromNone,说明这个资源是有身份证的,并非来路不明 if (loadFromType != LoadFromType.LoadFromNone) { int nCnt = 1; if (dependencies != null) { nCnt += dependencies.Length; for (int i = 0; i < dependencies.Length; ++i) { LoadBundleByFileStream(dependencies[i], getLoadFromType(dependencies[i]), AssetEncryptMode.None); if (updateFunc != null) { updateFunc((float)(i + 1) / nCnt, bSend); } } } //Debug.Log("<color=red> LoadSyn: " + strFullName + "</color>"); loaded = LoadBundleByFileStream(strFullName, loadFromType, info.encryption); if (loaded != null) { if (dependencies != null && dependencies.Length > 0) { loaded.AddDpendences(dependencies); } if (info.loadType != ELoadType.Music && info.loadType != ELoadType.Scene) { loaded.MapAssets(); ABManager.Instance.AfterLoad(loaded); } if (updateFunc != null) { updateFunc(1.0f, bSend); } } return(loaded); } else { Debug.Log("<color=red>资源:" + strFullName + "来路不明,在bundle表里不存在。</color>"); return(null); } }