Main.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { _decorator, Component, Node, Prefab, director, instantiate } from 'cc';
  2. import { GameNode } from './GameNode';
  3. import { GameUI } from './GameUI';
  4. import { HallUI } from './HallUI';
  5. import WindowManager from '../core/manager/WindowManager';
  6. import platformSystem from '../platform/platformSystem';
  7. import { bundleMgr } from '../core/manager/BundleManager';
  8. import { GameConst } from '../core/common/GameConst';
  9. import { audioMgr } from '../core/manager/AudioManager';
  10. import { settingData } from '../user/SettingData';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('Main')
  13. export class Main extends Component {
  14. public static I: Main;
  15. _HallUI: HallUI = null;
  16. _GameUI: GameUI = null;
  17. _GameNode: GameNode = null;
  18. start(){
  19. if(settingData.data.bgMusic){
  20. audioMgr.play(GameConst.audios.bg_music,true);
  21. }
  22. Main.I = this;
  23. WindowManager.ins.register(this.node)
  24. WindowManager.ins.open("HallUI").then(panle => {
  25. this._HallUI = panle
  26. })
  27. WindowManager.ins.open("GameUI").then(panle => {
  28. this._GameUI = panle;
  29. this._GameUI.node.active = false;
  30. bundleMgr.loadAsset(GameConst.bundleName.resources,"prefabs/GameNode",Prefab, (err, res) => {
  31. this._GameNode = (instantiate(res) as Node).getComponent(GameNode);
  32. director.getScene().addChild(this._GameNode.node);
  33. })
  34. })
  35. }
  36. play() {
  37. this._HallUI.node.active = false;
  38. this._GameUI.node.active = true;
  39. this._GameUI.restart();
  40. this._GameNode.node.active = true;
  41. this._GameNode.restart();
  42. platformSystem.platform.hideBannerAd();
  43. }
  44. backHall() {
  45. platformSystem.platform.showBannerAd();
  46. this._GameNode.node.active = false;
  47. this._HallUI.node.active = true;
  48. this._GameUI.node.active = false;
  49. }
  50. }