Files
2025-09-20 12:22:00 +08:00

43 lines
1.0 KiB
TypeScript

import { _decorator, Button, Component, Node, NodeEventType, Sprite } from "cc";
import { GButton } from "../../../Main/Common/GButton";
const { ccclass, property } = _decorator;
@ccclass("SimpleToggle")
export class SimpleToggle extends Component {
@property(Sprite)
selectedSprite: Sprite = null;
@property(Sprite)
unSelectedSprite: Sprite = null;
callback: () => {};
toggleGroupCallBack: Function;
btn: Button;
protected onLoad(): void {
GButton.BandClick(this.node,this.onClickThis,this);
this.btn = this.getComponent(Button);
}
refresh(isSelected: boolean) {
this.selectedSprite.node.active = isSelected;
this.unSelectedSprite.node.active = !isSelected;
}
onClickThis() {
if (this.callback) {
this.callback();
}
if (this.toggleGroupCallBack) {
this.toggleGroupCallBack(this.node);
}
this.btn.interactable = false;
}
protected onDestroy(): void {
//this.node.off(NodeEventType.TOUCH_START, this.onClickThis, this);
this.callback = null;
}
}