HotUpdatePanel.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import HotUpdate, { HotOptions } from "../../../mk/sdk/hot/HotUpdate";
  2. import Login from "../login/Login";
  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. public login:Login = null;
  17. onLoad() {
  18. this.initView();
  19. let options = new HotOptions();
  20. options.OnVersionInfo = (data) => {
  21. let { local, server } = data;
  22. // this.versionLabel.string = `本地版本号:${local}, 服务器版本号:${server}`;
  23. };
  24. options.OnUpdateProgress = (event: jsb.EventAssetsManager) => {
  25. let bytes = event.getDownloadedBytes() + '/' + event.getTotalBytes();
  26. let files = event.getDownloadedFiles() + '/' + event.getTotalFiles();
  27. let file = event.getPercentByFile().toFixed(2);
  28. let byte = event.getPercent().toFixed(2);
  29. let msg = event.getMessage();
  30. console.log('[update]: 进度=' + file);
  31. // this.updateProgress.progress = parseFloat(file);
  32. // this.tipsLabel.string = '正在更新中,请耐心等待';
  33. console.log(msg);
  34. };
  35. options.OnNeedToUpdate = (data) => {
  36. HotUpdate.hotUpdate();
  37. };
  38. options.OnNoNeedToUpdate = () => {
  39. this.enterGame();
  40. };
  41. options.OnUpdateFailed = () => {
  42. // this.tipsLabel.string = '更新失败';
  43. console.log('热更新失败');
  44. // HotUpdate.checkUpdate();
  45. };
  46. options.OnUpdateSucceed = () => {
  47. // this.tipsLabel.string = '更新成功';
  48. console.log('更新成功');
  49. // DialogMgr.showTipsWithOkBtn('更新成功,点击确定重启游戏', () => {
  50. // cc.audioEngine.stopAll();
  51. // cc.game.restart();
  52. // });
  53. };
  54. HotUpdate.init(this.manifest, options);
  55. }
  56. /** */
  57. start() {
  58. }
  59. initView() {
  60. // this.tipsLabel.string = '';
  61. // this.versionLabel.string = '';
  62. // this.updateProgress.progress = 0;
  63. // this.addNode.destroyAllChildren();
  64. }
  65. // 检查更新
  66. checkHotUpdate() {
  67. if (cc.sys.isNative) {
  68. if (this.manifest) {
  69. this.tipsLabel.string = '正在获取版本...';
  70. HotUpdate.checkUpdate();
  71. }
  72. } else {
  73. console.log('web 平台不需要热更新');
  74. this.enterGame();
  75. }
  76. }
  77. enterGame() {
  78. console.log('进入游戏成功');
  79. // this.updateProgress.node.active = false;
  80. // cc.director.loadScene('GameScene');
  81. this.login.upda
  82. }
  83. }