public void ReportProgress(float progress) { if (globalPromise.CurrentState != PromiseState.Pending) { return; } globalPromise.ReportProgress(progress); }
private IEnumerator WaitForAllCoroutine(IEnumerable <Action> actions, Promise promise) { int count = actions.CountFast(); int i = 0; foreach (Action action in actions) { action(); i++; promise.ReportProgress((float)count / i); yield return(null); } promise.Resolve(); }
public IPromise Then(Promise promise) { globalPromise.Progress(p => { promise.ReportProgress(p); }); globalPromise.Done(() => { promise.Resolve(); }); globalPromise.Catch(e => { promise.Reject(e); }); return(promise); }
public IPromise Then(Action <T> onSuccess = null, Action <Exception> onError = null) { Promise promise = Promise.Create(); Progress(p => { promise.ReportProgress(p); }); Done(r => { onSuccess?.Invoke(r); promise.Resolve(); }); Catch(e => { onError?.Invoke(e); promise.Reject(e); }); return(promise); }
private IEnumerator ProgressRoutine <T>(Promise <T> promise, UnityWebRequestAsyncOperation operation, Action <long> progressBytes) { float progress = 0; ulong lastByteProgress = 0; while (operation.isDone == false) { if (progressBytes != null && operation.webRequest.downloadedBytes != lastByteProgress) { lastByteProgress = operation.webRequest.downloadedBytes; progressBytes((long)lastByteProgress); } if (promise.CurrentState == PromiseState.Pending && operation.progress != progress) { promise.ReportProgress(operation.progress); progress = operation.progress; } yield return(null); } }