新建的一个继承自cc.Component的脚本,添加一个属性例如
@property({type:cc.Boolean})
isCheck:cc.Boolean = false;
如何监听isCheck的值的setter
直接在脚本中写会报错
public set isCheck(check:cc.Booolean){
this.isCheck = check;
//do something
}
新建的一个继承自cc.Component的脚本,添加一个属性例如
@property({type:cc.Boolean})
isCheck:cc.Boolean = false;
如何监听isCheck的值的setter
直接在脚本中写会报错
public set isCheck(check:cc.Booolean){
this.isCheck = check;
//do something
}
@property(cc.Label)
private tipLabel: cc.Label = null;
@property
private _text: string = '';
@property({
type: cc.String
})
public get string(): string {
return this._text;
}
public set string(value) {
this.notify(this._text, value);
this._text = value;
}
private notify(oldValue: string, newValue: string) {
console.log(`oldValue:${oldValue},newValue:${newValue}`);
if (!!this.tipLabel) {
this.tipLabel.string = `oldValue:${oldValue},newValue:${newValue}`;
}
}