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

currentState

Yuka.js的StateMachine对象提供了currentState属性,该属性用于获取当前状态机处于的状态。

语法

stateMachine.currentState;

返回值

当前状态机所处状态的状态实例。

示例

const stateMachine = new YUKA.StateMachine();
stateMachine.addState('idle', new IdleState());
stateMachine.addState('move', new MoveState());
stateMachine.changeToState('idle');
console.log(stateMachine.currentState); // 输出: IdleState {}
stateMachine.changeToState('move');
console.log(stateMachine.currentState); // 输出: MoveState {}

在上面的示例中,我们创建了一个新的StateMachine对象,并为其添加了两个状态(idle和move)的实例。我们然后切换到空闲状态,并输出了当前的状态。接下来,我们切换到移动状态,并再次输出当前状态。

注意,输出的状态都是作为状态实例返回的,而不仅仅是状态名称。因此,你可以访问该状态的任何属性和方法。