1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- import { _decorator, Component, Node } from 'cc';
- import { GameFlowManager } from './GameFlowManager';
- const { ccclass, property } = _decorator;
- /**
- * 个人资料触发器,用于点击场景中的个人资料按钮时激活个人资料UI
- */
- @ccclass('PersonalInfoTrigger')
- export class PersonalInfoTrigger extends Component {
- @property({
- type: Node,
- tooltip: '游戏流程管理器所在的节点'
- })
- gameFlowManagerNode: Node | null = null;
-
- @property({
- tooltip: '是否启用触发器'
- })
- isEnabled: boolean = true;
-
- // 游戏流程管理器引用
- private gameFlowManager: GameFlowManager | null = null;
-
- start() {
- // 注册点击事件
- this.node.on(Node.EventType.TOUCH_END, this.onPersonalInfoClicked, this);
-
- // 获取GameFlowManager引用
- if (this.gameFlowManagerNode) {
- this.gameFlowManager = this.gameFlowManagerNode.getComponent(GameFlowManager);
- if (!this.gameFlowManager) {
- console.error('游戏流程管理器节点上没有GameFlowManager组件');
- }
- } else {
- console.error('未设置游戏流程管理器节点');
- }
- }
-
- /**
- * 个人资料点击回调
- */
- private onPersonalInfoClicked() {
- if (!this.isEnabled) {
- console.log('个人资料触发器已禁用');
- return;
- }
-
- if (this.gameFlowManager) {
- // 调用游戏流程管理器显示当前NPC的个人资料
- this.gameFlowManager.showCurrentNpcPersonalInfo();
- } else {
- console.error('游戏流程管理器未设置,无法显示个人资料');
- }
- }
-
- /**
- * 启用触发器
- */
- public enable() {
- this.isEnabled = true;
- }
-
- /**
- * 禁用触发器
- */
- public disable() {
- this.isEnabled = false;
- }
-
- onDestroy() {
- // 移除事件监听
- this.node.off(Node.EventType.TOUCH_END, this.onPersonalInfoClicked, this);
- }
- }
|