Beispiel #1
0
    /// <summary>
    /// 热更新,资源下载
    /// </summary>
    /// <param name="mono"></param>
    /// <param name="onComplete"></param>
    public static void DownloadCloudAssets(this MonoBehaviour mono, System.Action <string, bool> onComplete)
    {
        mono.DownloadCloudAssets((path, downloadSize, size) =>
        {
            //EginProgressHUD.Instance.ShowWaitHUD("正在下载 : " + path + ",\r\n 总进度 : " + downloadSize + "/" + size);//显示正在下载(更新整个游戏)
            if (InstantUpdateCallback != null)
            {
                InstantUpdateCallback.RawGetFunc("OnProcess").Call(path, downloadSize, size);
            }
        }, (error, isDownloaded) =>
        {
            if (error != null)
            {
                //Debug.LogError("下载出错了 : " + error);
                //EginProgressHUD.Instance.ShowPromptHUD("下载出错了 : " + error, 3f);
            }
            else
            {
                //EginProgressHUD.Instance.HideHUD();
                if (onComplete != null)
                {
                    onComplete(error, isDownloaded);
                }
            }

            if (InstantUpdateCallback != null)
            {
                InstantUpdateCallback.RawGetFunc("OnFinish").Call(error, isDownloaded);
            }
        });
    }
Beispiel #2
0
    public static void DownloadCloudAssets(this MonoBehaviour mono, System.Action <string, long, long> onProcess, System.Action <string, bool> onComplete)
    {
        string src = Constants.UpdateUrl;//调用热更新地址是会自动切换地址
        string des = Constants.DownloadPath;

        GetVersionUpdateControl((versionCode) => {
#if UNITY_EDITOR
            if (SimpleFramework.Manager.GameManager._VersionControl_ali > 0)
            {
                versionCode = SimpleFramework.Manager.GameManager._VersionControl_ali;
            }
#endif

            if (versionCode <= 0)
            {//versionCode > 0 才是有效的
                Debug.LogError("下载出错了 : 阿里云上的版本号为 0");

                mono.Delay(30f, () => mono.DownloadCloudAssets(onProcess, onComplete));//如果下载出错了 没有下载完,那么重新下载
            }
            else
            {
                //JSONObject localConfig = GetLocalConfigJson(Constants.DataPath);
                //int localVersionCode = System.Convert.ToInt32(localConfig[Constants.InstantUpdate_VersionCode]);
                //if (localVersionCode == versionCode)
                //{//版本号相同, 不用热更新
                //    onComplete(null, false);
                //    return;
                //}

                //localConfig.RemoveField(Constants.InstantUpdate_VersionTime);
                //localConfig.RemoveField(Constants.InstantUpdate_VersionCode);
                //List<string> localGameModuleList = localConfig.keys;
                List <string> localGameModuleList = GetLocalModuleList();

                src = InsertUpdateUrlWithVersionCode(src, versionCode + "");//插入 热更新版本号

                if (!File.Exists(des + Constants.Config_File))
                {
                    Copy(Constants.DataPath + Constants.Config_File, des);
                }
                mono.UpdateGameModules(src, des, localGameModuleList, true, onProcess, (error, config) =>
                {
                    if (error != null)
                    {
                        Debug.LogError("下载出错了 : " + error);

                        mono.Delay(30f, () => mono.DownloadCloudAssets(onProcess, onComplete));//如果下载出错了 没有下载完,那么重新下载
                    }
                    else
                    {
                        //if (config.IsAvailable()) //有需要更新的资源
                        //    mono.StartCoroutine(mono.DoCheckDownloadComplete(src,des,onProcess, onComplete));
                        //else //没有需要更新的资源
                        //    if (onComplete != null) onComplete(null,false);//无资源更新,第二个参数为false
                        if (onComplete != null)
                        {
                            onComplete(null, config.IsAvailable());
                        }
                    }
                });
            }
        });
    }