toJSON()
方法返回一个包含 SphericalTriggerRegion
实例的JSON格式的对象。
SphericalTriggerRegion.toJSON()
一个JSON格式的对象,包含 SphericalTriggerRegion
实例的所有属性。
const region = new SphericalTriggerRegion({
center: {x: 0, y: 0, z: 0},
radius: 10,
onEnter: () => console.log('进入区域'),
onExit: () => console.log('退出区域')
});
const regionJSON = region.toJSON();
console.log(regionJSON);
输出结果:
{
"center": {"x": 0, "y": 0, "z": 0},
"radius": 10,
"onEnter": "function",
"onExit": "function"
}
SphericalTriggerRegion
实例的 onEnter
和 onExit
属性在 toJson 方法返回的 JSON 对象中会变成字符串格式。SphericalTriggerRegion
实例的方法不会出现在 toJSON()
的返回结果中。