Beispiel #1
0
    /// <summary>
    /// セットアップ
    /// </summary>
    public void Setup(
        SimpleDialog dialog,
        string resourceVersion,
        List <AssetBundleInfo> oldInfoList,
        FileDownloadHandle newInfoListHandle,
        List <AssetBundleInfo> targetInfoList)
    {
        this.dialog            = dialog;
        this.oldInfoList       = oldInfoList;
        this.newInfoListHandle = newInfoListHandle;
        this.targetInfoList    = targetInfoList;
        this.downloadManager.SetDirectory(AssetManager.GetAssetBundleDirectoryPath());
        this.downloadManager.onCompleted = this.OnDownloaded;

        //進捗率0%表示
        this.text.text = "0%";

        for (int i = 0; i < this.targetInfoList.Count; i++)
        {
            //ダウンロード対象追加
            var handle = new FileDownloadHandle(resourceVersion, this.targetInfoList[i].assetBundleName);
            handle.onCompleted += this.OnDownloadedHandle;
            this.downloadManager.Add(handle);
        }

        //ダイアログが開ききったらダウンロード開始
        this.dialog.onCompleteShow = () => StartCoroutine(this.Download());
    }
    /// <summary>
    /// 可能ならダウンロード処理
    /// </summary>
    private void DownloadIfCan()
    {
        if (this.isError)
        {
            return;
        }

        int busyCount             = 0;
        FileDownloadHandle handle = null;

        for (int i = 0; i < this.handles.Count && busyCount < MAX_THREAD_COUNT; i++)
        {
            if (this.handles[i].status == FileDownloadHandle.Status.Downloading)
            {
                //処理中リクエスト数をカウント
                busyCount++;
            }
            else if (handle == null)
            {
                //未処理ハンドルの検索
                handle = this.handles[i];
            }
        }

        if (busyCount < MAX_THREAD_COUNT && handle != null)
        {
            //余裕があるなら未処理リクエストの処理を開始
            handle.Send();
            this.DownloadIfCan();
        }
    }
    /// <summary>
    /// ダウンロード完了時
    /// </summary>
    private void OnDownloadCompleted(FileDownloadHandle handle)
    {
        if (handle.status == FileDownloadHandle.Status.Error)
        {
            //エラー発生
            this.isError = true;
        }

        //エラー発生中の場合
        if (this.isError)
        {
            //処理中のものが無くなったら
            if (!this.handles.Exists(x => x.status == FileDownloadHandle.Status.Downloading))
            {
                //エラーダイアログ表示してリトライさせる
                var dialog  = SharedUI.Instance.ShowSimpleDialog(true);
                var content = dialog.SetAsMessageDialog(Masters.LocalizeTextDB.Get("ConnectErrorMessage"));
                content.buttonGroup.buttons[0].onClick = dialog.Close;
                dialog.onClose = () =>
                {
                    this.isError = false;
                    this.DownloadIfCan();
                };
            }
            return;
        }

        if (handle.isAutoSave)
        {
            //ファイル保存
            this.SaveFile(handle);
        }

        //完了したハンドルの除去
        this.handles.Remove(handle);

        if (this.handles.Count > 0)
        {
            //可能なら次のファイルダウンロード開始
            this.DownloadIfCan();
        }
        else
        {
            //完了通知
            this.onCompleted?.Invoke();
        }
    }
Beispiel #4
0
    /// <summary>
    /// 各ファイルダウンロード完了時
    /// </summary>
    private void OnDownloadedHandle(FileDownloadHandle handle)
    {
        if (handle.status == FileDownloadHandle.Status.Success)
        {
            //古い情報消す
            this.oldInfoList.RemoveAll(x => x.assetBundleName == handle.name);

            //新しい情報保存
            var newInfo = this.targetInfoList.Find(x => x.assetBundleName == handle.name);
            if (newInfo != null)
            {
                this.oldInfoList.Add(newInfo);
            }

            //情報バイナリ保存
            this.downloadManager.SaveFile(this.newInfoListHandle.hash, this.oldInfoList.ToBinary().Cryption());
        }
    }
Beispiel #5
0
    /// <summary>
    /// リソースリストチェック
    /// </summary>
    private void CheckResourceList()
    {
#if !USE_ASSETBUNDLE
        this.Login();
        return;
#endif
        //リソースバージョン取得通信
        TopApi.CallTopApi((resourceVersion) =>
        {
            var handle        = new FileDownloadHandle(resourceVersion, "infoList.dat");
            handle.isAutoSave = false;

            //リソースリストダウンロード開始
            var downloader = new FileDownloadManager();
            downloader.Add(handle);
            downloader.DownloadStart();

            //タッチブロック
            SharedUI.Instance.DisableTouch();

            //ダウンロード完了時
            downloader.onCompleted = () =>
            {
                //タッチブロック解除
                SharedUI.Instance.EnableTouch();

                var directory = AssetManager.GetAssetBundleDirectoryPath();

                //旧リソースリスト
                var oldInfoList = new List <AssetBundleInfo>();
                {
                    var path = Path.Combine(directory, handle.hash);
                    if (File.Exists(path))
                    {
                        var bytes = File.ReadAllBytes(path).Cryption();
                        oldInfoList.AddRange(BinaryUtility.CreateArray <AssetBundleInfo>(bytes));
                    }
                }

                //新リソースリスト
                var newInfoList = new List <AssetBundleInfo>();
                {
                    var bytes = handle.bytes.Cryption();
                    newInfoList.AddRange(BinaryUtility.CreateArray <AssetBundleInfo>(bytes));
                }

                //ダウンロード対象
                var targetInfoList = new List <AssetBundleInfo>();

                for (int i = 0; i < newInfoList.Count; i++)
                {
                    var targetInfo = newInfoList[i];
                    var filePath   = Path.Combine(directory, targetInfo.assetBundleName.GetHashString());

                    //既存ファイルの場合
                    if (File.Exists(filePath))
                    {
                        //CRC値が同じならダウンロードの必要無し
                        var oldInfo = oldInfoList.Find(x => x.assetBundleName == targetInfo.assetBundleName);
                        if (oldInfo != null && oldInfo.crc == targetInfo.crc)
                        {
                            continue;
                        }
                    }

                    //ダウンロード対象として追加
                    targetInfoList.Add(targetInfo);
                }

                //ダウンロードする必要があるなら
                if (targetInfoList.Count > 0)
                {
                    //確認ダイアログ表示
                    this.OpenDownlodConfirmDialog(targetInfoList, () =>
                    {
                        //ダウンロード開始
                        var dialog  = SharedUI.Instance.ShowSimpleDialog();
                        var content = dialog.AddContent(this.downloadDialogContentPrefab);
                        content.Setup(dialog, resourceVersion, oldInfoList, handle, targetInfoList);

                        //ダウンロード終わったら
                        dialog.onClose = () =>
                        {
                            //アセットバンドル情報のセット
                            AssetManager.SetAssetBundleInfoList(newInfoList);
                            //ログイン
                            this.Login();
                        };
                    });
                }
                else
                {
                    //アセットバンドル情報のセット
                    AssetManager.SetAssetBundleInfoList(newInfoList);
                    //ログイン
                    this.Login();
                }
            };
        });
    }
 /// <summary>
 /// ダウンロード
 /// </summary>
 public void Add(FileDownloadHandle handle)
 {
     handle.onCompleted += this.OnDownloadCompleted;
     this.handles.Add(handle);
 }
 /// <summary>
 /// ファイル保存
 /// </summary>
 public void SaveFile(FileDownloadHandle handle)
 {
     this.SaveFile(handle.hash, handle.bytes);
 }