UILoadingPage.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import UIPage from "../Framework/UIPage";
  2. import Constant, { PageName } from "../Framework/Constant";
  3. import { cocosz } from "../Framework/CocosZ";
  4. import PlatUtils from "../../common-plugin/Scripts/PlatUtils";
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class UILoadingPage extends UIPage {
  8. private _loadingBar: cc.ProgressBar = null;
  9. constructor() {
  10. super(PageName.UILoadingPage);
  11. this.isValid() && this.onLoad();
  12. }
  13. protected onLoad() {
  14. // 健康忠告
  15. let health = cc.find("health", this._page);
  16. if (health) {
  17. if (cocosz.curLanguage == "zh" && (PlatUtils.IsHuaWei || PlatUtils.IsOPPO || cocosz.isDeBug)) {
  18. health.active = true;
  19. } else {
  20. health.active = false;
  21. }
  22. }
  23. this._loadingBar = cc.find("LoadingBar", this._page).getComponent(cc.ProgressBar);
  24. }
  25. protected onOpen() {
  26. cc.game.on(Constant.E_GAME_LOGIC, this._onGameMassageHandler, this);
  27. // 进度默认0.01
  28. this._loadingBar.progress = 0.01;
  29. // 最低进度
  30. let r = 0.01;
  31. cc.tween(this._page)
  32. .delay(0.2)
  33. .call(() => {
  34. r += 0.01;
  35. if (r < 1) { this._updateProgress(r); }
  36. })
  37. .union()
  38. .repeatForever()
  39. .start();
  40. }
  41. protected onClose() {
  42. cc.game.targetOff(this);
  43. }
  44. _onGameMassageHandler(event: any) {
  45. this._loadingBar.node.active = true;
  46. switch (event.type) {
  47. case Constant.E_UPDATE_PROGRESS: {
  48. this._updateProgress(event.data);
  49. break;
  50. }
  51. }
  52. }
  53. _updateProgress(pro: number) {
  54. if (pro > this._loadingBar.progress)
  55. this._loadingBar.progress = pro;
  56. }
  57. }