1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import { _decorator, Component, Node } from 'cc';
- import { RosterManager } from './RosterManager';
- import { GameFlowManager } from './GameFlowManager';
- const { ccclass, property } = _decorator;
- /**
- * 名单触发器,用于点击场景中的名单图片时激活名单UI
- */
- @ccclass('RosterTrigger')
- export class RosterTrigger extends Component {
- @property({
- type: RosterManager,
- tooltip: '名单管理器引用 (已弃用,请使用GameFlowManager中的名单管理器)'
- })
- rosterManager: RosterManager = null;
-
- @property({
- type: Node,
- tooltip: '游戏流程管理器所在的节点'
- })
- gameFlowManagerNode: Node = null;
-
- @property({
- tooltip: '是否启用触发器'
- })
- isEnabled: boolean = true;
-
- // 游戏流程管理器引用
- private gameFlowManager: GameFlowManager = null;
-
- start() {
- // 注册节点点击事件
- this.node.on(Node.EventType.TOUCH_END, this.onRosterClicked, this);
-
- // 从节点获取GameFlowManager组件
- if (this.gameFlowManagerNode) {
- this.gameFlowManager = this.gameFlowManagerNode.getComponent(GameFlowManager);
- if (!this.gameFlowManager) {
- console.error('游戏流程管理器节点上没有GameFlowManager组件');
- }
- } else {
- // 尝试在场景中查找
- this.gameFlowManager = this.node.scene.getComponentInChildren(GameFlowManager);
- if (!this.gameFlowManager) {
- console.error('无法在场景中找到GameFlowManager组件');
- }
- }
- }
-
- /**
- * 名单被点击时的处理
- */
- private onRosterClicked() {
- if (!this.isEnabled) return;
-
- if (this.gameFlowManager) {
- // 调用GameFlowManager的方法显示名单
- this.gameFlowManager.showCurrentLevelRoster();
- }
- }
-
- /**
- * 启用触发器
- */
- public enable() {
- this.isEnabled = true;
- }
-
- /**
- * 禁用触发器
- */
- public disable() {
- this.isEnabled = false;
- }
-
- onDestroy() {
- // 移除事件监听
- this.node.off(Node.EventType.TOUCH_END, this.onRosterClicked, this);
- }
- }
|