12345678910111213141516171819202122232425262728293031323334353637383940 |
- import { _decorator, Button, Component, Node } from 'cc';
- const { ccclass, property, requireComponent, executeInEditMode } = _decorator;
- @ccclass('UIExtend/Switcher')
- @requireComponent(Button)
- @executeInEditMode(true)
- export class Switcher extends Component {
- @property(Node)
- on: Node = null
- @property(Node)
- off: Node = null
- private _isOn: boolean = true
- @property
- public get IsOn(): boolean {
- return this._isOn
- }
- public set IsOn(v: boolean) {
- this._isOn = v;
- if (this.on) this.on.active = v
- if (this.off) this.off.active = !v
- }
- protected onLoad(): void {
- this.node.on(Button.EventType.CLICK, this.onClick, this)
- }
- protected onDestroy(): void {
- this.node.off(Button.EventType.CLICK, this.onClick, this)
- }
- protected onClick(): void {
- this.IsOn = !this.IsOn
- }
- }
|