コード例 #1
0
 public void ReportProgress(float progress)
 {
     if (globalPromise.CurrentState != PromiseState.Pending)
     {
         return;
     }
     globalPromise.ReportProgress(progress);
 }
コード例 #2
0
        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();
        }
コード例 #3
0
        public IPromise Then(Promise promise)
        {
            globalPromise.Progress(p =>
            {
                promise.ReportProgress(p);
            });

            globalPromise.Done(() =>
            {
                promise.Resolve();
            });

            globalPromise.Catch(e =>
            {
                promise.Reject(e);
            });

            return(promise);
        }
コード例 #4
0
ファイル: Promise.cs プロジェクト: studentutu/swift-framework
        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);
        }
コード例 #5
0
        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);
            }
        }