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

fromJSON是Yuka js库中一个从JSON格式数据创建实体的方法。

语法

entity.fromJSON( jsonData );

参数

  • jsonData: 必填项,要转换成实体的JSON格式数据。

返回值

该方法返回当前实体。

用法示例

// 定义实体
class Person {
  constructor( name, age ) {
    this.name = name;
    this.age = age;
  }
}

// 创建JSON格式数据
const jsonData = '{ "name": "Bob", "age": 30 }';

// 使用fromJSON方法将JSON数据转换成Person实体
const person = new Person().fromJSON( jsonData );

console.log( person );
// 输出结果: Person { name: 'Bob', age: 30 }

注意事项

  • JSON数据应该能够被正确的解析成JavaScript对象。
  • 实体属性名与JSON数据的属性名应该一致,以确保能够正确的解析属性值到实体中。
  • 不支持嵌套对象的解析,如果需要解析嵌套对象,需要在实体中定义相应的属性,并手动从JSON数据中解析。