| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 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();
- gData.appData.updateState = UpdateState.IsUpdate;
- gData.appData.updatePercent = parseFloat(file);
- console.log('[update]: 进度=' + file);
- };
- options.OnNeedToUpdate = (data) => {
- HotUpdate.hotUpdate();
- };
- options.OnNoNeedToUpdate = () => {
- this.enterGame();
- };
- options.OnUpdateFailed = () => {
- // this.tipsLabel.string = '更新失败';
- console.log('热更新失败');
- setTimeout(() => {
- HotUpdate.checkUpdate();
- }, 2000);
- };
- options.OnUpdateSucceed = () => {
- // this.tipsLabel.string = '更新成功';
- console.log('更新成功');
- setTimeout(() => {
- cc.audioEngine.stopAll();
- cc.game.restart();
- }, 500);
- };
- 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;
- }
- }
|