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;
	}
}
注意:Inspector序列化set与get时,访问权限要保持一致。

相关文章:

  • 2021-08-24
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
  • 2021-07-08
  • 2021-11-25
  • 2021-05-23
  • 2021-07-16
猜你喜欢
  • 2021-11-21
  • 2021-12-25
  • 2021-08-22
  • 2022-12-23
  • 2021-10-01
  • 2021-06-23
  • 2021-05-15
相关资源
相似解决方案