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 方法用于将 ObstacleAvoidanceBehavior 对象转换为 JSON 格式的字符串。

语法

obstacleBehavior.toJSON();

返回值

返回 ObstacleAvoidanceBehavior 对象的 JSON 格式字符串。

示例

const obstacleBehavior = new Yuka.ObstacleAvoidanceBehavior();
const json = obstacleBehavior.toJSON();

console.log(json); // {"type":"ObstacleAvoidanceBehavior","weight":1,"radius":3,"maxDistance":10}

属性列表

  • type:字符串类型,表示对象类型,值为 "ObstacleAvoidanceBehavior"
  • weight:数字类型,表示对象的权重。
  • radius:数字类型,表示对象的避障半径。
  • maxDistance:数字类型,表示对象的最大避障距离。

代码实现

ObstacleAvoidanceBehavior.prototype.toJSON = function () {
    return JSON.stringify( {
        type: this.constructor.name,
        weight: this.weight,
        radius: this.radius,
        maxDistance: this.maxDistance
    } );
};