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

addSubgoal

描述

addSubgoal函数用于向已存在的目标(goal)添加子目标(subgoal)。

语法

think.addSubgoal(goalId, subgoalId);

参数

  • goalId:(必选) 要添加子目标的父目标的ID。
  • subgoalId:(必选) 要添加的子目标的ID。

返回值

  • 无返回值。

示例

// 创建一个目标
think.createGoal('parentGoal', '完成作业');

// 创建两个子目标
think.createSubgoal('childGoal1', '读完书');
think.createSubgoal('childGoal2', '写完报告');

// 向父目标添加子目标
think.addSubgoal('parentGoal', 'childGoal1');
think.addSubgoal('parentGoal', 'childGoal2');

异常

  • 如果传递的goalIdsubgoalId参数无效,则会抛出异常。

应用场景

  • 可以通过添加子目标的方式,拆分大目标为更小的子目标,有利于目标管理和进度跟踪。

注意事项

  • 添加子目标的父目标必须已存在,否则会抛出异常。
  • 添加的子目标必须是未添加到任何父目标下的,否则会抛出异常。
  • 避免循环引用,即子目标不能成为自己或其祖先目标的父目标。