MatchMaster/assets/pause/script/PausePanel.ts
2026-08-28 19:21:40 +08:00

47 lines
1.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { ccclass } = cc._decorator;
type PausePanelAction = (event?: cc.Event, customEventData?: string) => void;
interface PausePanelActions {
[name: string]: PausePanelAction;
}
/** Pause prefab 中跨脚本按钮的桥接层;setUi 内部按钮仍保持原绑定。 */
@ccclass
export default class PausePanel extends cc.Component {
private actions: PausePanelActions = null;
bind(actions: PausePanelActions) {
this.actions = actions || {};
}
closePause(event?: cc.Event, customEventData?: string) {
this.invoke("closePause", event, customEventData);
}
shareFriend(event?: cc.Event, customEventData?: string) {
this.invoke("shareFriend", event, customEventData);
}
openMessage(event?: cc.Event, customEventData?: string) {
this.invoke("openMessage", event, customEventData);
}
returnHome(event?: cc.Event, customEventData?: string) {
this.invoke("returnHome", event, customEventData);
}
private invoke(name: string, event?: cc.Event, customEventData?: string) {
const action = this.actions && this.actions[name];
if (action) {
action(event, customEventData);
return;
}
cc.warn("PausePanel action is not bound:", name);
}
onDestroy() {
this.actions = null;
}
}