import { _decorator, Component, ProgressBar } from 'cc'; import { md5 } from '../core/utils/MD5'; import { ConfigData } from '../Data/ConfigData'; import { g } from '../Data/g'; import { Login } from './Login'; import { AppUpdate } from './AppUpdate'; import { ISJSB, platform } from '../Data/platform'; import { Utils } from '../core/utils/Utils'; import { HotUpdate } from '../HotUpdate/HotUpdate'; import { BitmapFont } from '../core/ui/BitmapFont'; import { SoundSystem } from '../Main/SoundSystem'; const { ccclass, property } = _decorator; @ccclass('App') export class App extends Component { @property({ type: Login, tooltip: "登录脚本" }) public login: Login; @property({ type: AppUpdate, tooltip: "应用更新脚本" }) public appUpdate: AppUpdate; @property({ type: HotUpdate, tooltip: "热更新脚本" }) public hotUpdate: HotUpdate; @property({ type: ProgressBar, tooltip: "加载进度条组件" }) public progressBar: ProgressBar; @property({ type: BitmapFont, tooltip: "加载进度" }) loadProgressBitmapFont: BitmapFont; private configLoaded = false; onLoad() { platform.removeSplash(); platform.reportThinkingOnce('openGame'); } start() { SoundSystem.stop(); platform.checkCPermissions(); this.loadConfig(); } private async loadConfig() { await this.node.getComponent(ConfigData).loadConfig(); this.configLoaded = true; } update() { if (this.configLoaded) { if (ISJSB) { if (this.hotUpdate.versionIsNew && this.appUpdate.versionIsNew != -1 && g.deviceData.needlogin && (g.deviceData.imei || g.deviceData.oaid || g.deviceData.androId || g.deviceData.mac)) { let account = new md5().hex_md5(g.deviceData.imei + g.deviceData.oaid + g.deviceData.androId + g.deviceData.mac); this.login.login(account); g.deviceData.needlogin = false; } else if (g.deviceData.channel && g.deviceData.version) { this.appUpdate.checkNativeVersion(g.deviceData.version); g.deviceData.version = null; } if (g.deviceData.apkDownloading) {//如果apk正在下载 this.appUpdate.setDownloadAPKProgress(); } } else { this.login.login(); this.configLoaded = false; } } } onHotUpdateProgress(progress: number) { this.progressBar.progress = progress; // this.loadProgressBitmapFont.string = Math.floor(progress / totalCount * 100) + '%' } }