Exemple #1
0
 /// <summary>
 /// ダウンロード要求失敗時処理
 /// </summary>
 /// <param name="downloadRequest">失敗したダウンロード要求</param>
 private void OnErrorDownloadRequest(AssetBundleDownloadRequest downloadRequest)
 {
     if (this.downloadCoroutineDictionary.ContainsKey(downloadRequest))
     {
         this.downloadCoroutineDictionary.Remove(downloadRequest);
     }
 }
Exemple #2
0
 /// <summary>
 /// ダウンロード要求完了時イベント
 /// </summary>
 /// <param name="downloadRequest">完了時ダウンロード要求</param>
 public void OnCompletedDownloadRequest(AssetBundleDownloadRequest downloadRequest)
 {
     if (this.downloadCoroutineDictionary.ContainsKey(downloadRequest))
     {
         this.downloadCoroutineDictionary.Remove(downloadRequest);
     }
 }
Exemple #3
0
    /// <summary>
    /// アセットバンドルをキャッシュから読み込み、またはダウンロードするコルーチン
    /// </summary>
    /// <returns>コルーチン</returns>
    /// <param name="downloadRequest">ダウンロード要求</param>
    private IEnumerator LoadFormCacheOrDownloadCoroutine(AssetBundleDownloadRequest downloadRequest)
    {
        while (!this.assetBundleInfoManager.IsDownloadedList)
        {
            yield return(null);
        }

        yield return(this.assetBundleDownloader.LoadFromCacheOrDownloadAssetBundle(downloadRequest));
    }
    /// <summary>
    /// アセットバンドルのダウンロード
    /// </summary>
    /// <returns>コルーチン</returns>
    /// <param name="downloadRequest">ダウンロードリクエスト</param>
    public IEnumerator LoadFromCacheOrDownloadAssetBundle(AssetBundleDownloadRequest downloadRequest)
    {
        while (!Caching.ready)
        {
            yield return(null);
        }

        var platformName = PlatformNameManager.GetPlatformName(Application.platform);

        foreach (var assetBundleInfo in downloadRequest.AssetBundleInfos)
        {
            var assetBundleName = assetBundleInfo.AssetBundleName;
            var url             = string.Format("{0}/{1}/{2}", AssetBundleManagerConfig.ServerURL, platformName, assetBundleName);

            var webRequest = UnityWebRequest.Get(url);
            var hash       = UnityEngine.Hash128.Parse(assetBundleInfo.HashString);
            webRequest.downloadHandler = new DownloadHandlerAssetBundle(url, hash, assetBundleInfo.Crc);
            webRequest.timeout         = 300;
            webRequest.SetRequestHeader("Cache-Control", "no-cache");

#if UNITY_2017_2_OR_NEWER
            yield return(webRequest.SendWebRequest());
#else
            yield return(webRequest.Send());
#endif

            while (!webRequest.isDone)
            {
                if (webRequest.isNetworkError || webRequest.isHttpError)
                {
                    if (downloadRequest.OnError != null)
                    {
                        downloadRequest.OnError.Invoke("AssetBundleInfoList Download Error.");
                    }
                    this.DownloadRequestErrorEvent.Invoke(downloadRequest);
                    webRequest.Dispose();
                    yield break;
                }
                Debug.LogFormat("[{0}] Download Progress. : {1}%", assetBundleName, (webRequest.downloadProgress * 100));
                yield return(null);
            }


            var handler     = webRequest.downloadHandler as DownloadHandlerAssetBundle;
            var assetBundle = handler.assetBundle;

            this.AssetBundleDownloadedEvent.Invoke(assetBundle);
            webRequest.downloadHandler.Dispose();
        }


        if (downloadRequest.OnCompleted != null)
        {
            downloadRequest.OnCompleted.Invoke();
        }
        this.DownloadRequestCompletedEvent.Invoke(downloadRequest);
    }
Exemple #5
0
    /// <summary>
    /// アセットバンドルをキャッシュから読み込み、またはダウンロードする
    /// </summary>
    /// <returns>コルーチン</returns>
    /// <param name="assetBundleName">アセットバンドル名</param>
    /// <param name="onError">エラー時コールバック</param>
    /// <param name="onCompleted">完了時コールバック</param>
    /// <param name="isDownloadDependencies">依存アセットバンドルをダウンロードするか</param>
    public void LoadFromCacheOrDownloadAssetBundle(string assetBundleName, System.Action <string> onError, System.Action onCompleted, bool isDownloadDependencies = true)
    {
        if (!this.assetBundleInfoManager.IsDownloadedList)
        {
            if (onError != null)
            {
                onError.Invoke("初期化が終了していません");
            }
            return;
        }

        if (this.onMemoryAssetBundleManager.CheckAssetBundleExists(assetBundleName))
        {
            if (onCompleted != null)
            {
                onCompleted.Invoke();
            }
            return;
        }

        if (!this.assetBundleInfoManager.CheckAssetBundleNameExists(assetBundleName))
        {
            if (onError != null)
            {
                onError.Invoke("指定されたアセットバンドル名のアセットバンドルが見つかりません");
            }
            return;
        }

        var assetBundleInfoList = new List <AssetBundleInfo>();
        var assetBundleInfo     = this.assetBundleInfoManager.GetAssetBundleInfo(assetBundleName);

        assetBundleInfoList.Add(assetBundleInfo);

        if (isDownloadDependencies)
        {
            var dependenceInfos = this.assetBundleInfoManager.GetDependenceInfos(assetBundleInfo);
            assetBundleInfoList.AddRange(dependenceInfos);
        }

        var downloadRequest = new AssetBundleDownloadRequest(assetBundleInfoList.ToArray(), onError, onCompleted);

        this.downloadRequestQueue.Enqueue(downloadRequest);
    }