const { ccclass, property } = cc._decorator; @ccclass export default class buyActivate extends cc.Component { @property(cc.Button) qiutBtn: cc.Button = null; @property(cc.Button) buyBtn: cc.Button = null; @property(cc.Label) countdown: cc.Label = null; private callback: Function = null; start() { } init(callback: Function, timeStr: string) { // 初始化回调函数 this.callback = callback; // 添加按钮事件监听 this.qiutBtn.node.on('click', this.onQuitBtnClick, this); this.buyBtn.node.on('click', this.onBuyBtnClick, this); this.countdown.string = timeStr; // 抖音& ios 显示钻石 其他 元 if (cc.sys.platform === cc.sys.BYTEDANCE_GAME && cc.sys.os === cc.sys.OS_IOS) { this.buyBtn.node.getChildByName("18yuan").active = false; this.buyBtn.node.getChildByName("18yuan_dy").active = true; } else { this.buyBtn.node.getChildByName("18yuan").active = true; this.buyBtn.node.getChildByName("18yuan_dy").active = false; } } // updateCountdown(str: string) { // this.countdown.string = str; // } onQuitBtnClick() { // 移除界面 this.node.destroy(); } onBuyBtnClick() { // 调用回调函数,触发passCheck中的购买逻辑 if (this.callback && typeof this.callback === 'function') { this.callback(); } // 移除界面 this.node.destroy(); } }