HotUpdatePanel.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import HotUpdate, { HotOptions } from "../../../mk/sdk/hot/HotUpdate";
  2. import { UpdateState } from "../../data/AppData";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class HotUpdatePanel extends cc.Component {
  6. @property({ displayName: 'project.manifest', type: cc.Asset, })
  7. manifest: cc.Asset = null;
  8. // @property({ displayName: '版本号', type: cc.Label, })
  9. // versionLabel: cc.Label = null;
  10. // @property({ displayName: '热更新进度条', type: cc.ProgressBar })
  11. // updateProgress: cc.ProgressBar = null;
  12. // @property({ displayName: '消息提示', type: cc.Label })
  13. // tipsLabel: cc.Label = null;
  14. // @property({ displayName: '添加节点', type: cc.Node })
  15. // addNode: cc.Node = null;
  16. onLoad() {
  17. this.initView();
  18. let options = new HotOptions();
  19. options.OnVersionInfo = (data) => {
  20. let { local, server } = data;
  21. // this.versionLabel.string = `本地版本号:${local}, 服务器版本号:${server}`;
  22. };
  23. options.OnUpdateProgress = (event: jsb.EventAssetsManager) => {
  24. let bytes = event.getDownloadedBytes() + '/' + event.getTotalBytes();
  25. let files = event.getDownloadedFiles() + '/' + event.getTotalFiles();
  26. let file = event.getPercentByFile().toFixed(2);
  27. let byte = event.getPercent().toFixed(2);
  28. let msg = event.getMessage();
  29. console.log('[update]: 进度=' + file);
  30. // this.updateProgress.progress = parseFloat(file);
  31. // this.tipsLabel.string = '正在更新中,请耐心等待';
  32. console.log(msg);
  33. };
  34. options.OnNeedToUpdate = (data) => {
  35. HotUpdate.hotUpdate();
  36. };
  37. options.OnNoNeedToUpdate = () => {
  38. this.enterGame();
  39. };
  40. options.OnUpdateFailed = () => {
  41. // this.tipsLabel.string = '更新失败';
  42. console.log('热更新失败');
  43. // HotUpdate.checkUpdate();
  44. };
  45. options.OnUpdateSucceed = () => {
  46. // this.tipsLabel.string = '更新成功';
  47. console.log('更新成功');
  48. // DialogMgr.showTipsWithOkBtn('更新成功,点击确定重启游戏', () => {
  49. // cc.audioEngine.stopAll();
  50. // cc.game.restart();
  51. // });
  52. };
  53. HotUpdate.init(this.manifest, options);
  54. }
  55. /** */
  56. start() {
  57. }
  58. initView() {
  59. // this.tipsLabel.string = '';
  60. // this.versionLabel.string = '';
  61. // this.updateProgress.progress = 0;
  62. // this.addNode.destroyAllChildren();
  63. }
  64. // 检查更新
  65. checkHotUpdate() {
  66. if (cc.sys.isNative) {
  67. if (this.manifest) {
  68. // this.tipsLabel.string = '正在获取版本...';
  69. HotUpdate.checkUpdate();
  70. }
  71. } else {
  72. console.log('web 平台不需要热更新');
  73. this.enterGame();
  74. }
  75. }
  76. enterGame() {
  77. console.log('进入游戏成功');
  78. gData.appData.updateState = UpdateState.UpdateFinish;
  79. }
  80. }