protected override void OnFinish(object resultObj) { if (_wwwLoader != null) { // 释放WWW加载的字节。。释放该部分内存,因为AssetBundle已经自己有缓存了 _wwwLoader.Release(); _wwwLoader = null; } base.OnFinish(resultObj); }
private IEnumerator CoLoad(string url, KResourceInAppPathType type, KAssetBundleLoaderMode loaderMode) { if (KResourceModule.GetResourceFullPath(url, out FullUrl, _inAppPathType)) { } else { if (Debug.isDebugBuild) { Logger.LogError("[KBytesLoader]Error Path: {0}", url); } OnFinish(null); } if (_inAppPathType == KResourceInAppPathType.PersistentAssetsPath) { Progress = .5f; Bytes = File.ReadAllBytes(FullUrl); } else if (_inAppPathType == KResourceInAppPathType.StreamingAssetsPath) { _wwwLoader = KWWWLoader.Load(FullUrl); while (!_wwwLoader.IsCompleted) { Progress = _wwwLoader.Progress / 2f; // 最多50%, 要算上Parser的嘛 yield return(null); } if (!_wwwLoader.IsSuccess) { //if (AssetBundlerLoaderErrorEvent != null) //{ // AssetBundlerLoaderErrorEvent(this); //} Logger.LogError("[KBytesLoader]Error Load WWW: {0}", url); OnFinish(null); yield break; } Bytes = _wwwLoader.Www.bytes; } else if (_inAppPathType == KResourceInAppPathType.ResourcesAssetsPath) // 使用Resources文件夹模式 { var pathExt = Path.GetExtension(FullUrl); // Resources.Load无需扩展名 var pathWithoutExt = FullUrl.Substring(0, FullUrl.Length - pathExt.Length); if (_loaderMode == KAssetBundleLoaderMode.ResourcesLoad) { var textAsset = Resources.Load <TextAsset>(pathWithoutExt); if (textAsset == null) { Logger.LogError("[KBytesLoader]Cannot Resources.Load from : {0}", pathWithoutExt); OnFinish(null); yield break; } Bytes = textAsset.bytes; Resources.UnloadAsset(textAsset); } else if (_loaderMode == KAssetBundleLoaderMode.ResourcesLoadAsync) { var loadReq = Resources.LoadAsync <TextAsset>(pathWithoutExt); while (!loadReq.isDone) { Progress = loadReq.progress / 2f; // 最多50%, 要算上Parser的嘛 } var loadAsset = loadReq.asset; var loadTextAsset = loadAsset as TextAsset; if (loadTextAsset == null) { Logger.LogError("[KBytesLoader]Error Resources.LoadAsync: {0}", url); OnFinish(null); yield break; } Bytes = loadTextAsset.bytes; Resources.UnloadAsset(loadTextAsset); } else { Logger.LogError("[KBytesLoader]Unvalid LoaderMode on Resources Load Mode: {0}", _loaderMode); OnFinish(null); yield break; } } else { Logger.LogError("[KBytesLoader]Error InAppPathType: {0}", KResourceModule.DefaultInAppPathType); OnFinish(null); yield break; } OnFinish(Bytes); }
private IEnumerator LoadAssetBundle(string relativeUrl) { byte[] bundleBytes; if (_inAppPathType == KResourceInAppPathType.StreamingAssetsPath) { _wwwLoader = KWWWLoader.Load(FullUrl); while (!_wwwLoader.IsCompleted) { Progress = _wwwLoader.Progress/2f; // 最多50%, 要算上Parser的嘛 yield return null; } if (!_wwwLoader.IsSuccess) { if (AssetBundlerLoaderErrorEvent != null) { AssetBundlerLoaderErrorEvent(this); } Logger.LogError("[KAssetBundleLoader]Error Load AssetBundle: {0}", relativeUrl); OnFinish(null); yield break; } bundleBytes = _wwwLoader.Www.bytes; } else if (_inAppPathType == KResourceInAppPathType.ResourcesAssetsPath) // 使用Resources文件夹模式 { var pathExt = Path.GetExtension(FullUrl); // Resources.Load无需扩展名 var pathWithoutExt = FullUrl.Substring(0, FullUrl.Length - pathExt.Length); if (_loaderMode == KAssetBundleLoaderMode.ResourcesLoad) { var textAsset = Resources.Load<TextAsset>(pathWithoutExt); if (textAsset == null) { if (AssetBundlerLoaderErrorEvent != null) AssetBundlerLoaderErrorEvent(this); Logger.LogError("[LoadAssetBundle]Cannot Resources.Load from : {0}", pathWithoutExt); OnFinish(null); yield break; } bundleBytes = textAsset.bytes; } else if (_loaderMode == KAssetBundleLoaderMode.ResourcesLoadAsync) { var loadReq = Resources.LoadAsync<TextAsset>(pathWithoutExt); while (!loadReq.isDone) { Progress = loadReq.progress/2f; // 最多50%, 要算上Parser的嘛 } var loadAsset = loadReq.asset; var loadTextAsset = loadAsset as TextAsset; if (loadTextAsset == null) { if (AssetBundlerLoaderErrorEvent != null) AssetBundlerLoaderErrorEvent(this); Logger.LogError("[KAssetBundleLoader]Error Resources.LoadAsync: {0}", relativeUrl); OnFinish(null); yield break; } bundleBytes = loadTextAsset.bytes; } else { if (AssetBundlerLoaderErrorEvent != null) AssetBundlerLoaderErrorEvent(this); Logger.LogError("[LoadAssetBundle]Unvalid LoaderMode on Resources Load Mode: {0}", _loaderMode); OnFinish(null); yield break; } } else { Logger.LogError("[LoadAssetBundle]Error InAppPathType: {0}", KResourceModule.DefaultInAppPathType); OnFinish(null); yield break; } Progress = 1/2f; 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) Logger.LogError("WWW.assetBundle is NULL: {0}", FullUrl); OnFinish(assetBundle); //Array.Clear(cloneBytes, 0, cloneBytes.Length); // 手工释放内存 //GC.Collect(0);// 手工释放内存 }
public IEnumerator CheckDownload() { ClearData(); var loadingPanel = UIModule.Instance.GetOrCreateUI <LoadingPanel>(); loadingPanel.SetProgress(I18N.Get("download_check")); loadingPanel.DisPlay(true); string url = AppConfig.resUrl + AppConfig.VersionTxtName; Log.LogToFile($"读取远程version.txt:{url}"); var loader = KWWWLoader.Load(url); while (!loader.IsCompleted) { yield return(null); } if (!loader.IsError) { ParseText(loader.Www.text, remoteVersion); remoteVersion.TryGetValue("filelist.txt", out filelistVersion); } else { ErrorType = UpdateErrorType.RemoteVersionError; yield break; } url = KResourceModule.GetResourceFullPath(AppConfig.VersionTxtName, false); Log.LogToFile($"读取本地version.txt:{url}"); loader = KWWWLoader.Load(url); while (!loader.IsCompleted) { yield return(null); } if (!loader.IsError) { ParseText(loader.Www.text, localVersion); } else { ErrorType = UpdateErrorType.LocalVersionError; yield break; } loader.Dispose(); loader = null; CompareVersion("lua.zip"); CompareVersion("setting.zip"); bool filelistSame = CompareVersion("filelist.txt", false); if (filelistSame == false) { //对比ab列表 string remote_filelist = null; url = AppConfig.resUrl + AppConfig.FilelistPath; loader = KWWWLoader.Load(url); while (!loader.IsCompleted) { yield return(null); } if (!loader.IsError) { remote_filelist = loader.Www.text; } else { ErrorType = UpdateErrorType.FilelistnError; } url = KResourceModule.GetResourceFullPath(AppConfig.FilelistPath, false); loader = KWWWLoader.Load(url); while (!loader.IsCompleted) { yield return(null); } //开始对比两个filelist if (!loader.IsError) { GetDownloadFromFilelist(loader.Www.text, remote_filelist); } else { ErrorType = UpdateErrorType.LocalFilelistnError; } } if (downloadFiles.Count > 0) { var panel = UIModule.Instance.GetOrCreateUI <KUIMsgBox>(); UIMsgBoxInfo info = new UIMsgBoxInfo().GetDefalut(I18N.Get("download_msg", KTool.FormatFileSize(downloadTotalSize)), strCancel: I18N.Get("common_skip")); info.OkCallback = () => { Game.Instance.StartCoroutine(StartUpdate()); }; info.CancelCallback = IngoreDownload; panel.info = info; panel.DisPlay(true); } else { Log.LogToFile($"本次启动无资源更新,跳过下载"); ClearData(); DownloadFinish = true; } }
private IEnumerator LoadAssetBundle(string relativeUrl) { byte[] bundleBytes; if (_inAppPathType == KResourceInAppPathType.StreamingAssetsPath) { _wwwLoader = KWWWLoader.Load(FullUrl); while (!_wwwLoader.IsCompleted) { Progress = _wwwLoader.Progress / 2f; // 最多50%, 要算上Parser的嘛 yield return(null); } if (!_wwwLoader.IsSuccess) { if (AssetBundlerLoaderErrorEvent != null) { AssetBundlerLoaderErrorEvent(this); } Logger.LogError("[KAssetBundleLoader]Error Load AssetBundle: {0}", relativeUrl); OnFinish(null); yield break; } bundleBytes = _wwwLoader.Www.bytes; } else if (_inAppPathType == KResourceInAppPathType.ResourcesAssetsPath) // 使用Resources文件夹模式 { var pathExt = Path.GetExtension(FullUrl); // Resources.Load无需扩展名 var pathWithoutExt = FullUrl.Substring(0, FullUrl.Length - pathExt.Length); if (_loaderMode == KAssetBundleLoaderMode.ResourcesLoad) { var textAsset = Resources.Load <TextAsset>(pathWithoutExt); if (textAsset == null) { if (AssetBundlerLoaderErrorEvent != null) { AssetBundlerLoaderErrorEvent(this); } Logger.LogError("[LoadAssetBundle]Cannot Resources.Load from : {0}", pathWithoutExt); OnFinish(null); yield break; } bundleBytes = textAsset.bytes; } else if (_loaderMode == KAssetBundleLoaderMode.ResourcesLoadAsync) { var loadReq = Resources.LoadAsync <TextAsset>(pathWithoutExt); while (!loadReq.isDone) { Progress = loadReq.progress / 2f; // 最多50%, 要算上Parser的嘛 } var loadAsset = loadReq.asset; var loadTextAsset = loadAsset as TextAsset; if (loadTextAsset == null) { if (AssetBundlerLoaderErrorEvent != null) { AssetBundlerLoaderErrorEvent(this); } Logger.LogError("[KAssetBundleLoader]Error Resources.LoadAsync: {0}", relativeUrl); OnFinish(null); yield break; } bundleBytes = loadTextAsset.bytes; } else { if (AssetBundlerLoaderErrorEvent != null) { AssetBundlerLoaderErrorEvent(this); } Logger.LogError("[LoadAssetBundle]Unvalid LoaderMode on Resources Load Mode: {0}", _loaderMode); OnFinish(null); yield break; } } else { Logger.LogError("[LoadAssetBundle]Error InAppPathType: {0}", KResourceModule.DefaultInAppPathType); OnFinish(null); yield break; } Progress = 1 / 2f; 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) { Logger.LogError("WWW.assetBundle is NULL: {0}", FullUrl); } OnFinish(assetBundle); //Array.Clear(cloneBytes, 0, cloneBytes.Length); // 手工释放内存 //GC.Collect(0);// 手工释放内存 }