示例#1
0
        /// <summary>
        /// Creates an <see cref="IAsyncOperation{TResult}"/> wrapper for the specified <see cref="UnityWebRequest"/>.
        /// </summary>
        /// <param name="request">The source web request.</param>
        public static WebRequestResult <byte[]> ToAsyncByteArray(this UnityWebRequest request)
        {
            var result = new WebRequestResult <byte[]>(request);

            result.Start();
            return(result);
        }
示例#2
0
        /// <summary>
        /// Creates an <see cref="IAsyncOperation{TResult}"/> wrapper for the specified <see cref="UnityWebRequest"/>.
        /// </summary>
        /// <param name="request">The source web request.</param>
        /// <returns>Returns a <see cref="IAsyncOperation{TResult}"/> instance that will complete when the source operation have completed.</returns>
        public static WebRequestResult <string> ToAsyncString(this UnityWebRequest request)
        {
            var result = new WebRequestResult <string>(request);

            result.Start();
            return(result);
        }
示例#3
0
        /// <summary>
        /// Creates an <see cref="IAsyncOperation{TResult}"/> wrapper for the specified <see cref="UnityWebRequest"/>.
        /// </summary>
        /// <param name="request">The source web request.</param>
        public static WebRequestResult <MovieTexture> ToAsyncMovieTexture(this UnityWebRequest request)
        {
            var result = new WebRequestResult <MovieTexture>(request);

            result.Start();
            return(result);
        }
示例#4
0
        /// <summary>
        /// Creates an <see cref="IAsyncOperation{TResult}"/> wrapper for the specified <see cref="UnityWebRequest"/>.
        /// </summary>
        /// <param name="request">The source web request.</param>
        public static WebRequestResult <AudioClip> ToAsyncAudioClip(this UnityWebRequest request)
        {
            var result = new WebRequestResult <AudioClip>(request);

            result.Start();
            return(result);
        }
示例#5
0
        /// <summary>
        /// Creates an <see cref="IAsyncOperation{TResult}"/> wrapper for the specified <see cref="UnityWebRequest"/>.
        /// </summary>
        /// <param name="request">The source web request.</param>
        public static WebRequestResult <AssetBundle> ToAsyncAssetBundle(this UnityWebRequest request)
        {
            var result = new WebRequestResult <AssetBundle>(request);

            result.Start();
            return(result);
        }
示例#6
0
        /// <summary>
        /// Creates an <see cref="IAsyncOperation{TResult}"/> wrapper for the specified <see cref="UnityWebRequest"/>.
        /// </summary>
        /// <param name="request">The source web request.</param>
        public static WebRequestResult <T> ToAsync <T>(this UnityWebRequest request) where T : class
        {
            var result = new WebRequestResult <T>(request);

            result.Start();
            return(result);
        }
示例#7
0
        /// <summary>
        /// Creates an <see cref="IAsyncOperation"/> wrapper for the specified <see cref="UnityWebRequest"/>.
        /// </summary>
        /// <param name="request">The source web request.</param>
        public static AsyncResult ToAsync(this UnityWebRequest request)
        {
            var result = new WebRequestResult <object>(request);

            result.Start();
            return(result);
        }
示例#8
0
        /// <summary>
        /// Creates an asyncronous operation optimized for downloading a <see cref="MovieTexture"/> via HTTP GET.
        /// </summary>
        /// <param name="url">The URI of the texture to download.</param>
        /// <returns>An operation that can be used to track the download process.</returns>
        public static IAsyncOperation <MovieTexture> GetMovieTexture(string url)
        {
#if UNITY_2017 || UNITY_2018
            var webRequest = UnityWebRequestMultimedia.GetMovieTexture(url);
            var result     = new WebRequestResult <MovieTexture>(webRequest);
#else
            var www    = new WWW(url);
            var result = new WwwResult <MovieTexture>(www);
#endif

            result.Start();
            return(result);
        }
