Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
 public AssetBundleLoadAssetResult(UnityWebRequest request, string assetName, object userState)
     : base(null, userState)
 {
     _assetBundleLoadResult = new WebRequestResult <AssetBundle>(request);
     _assetLoadResult       = new AssetBundleRequestResult <T>(assetName);
     _assetBundleLoadResult.AddCompletionCallback(_assetLoadResult);
     _assetLoadResult.AddCompletionCallback(this);
 }
 public AssetBundleLoadSceneResult(UnityWebRequest request, string sceneName, LoadSceneMode loadMode, object userState)
     : base(null, userState)
 {
     _assetBundleLoadResult = new WebRequestResult <AssetBundle>(request);
     _sceneLoadResult       = new AssetBundleSceneRequestResult(sceneName, loadMode);
     _assetBundleLoadResult.AddCompletionCallback(_sceneLoadResult);
     _sceneLoadResult.AddCompletionCallback(this);
 }
Пример #6
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);
        }
Пример #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);
        }
Пример #8
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);
        }
Пример #9
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_1_OR_NEWER
            var webRequest = UnityWebRequestMultimedia.GetMovieTexture(url);
            var result     = new Helpers.WebRequestResult <MovieTexture>(webRequest);
#else
            var www    = new WWW(url);
            var result = new Helpers.WwwResult <MovieTexture>(www);
#endif

            result.Start();
            return(result);
        }
Пример #10
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)
        {
#if UNITY_5_4_OR_NEWER
            var webRequest = UnityWebRequest.Get(url);
            var result     = new Helpers.WebRequestResult <byte[]>(webRequest);
#else
            var www    = new WWW(url);
            var result = new Helpers.WwwResult <byte[]>(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_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);
        }
Пример #12
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);
        }
Пример #13
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);
        }
Пример #14
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);
        }
Пример #15
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>
        /// <returns>An operation that can be used to track the download process.</returns>
        public static IAsyncOperation <AssetBundle> GetAssetBundle(string url, Hash128 hash)
        {
#if UNITY_2018_1_OR_NEWER
            var webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, hash, 0);
            var result     = new Helpers.WebRequestResult <AssetBundle>(webRequest);
#elif UNITY_5_4_OR_NEWER
            var webRequest = UnityWebRequest.GetAssetBundle(url, hash, 0);
            var result     = new Helpers.WebRequestResult <AssetBundle>(webRequest);
#else
            var www    = WWW.LoadFromCacheOrDownload(url, hash);
            var result = new Helpers.WwwResult <AssetBundle>(www);
#endif

            result.Start();
            return(result);
        }
Пример #16
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_1_OR_NEWER
            var webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url);
            var result     = new Helpers.WebRequestResult <AssetBundle>(webRequest);
#elif UNITY_5_4_OR_NEWER
            var webRequest = UnityWebRequest.GetAssetBundle(url);
            var result     = new Helpers.WebRequestResult <AssetBundle>(webRequest);
#else
            var www    = new WWW(url);
            var result = new Helpers.WwwResult <AssetBundle>(www);
#endif

            result.Start();
            return(result);
        }
Пример #17
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>
        /// <returns>An operation that can be used to track the download process.</returns>
        public static IAsyncOperation <Texture2D> GetTexture(string url)
        {
#if UNITY_2017_1_OR_NEWER
            var webRequest = UnityWebRequestTexture.GetTexture(url, false);
            var result     = new Helpers.WebRequestResult <Texture2D>(webRequest);
#elif UNITY_5_4_OR_NEWER
            var webRequest = UnityWebRequest.GetTexture(url);
            var result     = new Helpers.WebRequestResult <Texture2D>(webRequest);
#else
            var www    = new WWW(url);
            var result = new Helpers.WwwResult <Texture2D>(www);
#endif

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