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

fromJSON

该方法可从传入的JSON对象创建一个 Vehicle 的实例。

语法

Vehicle.fromJSON(json)

参数

  • json:对象,必需。要创建 Vehicle 实例的JSON对象。

示例

const json = {
  make: "Toyota",
  model: "Camry",
  year: 2020,
  color: "blue"
};

const vehicle = Vehicle.fromJSON(json);

返回值

Vehicle 实例。

异常

  • 如果传入的 JSON 对象不包含必需的属性,将抛出异常。
  • 如果传入的 JSON 对象中属性的值无法转换为正确的类型,将抛出异常。

备注

  • json 对象至少应包含 makemodelyearcolor 的属性。
  • year 属性应该是整数类型。

示例

const json = {
  make: "BMW",
  model: "X5",
  year: 2018,
  color: "silver"
}

const car = Vehicle.fromJSON(json);
console.log(car.make); // "BMW"
console.log(car.model); // "X5"
console.log(car.year); // 2018
console.log(car.color); // "silver"