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

描述

该函数用于将ObstacleAvoidanceBehavior中需要引用其他实体的属性转化为实际实体。

执行

ObstacleAvoidanceBehavior.prototype.resolveReferences = function(entities) {
  var self = this;
  entities.forEach(function(entity) {
    if (entity.name === self.obstacle.name) {
      self.obstacle = entity;
    }
  });
};

参数

  • entities:一个实体列表,包含需要被引用的实体。

返回值

该函数没有返回值,但会将ObstacleAvoidanceBehavior中需要引用其他实体的属性转化为实际实体。

使用方法

示例代码

var obstacleAvoidanceBehavior = new Yuka.ObstacleAvoidanceBehavior();
var obstacle = new Yuka.Obstacle(new Yuka.Vector3(1,1,1), 1);
var entities = [obstacle];
obstacleAvoidanceBehavior.obstacle = { name: obstacle.name };
obstacleAvoidanceBehavior.resolveReferences(entities);
console.log(obstacleAvoidanceBehavior.obstacle); // output: Obstacle {position: Vector3, radius: 1}

参数说明

  • 首先创建了一个ObstacleAvoidanceBehavior实例obstacleAvoidanceBehavior,并创建了一个Obstacle实例obstacle。
  • 创建一个实体列表entities,将Obstacle添加进去。
  • 修改obstacleAvoidanceBehavior的obstacle属性,使其引用了obstacle。
  • 调用obstacleAvoidanceBehavior的resolveReferences方法,传入entities作为参数,将obstacleAvoidanceBehavior的obstacle属性引用的名字转化为实际的obstacle实体。
  • 控制台输出obstacleAvoidanceBehavior的obstacle属性,可以看到已经成功地转化为实际的obstacle实体。