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

            result.Start();
            return(result);
        }
示例#2
0
        /// <summary>
        /// Creates an <see cref="IAsyncOperation"/> wrapper for the specified <see cref="WWW"/>.
        /// </summary>
        /// <param name="request">The source web request.</param>
        public static IAsyncOperation ToAsync(this WWW request)
        {
            var result = new Helpers.WwwResult <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)
        {
#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);
        }
示例#4
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);
        }
示例#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>
        /// <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);
        }
示例#6
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);
        }
示例#7
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);
#elif UNITY_5_4_OR_NEWER
            var webRequest = UnityWebRequest.GetTexture(url, nonReadable);
            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);
        }
示例#8
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);
#elif UNITY_5_4_OR_NEWER
            var webRequest = UnityWebRequest.GetAudioClip(url, audioType);
            var result     = new Helpers.WebRequestResult <AudioClip>(webRequest);
#else
            var www    = new WWW(url);
            var result = new Helpers.WwwResult <AudioClip>(www);
#endif

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