toJSON
方法用于将 ObstacleAvoidanceBehavior
对象转换为 JSON 格式的字符串。
obstacleBehavior.toJSON();
返回 ObstacleAvoidanceBehavior
对象的 JSON 格式字符串。
const obstacleBehavior = new Yuka.ObstacleAvoidanceBehavior();
const json = obstacleBehavior.toJSON();
console.log(json); // {"type":"ObstacleAvoidanceBehavior","weight":1,"radius":3,"maxDistance":10}
type
:字符串类型,表示对象类型,值为 "ObstacleAvoidanceBehavior"
。weight
:数字类型,表示对象的权重。radius
:数字类型,表示对象的避障半径。maxDistance
:数字类型,表示对象的最大避障距离。ObstacleAvoidanceBehavior.prototype.toJSON = function () {
return JSON.stringify( {
type: this.constructor.name,
weight: this.weight,
radius: this.radius,
maxDistance: this.maxDistance
} );
};