| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import HotUpdate, { HotOptions } from "../../../mk/sdk/hot/HotUpdate";
- import Login from "../login/Login";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class HotUpdatePanel extends cc.Component {
- @property({ displayName: 'project.manifest', type: cc.Asset, })
- manifest: cc.Asset = null;
- @property({ displayName: '版本号', type: cc.Label, })
- versionLabel: cc.Label = null;
- @property({ displayName: '热更新进度条', type: cc.ProgressBar })
- updateProgress: cc.ProgressBar = null;
- @property({ displayName: '消息提示', type: cc.Label })
- tipsLabel: cc.Label = null;
- @property({ displayName: '添加节点', type: cc.Node })
- addNode: cc.Node = null;
- public login:Login = null;
- onLoad() {
- this.initView();
- let options = new HotOptions();
- options.OnVersionInfo = (data) => {
- let { local, server } = data;
- // this.versionLabel.string = `本地版本号:${local}, 服务器版本号:${server}`;
- };
- options.OnUpdateProgress = (event: jsb.EventAssetsManager) => {
- let bytes = event.getDownloadedBytes() + '/' + event.getTotalBytes();
- let files = event.getDownloadedFiles() + '/' + event.getTotalFiles();
- let file = event.getPercentByFile().toFixed(2);
- let byte = event.getPercent().toFixed(2);
- let msg = event.getMessage();
- console.log('[update]: 进度=' + file);
- // this.updateProgress.progress = parseFloat(file);
- // this.tipsLabel.string = '正在更新中,请耐心等待';
- console.log(msg);
- };
- options.OnNeedToUpdate = (data) => {
- HotUpdate.hotUpdate();
- };
- options.OnNoNeedToUpdate = () => {
- this.enterGame();
- };
- options.OnUpdateFailed = () => {
- // this.tipsLabel.string = '更新失败';
- console.log('热更新失败');
- // HotUpdate.checkUpdate();
- };
- options.OnUpdateSucceed = () => {
- // this.tipsLabel.string = '更新成功';
- console.log('更新成功');
- // DialogMgr.showTipsWithOkBtn('更新成功,点击确定重启游戏', () => {
- // cc.audioEngine.stopAll();
- // cc.game.restart();
- // });
- };
- HotUpdate.init(this.manifest, options);
- }
- /** */
- start() {
- }
- initView() {
- // this.tipsLabel.string = '';
- // this.versionLabel.string = '';
- // this.updateProgress.progress = 0;
- // this.addNode.destroyAllChildren();
- }
- // 检查更新
- checkHotUpdate() {
- if (cc.sys.isNative) {
- if (this.manifest) {
- this.tipsLabel.string = '正在获取版本...';
- HotUpdate.checkUpdate();
- }
- } else {
- console.log('web 平台不需要热更新');
- this.enterGame();
- }
- }
- enterGame() {
- console.log('进入游戏成功');
- // this.updateProgress.node.active = false;
- // cc.director.loadScene('GameScene');
- this.login.upda
- }
- }
|