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

active

描述

active 是 Yuka.js Behavior 类的一个方法,该方法用于激活一个拥有行为的实体(entity)。

语法

active()

返回值

  • 无返回值。

示例

import { Entity, EntityManager, Behavior } from 'yuka';

class SomeBehavior extends Behavior {
  constructor() {
    super();
  }

  // override
  onUpdate() {
    console.log( 'SomeBehavior is active!' );
  }

  // override
  onDeactivate() {
    console.log( 'SomeBehavior is inactive!' );
  }
}

const entityManager = new EntityManager();
const entity = new Entity();

const someBehavior = new SomeBehavior();

entity.setBehavior( someBehavior );
entityManager.add( entity );

someBehavior.isActive; // false

// active 状态
someBehavior.active();
someBehavior.isActive; // true

// 等同于
entity.activeBehavior( someBehavior );
someBehavior.isActive; // true

// inactive 状态
someBehavior.deactive();
someBehavior.isActive; // false

// 等同于
entity.deactiveBehavior( someBehavior );
someBehavior.isActive; // false

实现

Behavior.prototype.active = function () {
  this.isActive = true;

  if ( this.onActivate ) {
    this.onActivate();
  }
};

Behavior.prototype.deactive = function () {
  this.isActive = false;

  if ( this.onDeactivate ) {
    this.onDeactivate();
  }
};

异常

  • 无异常抛出。

参见

许可

MIT