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

currentSubgoal

概述

currentSubgoalCompositeGoal类中的一个属性,用于表示当前正在执行的子目标。

详细描述

CompositeGoal类是一个组合目标类,用于将多个子目标组合起来形成一个大目标。在执行CompositeGoalActivate()方法时,currentSubgoal属性会被设置为第一个子目标。当子目标执行完成后,currentSubgoal会被设置为下一个子目标,直到所有子目标都执行完毕。

如果CompositeGoal类的Process()方法被调用,则会先检查当前子目标是否已完成。如果未完成,则会继续执行当前子目标。如果已完成,则会将currentSubgoal设置为下一个子目标并执行它。当所有子目标都完成后,CompositeGoalProcess()方法也会返回completed状态。

currentSubgoal是一个Goal类对象,具有Activate()Process()Terminate()方法。它的作用是将子目标集成到CompositeGoal中,以便执行大目标。

使用方法

使用currentSubgoal属性可以获取当前正在执行的子目标。也可以使用它来设置子目标,例如在执行当前子目标时发生错误,可以将currentSubgoal设置为同级或下一级子目标重新执行。

const compositeGoal = new yuka.CompositeGoal(entity, 'attackEnemies', 1);

// 添加子目标
const subGoal1 = new yuka.GoToEntityGoal(entity, enemy1);
const subGoal2 = new yuka.AttackEntityGoal(entity, enemy1);
const subGoal3 = new yuka.GoToEntityGoal(entity, enemy2);
const subGoal4 = new yuka.AttackEntityGoal(entity, enemy2);
compositeGoal.addChildGoal(subGoal1);
compositeGoal.addChildGoal(subGoal2);
compositeGoal.addChildGoal(subGoal3);
compositeGoal.addChildGoal(subGoal4);

// 执行子目标
compositeGoal.activate();

// 获取当前执行的子目标
const currentSubgoal = compositeGoal.currentSubgoal;

// 设置下一个子目标
compositeGoal.currentSubgoal = subGoal3;