const { ccclass, property } = cc._decorator; /** * 关闭指定面板 * @author 薛鸿潇 */ @ccclass export default class BtnClosePanel extends cc.Component { @property({ displayName: '关闭界面', tooltip: '', type: cc.Node }) private node_panel: cc.Node = null!;; @property({ displayName: '点击效果', tooltip: "仅支持 NONE 和 SCALE", type: cc.Enum(cc.Button.Transition) }) public transition_type: cc.Button.Transition = cc.Button.Transition.NONE; @property({ displayName: '完成回调', tooltip: "面板打开完成后触发", type: cc.Component.EventHandler }) public onComplete: cc.Component.EventHandler[] = []; /** 阻断点击 */ public block_click: boolean = false; onLoad() { if (!this.node.getComponent(cc.Button)) { let btn_comp = this.node.addComponent(cc.Button); btn_comp.transition = this.transition_type; } } start() { this.node.on('click', this.closePanel, this); } private async closePanel() { mk.audio.playEffect("button"); if (this.block_click) return; if (this.node_panel) { mk.ui.closePanel(this.node_panel.name); } const c_count = this.onComplete.length; for (let i = 0; i < c_count; i++) { if (this.onComplete[i].handler) this.onComplete[i].emit([]) } } // update (dt) {} }