InternalResult download(Url url) => new InternalResult( Future <Either <WWWError, UsageCountedDisposable <Texture2D> > > .async((promise, f) => { ASync.StartCoroutine(textureLoader( // TODO: change to UnityWebRequest.GetTexture from old WWW implementation // Here is sample code, but I don't remember why it is not used. Try it and see // for yourself. // var f = UnityWebRequest.GetTexture(staticAd.image.url).toFuture().flatMapT(req => { // var dlHandler = (DownloadHandlerTexture) req.downloadHandler; // var texture = dlHandler.texture; // if (texture) return new Either<ErrorMsg, Texture>(texture); // return new ErrorMsg($"Can't download texture from url{staticAd.image.url}"); // }); new WWW(url), promise, onDispose: t => { Object.Destroy(t); cache.Remove(url); if (Log.d.isDebug()) { Log.d.debug($"{nameof(ImageDownloader)} disposed texture: {url}"); } }) ); f.onComplete(e => { // remove from cache if image was not downloaded if (e.isLeft) { cache.Remove(url); } }); }) );
public static void trackWWWSend(string prefix, WWW www, Dictionary <string, string> headers) { ASync.StartCoroutine(ASync.WWWEnumerator(www).afterThis(() => { if (!string.IsNullOrEmpty(www.error)) { if (Log.isInfo) { Log.info( prefix + " send failed with: " + www.error + "\nRequest headers=" + headers.asString() + "\nResponse headers=" + www.responseHeaders.asString() ); } } else { if (Debug.isDebugBuild && Log.isInfo) { Log.info( prefix + " send succeeded with response headers=" + www.responseHeaders.asString() ); } } })); }
public static void trackWWWSend(this WWW www, string prefix, WWWForm form) { ASync.StartCoroutine(ASync.WWWEnumerator(www).afterThis(() => { if (!string.IsNullOrEmpty(www.error)) { if (Log.isInfo) { Log.info( $"{prefix} POST send to '{www.url}' failed with: {www.error}" + "\nRequest headers=" + form.headers.asDebugString() + "\nRequest body=" + Encoding.UTF8.GetString(form.data) + "\nResponse headers=" + www.responseHeaders.asDebugString() ); } } else { if (Debug.isDebugBuild && Log.isInfo) { Log.info( prefix + " POST send succeeded with response headers=" + www.responseHeaders.asDebugString() ); } } })); }
public static IObservable <DateTime> interval( Duration interval, Option <Duration> delay = default(Option <Duration>) ) { Option.ensureValue(ref delay); return(new Observable <DateTime>(observer => { var cr = ASync.StartCoroutine(intervalEnum(observer, interval, delay)); return new Subscription(cr.stop); })); }
public static Tpl <IAsyncOperation, Future <Either <ErrorMsg, A> > > loadAsync <A>( PathStr loadPath ) where A : Object { var path = loadPath.unityPath; IResourceRequest request = new WrappedResourceRequest(Resources.LoadAsync <A>(path)); return(F.t( request.upcast(default(IAsyncOperation)), Future <Either <ErrorMsg, A> > .async( p => ASync.StartCoroutine(waitForLoadCoroutine <A>(request, p.complete, path)) ) )); }
Future <Either <WWWError, UsageCountedDisposable <Texture2D> > > download(Url url) => Future <Either <WWWError, UsageCountedDisposable <Texture2D> > > .async((promise, f) => { ASync.StartCoroutine(textureLoader( new WWW(url), promise, onDispose: t => { Object.Destroy(t); cache.Remove(url); if (Log.d.isDebug()) { Log.d.debug($"{nameof(ImageDownloader)} disposed texture: {url}"); } }) ); f.onComplete(e => { // remove from cache if image was not downloaded if (e.isLeft) { cache.Remove(url); } }); });
static FPS() { ASync.StartCoroutine(update()); ASync.StartCoroutine(calculate()); }