protected override async Task AsyncRun() { string fullurl; var loc = PathRouter.GetFullPath(Url, true, out fullurl); if (loc == PathLocation.NotFound) { throw new FileNotFoundException("BytesLoader", Url); } ResLog.VerboseFormat("BytesLoader.Load, loc:{0}, fullpath:{1}", loc, fullurl); byte[] bytes = null; try { bytes = await WWWLoader.AsyncLoad(fullurl, v => Progress = v); Finish(bytes); } catch (Exception e) { Finish(null, true); throw e; } }
/// <summary> /// use www to load stuff /// never let exception out of this function /// </summary> protected async void AsyncStartLoading() { ++_runningCount; ResLog.VerboseFormat( "({0}) Dispatch {1} for loading, current running {2}", GetType().Name, Url, _runningCount); try { using (WWW www = new WWW(Url)) { www.threadPriority = Application.backgroundLoadingPriority; while (!www.isDone) { Progress = www.progress; await Awaiters.NextFrame; } Progress = www.progress; if (!string.IsNullOrEmpty(www.error)) { throw new ApplicationException(string.Format( "WWW error, url={0}, error={1}", Url, www.error)); } else { Finish(www.bytes); } } } catch (Exception e) { Finish(null, true); exception = e; } finally { --_runningCount; } }
public static byte[] Load(string path) { using (var timer = LoadTimer.Start <BytesLoader>(path)) { string fullpath; var loc = PathRouter.GetFullPath(path, false, out fullpath); if (loc == PathLocation.NotFound) { throw new FileNotFoundException("BytesLoader", path); } ResLog.VerboseFormat("BytesLoader.Load, loc:{0}, fullpath:{1}", loc, fullpath); if (loc == PathLocation.InApp && Application.platform == RuntimePlatform.Android) { return(AndroidPlugin.GetAssetBytes(path)); } else { return(File.ReadAllBytes(fullpath)); } } }