RosterTrigger.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { _decorator, Component, Node } from 'cc';
  2. import { RosterManager } from './RosterManager';
  3. import { GameFlowManager } from './GameFlowManager';
  4. const { ccclass, property } = _decorator;
  5. /**
  6. * 名单触发器,用于点击场景中的名单图片时激活名单UI
  7. */
  8. @ccclass('RosterTrigger')
  9. export class RosterTrigger extends Component {
  10. @property({
  11. type: RosterManager,
  12. tooltip: '名单管理器引用 (已弃用,请使用GameFlowManager中的名单管理器)'
  13. })
  14. rosterManager: RosterManager = null;
  15. @property({
  16. type: Node,
  17. tooltip: '游戏流程管理器所在的节点'
  18. })
  19. gameFlowManagerNode: Node = null;
  20. @property({
  21. tooltip: '是否启用触发器'
  22. })
  23. isEnabled: boolean = true;
  24. // 游戏流程管理器引用
  25. private gameFlowManager: GameFlowManager = null;
  26. start() {
  27. // 注册节点点击事件
  28. this.node.on(Node.EventType.TOUCH_END, this.onRosterClicked, this);
  29. // 从节点获取GameFlowManager组件
  30. if (this.gameFlowManagerNode) {
  31. this.gameFlowManager = this.gameFlowManagerNode.getComponent(GameFlowManager);
  32. if (!this.gameFlowManager) {
  33. console.error('游戏流程管理器节点上没有GameFlowManager组件');
  34. }
  35. } else {
  36. // 尝试在场景中查找
  37. this.gameFlowManager = this.node.scene.getComponentInChildren(GameFlowManager);
  38. if (!this.gameFlowManager) {
  39. console.error('无法在场景中找到GameFlowManager组件');
  40. }
  41. }
  42. }
  43. /**
  44. * 名单被点击时的处理
  45. */
  46. private onRosterClicked() {
  47. if (!this.isEnabled) return;
  48. if (this.gameFlowManager) {
  49. // 调用GameFlowManager的方法显示名单
  50. this.gameFlowManager.showCurrentLevelRoster();
  51. }
  52. }
  53. /**
  54. * 启用触发器
  55. */
  56. public enable() {
  57. this.isEnabled = true;
  58. }
  59. /**
  60. * 禁用触发器
  61. */
  62. public disable() {
  63. this.isEnabled = false;
  64. }
  65. onDestroy() {
  66. // 移除事件监听
  67. this.node.off(Node.EventType.TOUCH_END, this.onRosterClicked, this);
  68. }
  69. }