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

cost

costYukajs库中的一个类,它用于处理代价和成本的计算。

构造函数

constructor()

new Cost()

创建一个新的Cost实例。

实例方法

add(cost)

cost.add(cost: Cost)

将另一个Cost实例的所有成本加到当前实例中。返回当前实例。

subtract(cost)

cost.subtract(cost: Cost)

从当前实例中减去另一个Cost实例的所有成本。返回当前实例。

clear()

cost.clear()

清空当前实例的所有成本。返回当前实例。

clone()

cost.clone()

克隆当前实例,返回一个新的Cost实例,其成本与当前实例相同。

scale(factor)

cost.scale(factor: Number)

按比例缩放当前实例的所有成本。返回当前实例。

getTotalCost()

cost.getTotalCost()

返回当前实例的总成本。

getCost(type)

cost.getCost(type: String)

返回当前实例指定类型的成本。如果该类型的成本不存在,则返回0。

setCost(type, value)

cost.setCost(type: String, value: Number)

设置当前实例指定类型的成本。如果该类型的成本不存在,则添加该类型成本。返回当前实例。

addCost(type, value)

cost.addCost(type: String, value: Number)

将指定类型的成本加到当前实例中。如果该类型的成本不存在,则添加该类型成本。返回当前实例。

subtractCost(type, value)

cost.subtractCost(type: String, value: Number)

从当前实例中减去指定类型的成本。如果该类型的成本不存在,则什么也不做。返回当前实例。

clearCost(type)

cost.clearCost(type: String)

清除当前实例指定类型的成本。如果该类型的成本不存在,则什么也不做。返回当前实例。

hasCost(type)

cost.hasCost(type: String)

返回当前实例是否具有指定类型的成本的布尔值。

示例

const costA = new Cost().setCost('health', 50).setCost('mana', 20);
const costB = new Cost().setCost('health', 10).setCost('stamina', 30);

// 添加costB的成本到costA中
costA.add(costB);
// costA现在包含50点生命值损失,20点法力值消耗,10点生命值损失和30点耐力消耗。

// 从costA中减去costB的成本
costA.subtract(costB);
// costA现在包含40点生命值损失和20点法力值消耗。

// 缩放costA的成本
costA.scale(0.5);
// costA现在包含20点生命值损失和10点法力值消耗。

更详细的信息和使用示例,请参见Yuka的官方文档.