Beispiel #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 IAsyncOperation <T> ToAsync <T>(this UnityWebRequest request) where T : class
        {
            var result = new Helpers.WebRequestResult <T>(request);

            result.Start();
            return(result);
        }
Beispiel #2
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 IAsyncOperation ToAsync(this UnityWebRequest request)
        {
            var result = new Helpers.WebRequestResult <object>(request);

            result.Start();
            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Creates an asyncronous operation optimized for downloading binary content via HTTP GET.
        /// </summary>
        /// <param name="url">The URI of the binary content to download.</param>
        /// <returns>An operation that can be used to track the download process.</returns>
        public static IAsyncOperation <byte[]> GetBytes(string url)
        {
            var webRequest = UnityWebRequest.Get(url);
            var result     = new Helpers.WebRequestResult <byte[]>(webRequest);

            result.Start();
            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// Creates an asyncronous operation optimized for downloading binary content via HTTP GET.
        /// </summary>
        /// <param name="url">The URI of the binary content to download.</param>
        /// <param name="userState">User-defined data.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="url"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">Thrown if <paramref name="url"/> is an empty string.</exception>
        /// <returns>An operation that can be used to track the download process.</returns>
        /// <seealso cref="GetTextAsync(string, object)"/>
        public static IAsyncOperation <byte[]> GetBytesAsync(string url, object userState = null)
        {
            ThrowIfInvalidUrl(url);

            var webRequest = UnityWebRequest.Get(url);
            var result     = new Helpers.WebRequestResult <byte[]>(webRequest);

            result.Start();
            return(result);
        }
Beispiel #5
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_1_OR_NEWER
            var webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, hash, crc);
            var result     = new Helpers.WebRequestResult <AssetBundle>(webRequest);
#else
            var webRequest = UnityWebRequest.GetAssetBundle(url, hash, crc);
            var result     = new Helpers.WebRequestResult <AssetBundle>(webRequest);
#endif

            result.Start();
            return(result);
        }
Beispiel #6
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_1_OR_NEWER
            var webRequest = UnityWebRequestTexture.GetTexture(url, nonReadable);
            var result     = new Helpers.WebRequestResult <Texture2D>(webRequest);
#else
            var webRequest = UnityWebRequest.GetTexture(url, nonReadable);
            var result     = new Helpers.WebRequestResult <Texture2D>(webRequest);
#endif

            result.Start();
            return(result);
        }
Beispiel #7
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_1_OR_NEWER
            var webRequest = UnityWebRequestMultimedia.GetAudioClip(url, audioType);
            var result     = new Helpers.WebRequestResult <AudioClip>(webRequest);
#else
            var webRequest = UnityWebRequest.GetAudioClip(url, audioType);
            var result     = new Helpers.WebRequestResult <AudioClip>(webRequest);
#endif

            result.Start();
            return(result);
        }
Beispiel #8
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>
        /// <param name="userState">User-defined data.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="url"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">Thrown if <paramref name="url"/> is an empty string.</exception>
        /// <returns>An operation that can be used to track the download process.</returns>
        /// <seealso cref="GetAssetBundleAsync(string, object)"/>
        public static IAsyncOperation <AssetBundle> GetAssetBundleAsync(string url, Hash128 hash, uint crc, object userState = null)
        {
            ThrowIfInvalidUrl(url);

#if UNITY_2018_1_OR_NEWER
            var webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, hash, crc);
#else
            var webRequest = UnityWebRequest.GetAssetBundle(url, hash, crc);
#endif

            var result = new Helpers.WebRequestResult <AssetBundle>(webRequest, userState);
            result.Start();
            return(result);
        }
Beispiel #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>
        /// <param name="userState">User-defined data.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="url"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">Thrown if <paramref name="url"/> is an empty string.</exception>
        /// <returns>An operation that can be used to track the download process.</returns>
        /// <seealso cref="GetTextureAsync(string, object)"/>
        public static IAsyncOperation <Texture2D> GetTextureAsync(string url, bool nonReadable, object userState = null)
        {
            ThrowIfInvalidUrl(url);

#if UNITY_2017_1_OR_NEWER
            var webRequest = UnityWebRequestTexture.GetTexture(url, nonReadable);
#else
            var webRequest = UnityWebRequest.GetTexture(url, nonReadable);
#endif

            var result = new Helpers.WebRequestResult <Texture2D>(webRequest, userState);
            result.Start();
            return(result);
        }
Beispiel #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>
        /// <param name="userState">User-defined data.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="url"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">Thrown if <paramref name="url"/> is an empty string.</exception>
        /// <returns>An operation that can be used to track the download process.</returns>
        /// <seealso cref="GetAudioClipAsync(string, object)"/>
        public static IAsyncOperation <AudioClip> GetAudioClipAsync(string url, AudioType audioType, object userState = null)
        {
            ThrowIfInvalidUrl(url);

#if UNITY_2017_1_OR_NEWER
            var webRequest = UnityWebRequestMultimedia.GetAudioClip(url, audioType);
#else
            var webRequest = UnityWebRequest.GetAudioClip(url, audioType);
#endif

            var result = new Helpers.WebRequestResult <AudioClip>(webRequest, userState);
            result.Start();
            return(result);
        }
 protected override void OnStarted()
 {
     _assetBundleLoadResult.Start();
 }