TypeScript中的set与get
private _id:number;
public get id():number{
return this._id;
}
public set id(value:number){//set:必须无返回值类型
this._id=value;
}
Inspector面板序列化set与get
const{ccclass,property}=cc._decorator;
@ccclass
export default class Test extends cc.Component{
@property //只写@property不设置参数
private _snowPrefab:cc.Node=null;
@property({type:cc.Node,visible:true})
private set snowPrefab(value:cc.Node){
cc.log("set snowPrefab");
this._snowPrefab=value;
}
private get snowPrefab():cc.Node{
return this._snowPrefab;
}
}