private IEnumerator LoadAssetBundle(string relativeUrl) { #if UNITY_5 || UNITY_2017_1_OR_NEWER // Unity 5 Manifest中管理了依赖 var abPath = relativeUrl.ToLower(); var deps = _assetBundleManifest.GetAllDependencies(abPath); _depLoaders = new AssetBundleLoader[deps.Length]; for (var d = 0; d < deps.Length; d++) { var dep = deps[d]; _depLoaders[d] = AssetBundleLoader.Load(dep, null, _loaderMode); } for (var l = 0; l < _depLoaders.Length; l++) { var loader = _depLoaders[l]; while (!loader.IsCompleted) { yield return(null); } } #endif #if UNITY_5 || UNITY_2017_1_OR_NEWER // Unity 5 AssetBundle自动转小写 relativeUrl = relativeUrl.ToLower(); #endif var bytesLoader = HotBytesLoader.Load(KResourceModule.BundlesPathRelative + relativeUrl, _loaderMode); while (!bytesLoader.IsCompleted) { yield return(null); } if (!bytesLoader.IsSuccess) { if (AssetBundlerLoaderErrorEvent != null) { AssetBundlerLoaderErrorEvent(this); } Log.Error("[AssetBundleLoader]Error Load Bytes AssetBundle: {0}", relativeUrl); OnFinish(null); yield break; } byte[] bundleBytes = bytesLoader.Bytes; Progress = 1 / 2f; bytesLoader.Release(); // 字节用完就释放 BundleParser = new KAssetBundleParser(RelativeResourceUrl, bundleBytes); 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) { Log.Error("WWW.assetBundle is NULL: {0}", RelativeResourceUrl); } OnFinish(assetBundle); //Array.Clear(cloneBytes, 0, cloneBytes.Length); // 手工释放内存 //GC.Collect(0);// 手工释放内存 }
private IEnumerator LoadAssetBundle(string relativeUrl) { #if UNITY_5 // Unity 5下,自动进行依赖加载 var abPath = relativeUrl.ToLower(); var deps = _assetBundleManifest.GetAllDependencies(abPath); _depLoaders = new AssetBundleLoader[deps.Length]; for (var d = 0; d < deps.Length; d++) { var dep = deps[d]; _depLoaders[d] = AssetBundleLoader.Load(dep, null, _loaderMode); } for (var l = 0; l < _depLoaders.Length; l++) { var loader = _depLoaders[l]; while (!loader.IsCompleted) { yield return null; } } #endif #if UNITY_5 // Unity 5 AssetBundle自动转小写 relativeUrl = relativeUrl.ToLower(); #endif var bytesLoader = HotBytesLoader.Load(relativeUrl, _loaderMode); while (!bytesLoader.IsCompleted) { yield return null; } if (!bytesLoader.IsSuccess) { if (AssetBundlerLoaderErrorEvent != null) { AssetBundlerLoaderErrorEvent(this); } Log.Error("[AssetBundleLoader]Error Load Bytes AssetBundle: {0}", relativeUrl); OnFinish(null); yield break; } byte[] bundleBytes = bytesLoader.Bytes; Progress = 1 / 2f; bytesLoader.Release(); // 字节用完就释放 BundleParser = new KAssetBundleParser(RelativeResourceUrl, bundleBytes); 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) Log.Error("WWW.assetBundle is NULL: {0}", RelativeResourceUrl); OnFinish(assetBundle); //Array.Clear(cloneBytes, 0, cloneBytes.Length); // 手工释放内存 //GC.Collect(0);// 手工释放内存 }