AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

toJSON

描述

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 实例的 onEnteronExit 属性在 toJson 方法返回的 JSON 对象中会变成字符串格式。
  • 在 JSON 序列化时,函数会被自动忽略,因此 SphericalTriggerRegion 实例的方法不会出现在 toJSON() 的返回结果中。