IEnumerator LoadAssetBundle(string relativeUrl) { var wwwLoader = CWWWLoader.Load(FullUrl); while (!wwwLoader.IsFinished) { Progress = wwwLoader.Progress / 2f; // 最多50%, 要算上Parser的嘛 yield return(null); } Progress = 1 / 2f; if (!wwwLoader.IsOk) { if (AssetBundlerLoaderErrorEvent != null) { AssetBundlerLoaderErrorEvent(this); } CDebug.LogError("[CAssetBundleLoader]Error Load AssetBundle: {0}", relativeUrl); OnFinish(null); wwwLoader.Release(); yield break; } else { // 提前结束 // 解密 // 释放WWW加载的字节。。释放该部分内存,因为AssetBundle已经自己有缓存了 var cloneBytes = (byte[])wwwLoader.Www.bytes.Clone(); wwwLoader.Release(); BundleParser = new CAssetBundleParser(RelativeResourceUrl, cloneBytes); while (!BundleParser.IsFinished) { if (IsReadyDisposed) // 中途释放 { OnFinish(null); yield break; } Progress = BundleParser.Progress / 2f + 1 / 2f; // 最多50%, 要算上WWWLoader的嘛 yield return(null); } Progress = 1f; var assetBundle = BundleParser.Bundle; if (assetBundle == null) { CDebug.LogError("WWW.assetBundle is NULL: {0}", FullUrl); } OnFinish(assetBundle); //Array.Clear(cloneBytes, 0, cloneBytes.Length); // 手工释放内存 } //GC.Collect(0);// 手工释放内存 }
IEnumerator LoadAssetBundle(string relativeUrl) { XLoadCache loadCache; if (!AssetBundlesCache.TryGetValue(RelativeResourceUrl, out loadCache)) { loadCache = new XLoadCache() { RelativeUrl = RelativeResourceUrl, Ab = null }; AssetBundlesCache[RelativeResourceUrl] = loadCache; CWWWLoader wwwLoader = new CWWWLoader(FullUrl); while (!wwwLoader.IsFinished) { yield return(null); } // 解密 CAssetBundleParser parser = new CAssetBundleParser(RelativeResourceUrl, wwwLoader.Www.bytes); while (!parser.IsFinished) { yield return(null); } if (parser.Bundle == null) { CBase.LogError("WWW.assetBundle is NULL: {0}", FullUrl); } loadCache.Ab = parser.Bundle; } else { if (loadCache.IsLoadedFinish) { yield return(null); // 确保每一次异步都延迟一帧 } while (!loadCache.IsLoadedFinish) { yield return(null); //Wait } } Bundle = loadCache.Ab; if (Callback != null) { Callback(FullUrl, Bundle, CallbackArgs); } }
IEnumerator LoadAssetBundle(string relativeUrl) { XLoadCache loadCache; if (!AssetBundlesCache.TryGetValue(RelativeResourceUrl, out loadCache)) { loadCache = new XLoadCache() { RelativeUrl = RelativeResourceUrl, Ab = null }; AssetBundlesCache[RelativeResourceUrl] = loadCache; CWWWLoader wwwLoader = new CWWWLoader(FullUrl); while (!wwwLoader.IsFinished) yield return null; // 解密 CAssetBundleParser parser = new CAssetBundleParser(RelativeResourceUrl, wwwLoader.Www.bytes); while (!parser.IsFinished) { yield return null; } if (parser.Bundle == null) CBase.LogError("WWW.assetBundle is NULL: {0}", FullUrl); loadCache.Ab = parser.Bundle; } else { if (loadCache.IsLoadedFinish) { yield return null; // 确保每一次异步都延迟一帧 } while (!loadCache.IsLoadedFinish) { yield return null; //Wait } } Bundle = loadCache.Ab; if (Callback != null) Callback(FullUrl, Bundle, CallbackArgs); }
IEnumerator LoadAssetBundle(string relativeUrl) { var wwwLoader = CWWWLoader.Load(FullUrl); while (!wwwLoader.IsFinished) { Progress = wwwLoader.Progress / 2f; // 最多50%, 要算上Parser的嘛 yield return null; } Progress = 1/2f; if (!wwwLoader.IsOk) { if (AssetBundlerLoaderErrorEvent != null) { AssetBundlerLoaderErrorEvent(this); } CDebug.LogError("[CAssetBundleLoader]Error Load AssetBundle: {0}", relativeUrl); OnFinish(null); wwwLoader.Release(); yield break; } else { // 提前结束 // 解密 // 释放WWW加载的字节。。释放该部分内存,因为AssetBundle已经自己有缓存了 var cloneBytes = (byte[])wwwLoader.Www.bytes.Clone(); wwwLoader.Release(); BundleParser = new CAssetBundleParser(RelativeResourceUrl, cloneBytes); while (!BundleParser.IsFinished) { if (IsReadyDisposed) // 中途释放 { OnFinish(null); yield break; } Progress = BundleParser.Progress / 2f + 1/2f; // 最多50%, 要算上WWWLoader的嘛 yield return null; } Progress = 1f; var assetBundle = BundleParser.Bundle; if (assetBundle == null) CDebug.LogError("WWW.assetBundle is NULL: {0}", FullUrl); OnFinish(assetBundle); //Array.Clear(cloneBytes, 0, cloneBytes.Length); // 手工释放内存 } //GC.Collect(0);// 手工释放内存 }