Esempio n. 1
0
        /// <summary>
        /// Creates an <see cref="Task{TResult}"/> wrapper for the specified <see cref="WWW"/>.
        /// </summary>
        /// <param name="request">The source web request.</param>
        public static Task <T> ToTask <T>(this WWW request) where T : class
        {
            var result = new TaskCompletionSource <T>(request);

            AsyncUtility.AddCompletionCallback(request, () => OnTaskCompleted(result, request));
            return(result.Task);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates an <see cref="Task{TResult}"/> wrapper for the Unity <see cref="AssetBundleRequest"/>.
        /// </summary>
        /// <param name="op">The source operation.</param>
        public static Task <T> ToTask <T>(this AssetBundleRequest op) where T : UnityEngine.Object
        {
            var result = new TaskCompletionSource <T>(op);

            AsyncUtility.AddCompletionCallback(op, () => result.TrySetResult(op.asset as T));
            return(result.Task);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates an <see cref="Task"/> wrapper for the specified <see cref="WWW"/>.
        /// </summary>
        /// <param name="request">The source web request.</param>
        public static Task ToTask(this WWW request)
        {
            var result = new TaskCompletionSource <object>(request);

            AsyncUtility.AddCompletionCallback(request, () => OnTaskCompleted(result, request));
            return(result.Task);
        }
Esempio n. 4
0
            /// <inheritdoc/>
            public void OnCompleted(Action continuation)
            {
#if UNITY_2017_2_OR_NEWER || UNITY_2018
                // Starting with Unity 2017.2 there is AsyncOperation.completed event
                _op.completed += o => continuation();
#else
                AsyncUtility.AddCompletionCallback(_op, continuation);
#endif
            }
Esempio n. 5
0
 /// <inheritdoc/>
 protected override void OnStarted()
 {
     if (_www.isDone)
     {
         SetCompleted();
     }
     else
     {
         AsyncUtility.AddCompletionCallback(_www, SetCompleted);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Creates an <see cref="Task"/> wrapper for the Unity <see cref="AsyncOperation"/>.
 /// </summary>
 /// <param name="op">The source operation.</param>
 public static Task ToTask(this AsyncOperation op)
 {
     if (op.isDone)
     {
         return(Task.CompletedTask);
     }
     else
     {
         var result = new TaskCompletionSource <object>(op);
         AsyncUtility.AddCompletionCallback(op, () => result.TrySetResult(null));
         return(result.Task);
     }
 }
Esempio n. 7
0
        /// <inheritdoc/>
        protected override void OnStarted()
        {
            if (_op.isDone)
            {
                OnSetCompleted(_op);
            }
            else
            {
#if UNITY_2017_2_OR_NEWER || UNITY_2018
                // Starting with Unity 2017.2 there is AsyncOperation.completed event
                _op.completed += OnSetCompleted;
#else
                AsyncUtility.AddCompletionCallback(_op, () => OnSetCompleted(_op));
#endif
            }
        }
        /// <inheritdoc/>
        protected override void OnStarted()
        {
            if (_request.isDone)
            {
                SetCompleted();
            }
            else if (_request.isModifiable)
            {
#if UNITY_2017_2_OR_NEWER || UNITY_2018
                _op = _request.SendWebRequest();
#else
                _op = _request.Send();
#endif

                AsyncUtility.AddCompletionCallback(_op, SetCompleted);
            }
        }
Esempio n. 9
0
 /// <inheritdoc/>
 public void OnCompleted(Action continuation)
 {
     AsyncUtility.AddCompletionCallback(_op, continuation);
 }