示例#9
0
        /// <summary>
        /// Creates an asyncronous operation optimized for downloading a <see cref="Texture2D"/> via HTTP GET.
        /// </summary>
        /// <param name="url">The URI of the texture to download.</param>
        /// <param name="nonReadable">If <see langword="true"/>, the texture's raw data will not be accessible to script. This can conserve memory.</param>
        /// <returns>An operation that can be used to track the download process.</returns>
        public static IAsyncOperation <Texture2D> GetTexture(string url, bool nonReadable)
        {
#if UNITY_2017 || UNITY_2018
            var webRequest = UnityWebRequestTexture.GetTexture(url, nonReadable);
            var result     = new WebRequestResult <Texture2D>(webRequest);
#elif UNITY_5_4_OR_NEWER
            var webRequest = UnityWebRequest.GetTexture(url, nonReadable);
            var result     = new WebRequestResult <Texture2D>(webRequest);
#else
            var www    = new WWW(url);
            var result = new WwwResult <Texture2D>(www);
#endif

            result.Start();
            return(result);
        }
示例#10
0
        /// <summary>
        /// Creates an asyncronous operation optimized for downloading a <see cref="AudioClip"/> via HTTP GET.
        /// </summary>
        /// <param name="url">The URI of the audio clip to download.</param>
        /// <param name="audioType">The type of audio encoding for the downloaded audio clip.</param>
        /// <returns>An operation that can be used to track the download process.</returns>
        public static IAsyncOperation <AudioClip> GetAudioClip(string url, AudioType audioType)
        {
#if UNITY_2017 || UNITY_2018
            var webRequest = UnityWebRequestMultimedia.GetAudioClip(url, audioType);
            var result     = new WebRequestResult <AudioClip>(webRequest);
#elif UNITY_5_4_OR_NEWER
            var webRequest = UnityWebRequest.GetAudioClip(url, audioType);
            var result     = new WebRequestResult <AudioClip>(webRequest);
#else
            var www    = new WWW(url);
            var result = new WwwResult <AudioClip>(www);
#endif

            result.Start();
            return(result);
        }
示例#11
0
        /// <summary>
        /// Creates an asyncronous operation optimized for downloading a <see cref="AssetBundle"/> via HTTP GET.
        /// </summary>
        /// <param name="url">The URI of the asset bundle to download.</param>
        /// <param name="hash">A version hash. If this hash does not match the hash for the cached version of this asset bundle, the asset bundle will be redownloaded.</param>
        /// <param name="crc">If nonzero, this number will be compared to the checksum of the downloaded asset bundle data. If the CRCs do not match, an error will be logged and the asset bundle will not be loaded. If set to zero, CRC checking will be skipped.</param>
        /// <returns>An operation that can be used to track the download process.</returns>
        public static IAsyncOperation <AssetBundle> GetAssetBundle(string url, Hash128 hash, uint crc)
        {
#if UNITY_2018
            var webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, hash, crc);
            var result     = new WebRequestResult <AssetBundle>(webRequest);
#elif UNITY_5_4_OR_NEWER || UNITY_2017
            var webRequest = UnityWebRequest.GetAssetBundle(url, hash, crc);
            var result     = new WebRequestResult <AssetBundle>(webRequest);
#else
            var www    = WWW.LoadFromCacheOrDownload(url, hash, crc);
            var result = new WwwResult <AssetBundle>(www);
#endif

            result.Start();
            return(result);
        }
示例#12
0
        /// <summary>
        /// Creates an asyncronous operation optimized for downloading a <see cref="AssetBundle"/> via HTTP GET.
        /// </summary>
        /// <param name="url">The URI of the asset bundle to download.</param>
        /// <returns>An operation that can be used to track the download process.</returns>
        public static IAsyncOperation <AssetBundle> GetAssetBundle(string url)
        {
#if UNITY_2018
            var webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url);
            var result     = new WebRequestResult <AssetBundle>(webRequest);
#elif UNITY_5_4_OR_NEWER || UNITY_2017
            var webRequest = UnityWebRequest.GetAssetBundle(url);
            var result     = new WebRequestResult <AssetBundle>(webRequest);
#else
            var www    = new WWW(url);
            var result = new WwwResult <AssetBundle>(www);
#endif

            result.Start();
            return(result);
        }