Example #1
0
 public override IObservable <UnityWebRequest> FetchHead(IProgress <float> progress = null)
 {
     return(Observable.Defer(() =>
     {
         if (IsHeadFetched)
         {
             return ReturnNull.ReportOnCompleted(progress);
         }
         return UnityWebRequest.Head(Url).SendAsObservable(progress /*, ETag, LastModified*/).Do(request =>
         {
             OnHeadFetched(request);
             if (!IsDownloaded && request.GetETag() == ETag)
             {
                 OnDownloaded(request);
             }
         });
     }));
 }
        //public string ETag { get; set; }
        //public string LastModified { get; set; }

        public override IObservable <UnityWebRequest> FetchHead(IProgress <float> progress = null)
        {
            return(Observable.Defer(() =>
            {
                if (IsHeadFetched)
                {
                    return ReturnNull.ReportOnCompleted(progress);
                }
                return (Hash.isValid ? AssetLoader.WhenCacheReady() : Observable.ReturnUnit()).ContinueWith(_ =>
                {
                    if (Hash.isValid && Caching.IsVersionCached(Url, Hash))
                    {
                        try { OnDownloaded(null); }                         // TODO remove try-catch block https://github.com/neuecc/UniRx/issues/311
                        catch (Exception ex) { return Observable.Throw <UnityWebRequest>(ex); }
                        return ReturnNull.ReportOnCompleted(progress);
                    }
                    return UnityWebRequest.Head(Url).SendAsObservable(progress /*, ETag, LastModified*/).Do(OnHeadFetched);
                });
            }));
        }
Example #3
0
 public override IObservable <UnityWebRequest> Download(IProgress <float> progress = null) =>
 Observable.Defer(() => IsHeadFetched ? ReturnNull : FetchHead()).ContinueWith(_ =>
                                                                               IsDownloaded ? ReturnNull.ReportOnCompleted(progress) : DoDownload(progress));