App.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { _decorator, Component, ProgressBar } from 'cc';
  2. import { md5 } from '../core/utils/MD5';
  3. import { ConfigData } from '../Data/ConfigData';
  4. import { g } from '../Data/g';
  5. import { Login } from './Login';
  6. import { AppUpdate } from './AppUpdate';
  7. import { ISJSB, platform } from '../Data/platform';
  8. import { Utils } from '../core/utils/Utils';
  9. import { HotUpdate } from '../HotUpdate/HotUpdate';
  10. import { BitmapFont } from '../core/ui/BitmapFont';
  11. import { SoundSystem } from '../Main/SoundSystem';
  12. const { ccclass, property } = _decorator;
  13. @ccclass('App')
  14. export class App extends Component {
  15. @property({ type: Login, tooltip: "登录脚本" })
  16. public login: Login;
  17. @property({ type: AppUpdate, tooltip: "应用更新脚本" })
  18. public appUpdate: AppUpdate;
  19. @property({ type: HotUpdate, tooltip: "热更新脚本" })
  20. public hotUpdate: HotUpdate;
  21. @property({ type: ProgressBar, tooltip: "加载进度条组件" })
  22. public progressBar: ProgressBar;
  23. @property({ type: BitmapFont, tooltip: "加载进度" })
  24. loadProgressBitmapFont: BitmapFont;
  25. private configLoaded = false;
  26. onLoad() {
  27. platform.removeSplash();
  28. platform.reportThinkingOnce('openGame');
  29. }
  30. start() {
  31. SoundSystem.stop();
  32. platform.checkCPermissions();
  33. this.loadConfig();
  34. }
  35. private async loadConfig() {
  36. await this.node.getComponent(ConfigData).loadConfig();
  37. this.configLoaded = true;
  38. }
  39. update() {
  40. if (this.configLoaded) {
  41. if (ISJSB) {
  42. if (this.hotUpdate.versionIsNew && this.appUpdate.versionIsNew != -1 && g.deviceData.needlogin && (g.deviceData.imei || g.deviceData.oaid || g.deviceData.androId || g.deviceData.mac)) {
  43. let account = new md5().hex_md5(g.deviceData.imei + g.deviceData.oaid + g.deviceData.androId + g.deviceData.mac);
  44. this.login.login(account);
  45. g.deviceData.needlogin = false;
  46. }
  47. else if (g.deviceData.channel && g.deviceData.version) {
  48. this.appUpdate.checkNativeVersion(g.deviceData.version);
  49. g.deviceData.version = null;
  50. }
  51. if (g.deviceData.apkDownloading) {//如果apk正在下载
  52. this.appUpdate.setDownloadAPKProgress();
  53. }
  54. }
  55. else {
  56. this.login.login();
  57. this.configLoaded = false;
  58. }
  59. }
  60. }
  61. onHotUpdateProgress(progress: number) {
  62. this.progressBar.progress = progress;
  63. // this.loadProgressBitmapFont.string = Math.floor(progress / totalCount * 100) + '%'
  64. }
  65. }