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对象转换为一个State实例。该函数应该在实例化State对象之前使用。

用法

const stateData = { /* JSON数据 */ };
const state = State.fromJSON(stateData);

参数

  • stateData(Object):需要转换为State对象的JSON数据。

返回值

  • (State):一个新创建的State对象。

示例

const stateData = {
  name: 'Bruce Wayne',
  age: 35,
  location: {
    x: 11.23,
    y: 8.12,
    z: 2.46
  }
};

const state = State.fromJSON(stateData);
console.log(state.name); // Bruce Wayne
console.log(state.age); // 35
console.log(state.location.x); // 11.23

注意事项

  • JSON数据必须与State对象的属性相匹配,否则会导致转换失败。
  • State.fromJSON方法目前仅支持一层JSON数据转换,即如果stateData中包含嵌套的对象或数组,这些对象或数组将无法转换。