Main.ts 1.3 KB

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