Example #1
0
        ///<summary>Retrieves an AssetBundle from a remote server. Wraps <see cref="UnityWebRequestAssetBundle.GetAssetBundle"/> and uses the default AssetBundle cache
        ///<param name="url">The absolute URL to the GET endpoint</param>
        ///<param name="bundle">The RemoteAssetBundle struct</param>
        ///<param name="callback">An Action with signature (string, AssetBundle) Note - string will be null if there's no error</param>
        ///<returns>Returns an enumerator. The AssetBundle is available via the callback</returns>
        ///</summary>
        public static IEnumerator DownloadAssetBundleAsync(string url, RemoteAssetBundle bundle, System.Action <string, AssetBundle> callback)
        {
            string            endpoint     = string.Format("{0}/{1}?versionhash={2}", url, bundle.info.name, bundle.versionHash);
            CachedAssetBundle cachedBundle = new CachedAssetBundle();

            cachedBundle.hash = bundle.toHash128();
            cachedBundle.name = bundle.info.name;
            using (UnityWebRequest req = UnityWebRequestAssetBundle.GetAssetBundle(endpoint, cachedBundle, 0))
            {
                yield return(req.SendWebRequest());

                if (req.isNetworkError || req.isHttpError)
                {
                    callback(req.error, null);
                }
                else
                {
                    try
                    {
                        AssetBundle ab = DownloadHandlerAssetBundle.GetContent(req);
                        callback(null, ab);
                    }
                    catch (System.Exception ex)
                    {
                        callback(ex.Message, null);
                    }
                }
            }
        }
Example #2
0
        public static async Task <FCMMessageStatus> SendBundleMessage(string url, RemoteAssetBundle bundle, string jwtName = null)
        {
            HttpResponseMessage response = await SendBundleMessageAsync(url, bundle, jwtName);

            string content = await response.Content.ReadAsStringAsync();

            return(FCMMessageStatus.Deserialize(content));
        }
Example #3
0
        public static async Task <RemoteAssetBundle> UploadAssetBundle(string url, AssetBundleInfo info, string appName = null, string jwtName = null)
        {
            HttpResponseMessage response = await UploadAssetBundleAsync(url, info, appName, jwtName);

            string content = await response.Content.ReadAsStringAsync();

            return(RemoteAssetBundle.Deserialize(content));
        }
Example #4
0
        ///<summary>Simplified version of <see cref="VerifyAssetBundleAsync"/>
        ///<para>This is enforced by default as an extra set of checks and balances when calling <see cref="GetAssetBundleManifestAsync"/> with verified = true</para>
        ///<param name="url">The absolute URL to the PUT endpoint</param>
        ///<param name="bundle">The RemoteAssetBundle struct</param>
        ///<param name="jwtName">Optional name of a JSON Web Token (placed somewhere in Assets) that can be used for authentication</param>
        ///<returns>Returns a Task which returns a deserialized RemoteAssetBundle</returns>
        ///</summary>
        public static async Task <RemoteAssetBundle> VerifyAssetBundle(string url, RemoteAssetBundle bundle, bool verifiedVal, string jwtName = null)
        {
            HttpResponseMessage response = await VerifyAssetBundleAsync(url, bundle, verifiedVal, jwtName);

            string content = await response.Content.ReadAsStringAsync();

            return(RemoteAssetBundle.Deserialize(content));
        }
Example #5
0
        public static Task <HttpResponseMessage> SendBundleMessageAsync(string url, RemoteAssetBundle bundle, string jwtName = null)
        {
            bool useJWT = !string.IsNullOrEmpty(jwtName);

            if (useJWT)
            {
                client.DefaultRequestHeaders.Authorization = GenerateAuthHeaderFromJWT(jwtName);
            }
            string endpoint = string.Format("{0}/{1}?versionHash={2}", url, Sanitize(bundle.info.name), Sanitize(bundle.versionHash));

            return(client.PostAsync(endpoint, null));
        }
Example #6
0
        ///<summary>Sets a RemoteAssetBundle's Verified property to true so it will be loaded on manifests that require all bundles to be verified.
        ///<para>This is enforced by default as an extra set of checks and balances when calling <see cref="GetAssetBundleManifestAsync"/> with verified = true</para>
        ///<param name="url">The absolute URL to the PUT endpoint</param>
        ///<param name="bundle">The RemoteAssetBundle struct</param>
        ///<param name="jwtName">Optional name of a JSON Web Token (placed somewhere in Assets) that can be used for authentication</param>
        ///<returns>Returns a Task so can be used with await or ContinueWith</returns>
        ///</summary>
        public static Task <HttpResponseMessage> VerifyAssetBundleAsync(string url, RemoteAssetBundle bundle, bool verifiedVal, string jwtName = null)
        {
            bool useJWT = !string.IsNullOrEmpty(jwtName);

            if (useJWT)
            {
                client.DefaultRequestHeaders.Authorization = GenerateAuthHeaderFromJWT(jwtName);
            }
            string        verified = "{\"verified\":" + (verifiedVal ? "true" : "false") + "}";
            StringContent content  = new StringContent(verified, Encoding.UTF8, "application/json");
            string        endpoint = string.Format("{0}/{1}?versionhash={2}", url, Sanitize(bundle.info.name), Sanitize(bundle.versionHash));

            return(client.PutAsync(endpoint, content));
        }
Example #7
0
 private IEnumerator FetchAssetBundle(RemoteAssetBundle bundle, RemoteAssetBundleMap assetMap)
 {
     System.Action <string, AssetBundle> callback = (error, b) =>
     {
         if (!string.IsNullOrEmpty(error))
         {
             Debug.LogError(error);
         }
         else
         {
             if (b)
             {
                 assetMap.AddLoadedRemoteBundle(b);
             }
         }
     };
     return(RemoteAssetBundleUtils.DownloadAssetBundleAsync(remoteAssetBundleEndpoint, bundle, callback));
 }
Example #8
0
        public static RemoteAssetBundle Deserialize(string val)
        {
            RemoteAssetBundle obj = JsonUtility.FromJson <RemoteAssetBundle>(val);

            return(obj);
        }
Example #9
0
        ///<summary>Simplified version of <see cref="DeleteAssetBundleAsync" />
        ///<param name="url">The absolute URL to the POST endpoint</param>
        ///<param name="bundle">The RemoteAssetBundle struct</param>
        ///<returns>Returns the status code of the <see cref="HttpResponseMessage" /></returns>
        ///</summary>
        public static async Task <HttpStatusCode> DeleteAssetBundle(string url, RemoteAssetBundle bundle, string jwtName = null)
        {
            HttpResponseMessage response = await DeleteAssetBundleAsync(url, bundle, jwtName);

            return(response.StatusCode);
        }