Beispiel #1
0
    IEnumerator LoadAssetList(AssetListLoadedFunc callBack)
    {
        // Defer this function to the next frame until server replied and response has been downloaded
        UnityWebRequest req = UnityWebRequest.Get(string.Format("{0}/Bundle", this.ServerAddress));
        yield return req.SendWebRequest();

        if (req.isNetworkError || req.isHttpError)
        {
            
            _lastError = req.error;

            if (callBack != null)
                callBack(null);
        }
        else
        {
            Debug.Log("Asset Manager: Asset list finished downloading.");

            AssetBundleListing listing = JsonUtility.FromJson<AssetBundleListing>(req.downloadHandler.text);

            List<string> assetList = new List<string>();
            foreach (var bundle in listing.AssetBundleList)
            {
                assetList.Add(bundle.BundleName);

                if (bundle.Thumbnail != null)
                {
                    _thumbnails[bundle.BundleName] = System.Convert.FromBase64String(bundle.Thumbnail);
                    bundle.Thumbnail = null;
                }
            }

            if (callBack != null)
            {
                // Dispatch events
                callBack(assetList);
                if (OnAssetListLoaded != null)
                {
                    OnAssetListLoaded(assetList);
                }
            }
        }
    }
Beispiel #2
0
 /// <summary>
 /// Sends a request to the Asset Server and fetches the list of all
 /// stored assets waiting to be queried asynchroniously.
 /// Due to the returning list containing the Thumbnails of the AssetBundles,
 /// this Request is a network-heavy process and should only be called once.
 /// </summary>
 /// <param name="callBack">
 /// Method to be called when returning the list of Assets.
 /// Callback will get a null-argument if an error occured while fetchting the list.
 /// </param>
 public void RequestAssetList(AssetListLoadedFunc callBack)
 {
     Debug.Log("Asset Manager: Requesting asset list from server...");
     StartCoroutine(LoadAssetList(callBack));
 }