Main.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. const { ccclass, property } = _decorator;
  10. @ccclass('Main')
  11. export class Main extends Component {
  12. static _instance: Main = null;
  13. public static Instance(): Main {
  14. return Main._instance;
  15. }
  16. _HallUI: HallUI = null;
  17. _GameUI: GameUI = null;
  18. _GameNode: GameNode = null;
  19. start() {
  20. Main._instance = this;
  21. WindowManager.ins.register(this.node)
  22. WindowManager.ins.open("HallUI").then(panle => {
  23. this._HallUI = panle
  24. })
  25. WindowManager.ins.open("GameUI").then(panle => {
  26. this._GameUI = panle;
  27. this._GameUI.node.active = false;
  28. bundleMgr.loadAsset(GameConst.bundleName.resources,"prefabs/GameNode",Prefab, (err, res) => {
  29. this._GameNode = (instantiate(res) as Node).getComponent(GameNode);
  30. director.getScene().addChild(this._GameNode.node);
  31. })
  32. })
  33. }
  34. play() {
  35. this._HallUI.node.active = false;
  36. this._GameUI.node.active = true;
  37. this._GameUI.restart();
  38. this._GameNode.node.active = true;
  39. this._GameNode.restart();
  40. platformSystem.platform.hideBannerAd();
  41. }
  42. backHall() {
  43. platformSystem.platform.showBannerAd();
  44. this._GameNode.node.active = false;
  45. this._HallUI.node.active = true;
  46. this._GameUI.node.active = false;
  47. }
  48. }