| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import HotUpdate, { HotOptions } from "../../../mk/sdk/hot/HotUpdate";
- import { UpdateState } from "../../data/AppData";
- 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;
- 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('进入游戏成功');
- gData.appData.updateState = UpdateState.UpdateFinish;
- }
- }
|