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

resolveReferences

概述

resolveReferences 是 Yuka.js 中 InterposeBehavior 类中的一个方法。该方法用于解析实体的引用并添加到对应的数组中。

参数

该方法不需要任何参数。

返回值

该方法没有返回值。

使用示例

import { InterposeBehavior } from 'yuka';

class MyInterposeBehavior extends InterposeBehavior {

  update( entity, delta ) {
    // ...
  }

  resolveReferences() {
    const entities = this.world.entities;

    // 遍历所有需要链接的实体
    this.interposes.forEach( interpose => {
      const hunter = entities.find( e => e.name === interpose.hunterName );
      const prey = entities.find( e => e.name === interpose.preyName );

      if ( hunter && prey ) {
        // 给猎人和猎物分别添加引用
        interpose.hunter = hunter;
        interpose.prey = prey;
      }
    } );
  }

}

实现细节

resolveReferences 方法会根据现有的实体名称来查找到对应的实体,并将其添加到对应的数组中。如果找不到一个实体,对应的数组就会保持为空。

该方法主要作为 update 方法的前置条件,正确的引用关系是实现行为逻辑的关键,如果引用关系出错,将会导致 update 方法的错误结果。