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 方法将 Cell 实例转换为 JSON 字符串。该方法遵循 "JSON.stringify" 的约定,可以被传递到该函数中。

语法

cell.toJSON()

返回值

toJSON 方法返回一个代表 Cell 实例的 JSON 对象,其中包括以下属性:

  • type:字符串,表示 Cell 实例的类型。
  • value:变量类型,表示 Cell 实例的值。
  • row:整型,表示 Cell 实例所在的行号。
  • column:整型,表示 Cell 实例所在的列号。

代码示例

const cell = new yuka.Cell('string', 'hello', 1, 1);
console.log(cell.toJSON());
// 输出:
// {
//   "type": "string",
//   "value": "hello",
//   "row": 1,
//   "column": 1
// }

注意事项

  • 通过 toJSON 方法转换得到的 JSON 对象,可以通过 JSON.stringify 方法序列化为字符串,再通过 JSON.parse 方法反序列化为对象。
  • 如果 Cell 实例的值是函数,那么 toJSON 方法会将其忽略,即不会被包含在返回的 JSON 对象中。