LieDetectorTrigger.ts 2.0 KB

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