RosterTrigger.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { _decorator, Component, Node } from 'cc';
  2. import { RosterManager } from './RosterManager';
  3. const { ccclass, property } = _decorator;
  4. /**
  5. * 名单触发器,用于点击场景中的名单图片时激活名单UI
  6. */
  7. @ccclass('RosterTrigger')
  8. export class RosterTrigger extends Component {
  9. @property({
  10. type: RosterManager,
  11. tooltip: '名单管理器引用'
  12. })
  13. rosterManager: RosterManager = null;
  14. @property({
  15. tooltip: '是否启用触发器'
  16. })
  17. isEnabled: boolean = true;
  18. start() {
  19. // 注册节点点击事件
  20. this.node.on(Node.EventType.TOUCH_END, this.onRosterClicked, this);
  21. }
  22. /**
  23. * 名单被点击时的处理
  24. */
  25. private onRosterClicked() {
  26. if (!this.isEnabled) {
  27. return;
  28. }
  29. console.log('名单图片被点击');
  30. // 如果有名单管理器引用,则显示名单UI
  31. if (this.rosterManager) {
  32. this.rosterManager.showRosterPanel();
  33. } else {
  34. console.error('未设置名单管理器引用,无法显示名单UI');
  35. }
  36. }
  37. /**
  38. * 启用触发器
  39. */
  40. public enable() {
  41. this.isEnabled = true;
  42. }
  43. /**
  44. * 禁用触发器
  45. */
  46. public disable() {
  47. this.isEnabled = false;
  48. }
  49. onDestroy() {
  50. // 移除事件监听
  51. this.node.off(Node.EventType.TOUCH_END, this.onRosterClicked, this);
  52. }
  53. }