Main.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { EventType, ObserverManager } from './Manager/core/EventManager';
  2. import PrefabManager from './Manager/core/PrefabManager';
  3. import { UIID } from './Manager/core/UIID';
  4. import { gameModel } from './Module/Module';
  5. import CCUtils from './Utiles/CCUtils';
  6. import Utiles from './Utiles/Utiles';
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class Main extends cc.Component {
  10. public windowsLayer: cc.Node = null;
  11. start() {}
  12. protected onLoad(): void {}
  13. /**
  14. * 初始化
  15. *
  16. * @protected
  17. * @memberof Main
  18. */
  19. protected onEnable(): void {
  20. this.windowsLayer = CCUtils.findChild(this.node, 'windowsLayer');
  21. // 打开主界面
  22. PrefabManager.open(UIID.MainHome, this.windowsLayer);
  23. PrefabManager.open(UIID.GameMainPrefab, this.windowsLayer, (node: cc.Node) => {
  24. PrefabManager.close(node);
  25. });
  26. // 加载BGM
  27. // 监听管理类
  28. this.eventManager();
  29. }
  30. private eventManager(): void {
  31. // 打开游戏界面
  32. ObserverManager.addObserver(EventType.OpenGame, (data): void => {
  33. this.openGame(data);
  34. });
  35. }
  36. private openGame(data?: any): any {
  37. // 打开游戏界面 data.index 表示第几首歌
  38. gameModel.curIndex = data.index;
  39. console.log('打开游戏界面', gameModel.curIndex);
  40. PrefabManager.close(UIID.MainHome);
  41. PrefabManager.open(UIID.GameMainPrefab, this.windowsLayer);
  42. }
  43. }