Main.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. import { autoBind } from '../core/extend/AutoBind';
  12. import { BaseExp } from '../core/base/BaseExp';
  13. const { ccclass, property } = _decorator;
  14. @ccclass('Main')
  15. export class Main extends BaseExp {
  16. public static I: Main;
  17. @autoBind({type:Node,tooltip:"资源加载lable"})
  18. public start_bg: Node;
  19. _HallUI: HallUI = null;
  20. _GameUI: GameUI = null;
  21. _GameNode: GameNode = null;
  22. start(){
  23. if(settingData.data.bgMusic){
  24. audioMgr.play(GameConst.audios.bg_music,true);
  25. }
  26. Main.I = this;
  27. WindowManager.ins.register(this.node)
  28. WindowManager.ins.open("HallUI").then(panle => {
  29. this._HallUI = panle
  30. })
  31. WindowManager.ins.open("GameUI").then(panle => {
  32. this._GameUI = panle;
  33. this._GameUI.node.active = false;
  34. bundleMgr.loadAsset(GameConst.bundleName.resources,"prefabs/GameNode",Prefab, (err, res) => {
  35. this._GameNode = (instantiate(res) as Node).getComponent(GameNode);
  36. director.getScene().addChild(this._GameNode.node);
  37. })
  38. })
  39. }
  40. play() {
  41. this.start_bg.active = false;
  42. this._HallUI.node.active = false;
  43. this._GameUI.node.active = true;
  44. this._GameUI.restart();
  45. this._GameNode.node.active = true;
  46. this._GameNode.restart();
  47. platformSystem.platform.hideBannerAd();
  48. }
  49. backHall() {
  50. platformSystem.platform.showBannerAd();
  51. this.start_bg.active = true;
  52. this._GameNode.node.active = false;
  53. this._HallUI.node.active = true;
  54. this._GameUI.node.active = false;
  55. }
  56. }