Esempio n. 1
0
        private static IEnumerator FetchAssetBundle <T>(AssetBundleLoadAssetOperation operation,
                                                        IObserver <T> observer, IProgress <float> reportProgress, CancellationToken cancel)
            where T : UnityEngine.Object
        {
            while (!operation.IsDone() && !cancel.IsCancellationRequested)
            {
                if (reportProgress != null)
                {
                    try
                    {
                        reportProgress.Report(operation.GetProgress());
                    }
                    catch (Exception ex)
                    {
                        observer.OnError(ex);
                        yield break;
                    }
                }

                yield return(null);
            }

            try
            {
                if (cancel.IsCancellationRequested)
                {
                    yield break;
                }

                if (reportProgress != null)
                {
                    try
                    {
                        reportProgress.Report(operation.GetProgress());
                    }
                    catch (Exception ex)
                    {
                        observer.OnError(ex);
                        yield break;
                    }
                }

                if (!string.IsNullOrEmpty(operation.GetError()))
                {
                    observer.OnError(new AssetBundleLoadAssetOperationErrorException(operation));
                }
                else
                {
                    observer.OnNext(operation.GetAsset <T>());
                    observer.OnCompleted();
                }
            }
            catch (Exception ex)
            {
                observer.OnError(ex);
            }
        }
Esempio n. 2
0
 public AssetBundleLoadAssetOperationErrorException(AssetBundleLoadAssetOperation operation)
 {
     Operation       = operation;
     RawErrorMessage = operation.GetError();
 }