2025-12-26 14:50:35 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @esengine/behavior-tree
|
|
|
|
|
|
*
|
|
|
|
|
|
* @zh AI 行为树系统,支持运行时执行和可视化编辑
|
|
|
|
|
|
* @en AI Behavior Tree System with runtime execution and visual editor support
|
|
|
|
|
|
*
|
2025-12-30 20:31:52 +08:00
|
|
|
|
* @zh 此包是通用的行为树实现,可以与任何基于 @esengine/ecs-framework 的引擎集成
|
|
|
|
|
|
* (Cocos Creator、LayaAir、Node.js 等)。
|
2025-12-26 14:50:35 +08:00
|
|
|
|
*
|
2025-12-30 20:31:52 +08:00
|
|
|
|
* @en This package is a generic behavior tree implementation that works with any engine
|
|
|
|
|
|
* based on @esengine/ecs-framework (Cocos Creator, LayaAir, Node.js, etc.).
|
2025-12-26 14:50:35 +08:00
|
|
|
|
*
|
2025-12-30 20:31:52 +08:00
|
|
|
|
* @example
|
2025-12-26 14:50:35 +08:00
|
|
|
|
* ```typescript
|
2025-12-30 20:31:52 +08:00
|
|
|
|
* import { Core, Scene } from '@esengine/ecs-framework';
|
2025-12-26 14:50:35 +08:00
|
|
|
|
* import {
|
2025-12-30 20:31:52 +08:00
|
|
|
|
* BehaviorTreePlugin,
|
|
|
|
|
|
* BehaviorTreeBuilder,
|
|
|
|
|
|
* BehaviorTreeStarter
|
2025-12-26 14:50:35 +08:00
|
|
|
|
* } from '@esengine/behavior-tree';
|
|
|
|
|
|
*
|
2025-12-30 20:31:52 +08:00
|
|
|
|
* // 1. Initialize Core and install plugin
|
|
|
|
|
|
* Core.create();
|
|
|
|
|
|
* const plugin = new BehaviorTreePlugin();
|
|
|
|
|
|
* await Core.installPlugin(plugin);
|
2025-12-26 14:50:35 +08:00
|
|
|
|
*
|
2025-12-30 20:31:52 +08:00
|
|
|
|
* // 2. Create scene and setup behavior tree system
|
|
|
|
|
|
* const scene = new Scene();
|
|
|
|
|
|
* plugin.setupScene(scene);
|
|
|
|
|
|
* Core.setScene(scene);
|
2025-12-26 14:50:35 +08:00
|
|
|
|
*
|
2025-12-30 20:31:52 +08:00
|
|
|
|
* // 3. Build behavior tree
|
|
|
|
|
|
* const tree = BehaviorTreeBuilder.create('MyAI')
|
|
|
|
|
|
* .selector('Root')
|
|
|
|
|
|
* .log('Hello!')
|
|
|
|
|
|
* .end()
|
|
|
|
|
|
* .build();
|
2025-12-26 14:50:35 +08:00
|
|
|
|
*
|
2025-12-30 20:31:52 +08:00
|
|
|
|
* // 4. Start behavior tree on entity
|
|
|
|
|
|
* const entity = scene.createEntity('AIEntity');
|
|
|
|
|
|
* BehaviorTreeStarter.start(entity, tree);
|
|
|
|
|
|
*
|
|
|
|
|
|
* // 5. Run game loop
|
|
|
|
|
|
* setInterval(() => Core.update(0.016), 16);
|
2025-12-26 14:50:35 +08:00
|
|
|
|
* ```
|
|
|
|
|
|
*
|
|
|
|
|
|
* @packageDocumentation
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// Constants
|
|
|
|
|
|
export { BehaviorTreeAssetType } from './constants';
|
|
|
|
|
|
|
|
|
|
|
|
// Types
|
|
|
|
|
|
export * from './Types/TaskStatus';
|
|
|
|
|
|
export type { IBTAssetManager, IBehaviorTreeAssetContent } from './Types/AssetManagerInterface';
|
|
|
|
|
|
|
|
|
|
|
|
// Execution (runtime core)
|
|
|
|
|
|
export * from './execution';
|
|
|
|
|
|
|
|
|
|
|
|
// Utilities
|
|
|
|
|
|
export * from './BehaviorTreeStarter';
|
|
|
|
|
|
export * from './BehaviorTreeBuilder';
|
|
|
|
|
|
|
|
|
|
|
|
// Serialization
|
|
|
|
|
|
export * from './Serialization/NodeTemplates';
|
|
|
|
|
|
export * from './Serialization/BehaviorTreeAsset';
|
|
|
|
|
|
export * from './Serialization/EditorFormatConverter';
|
|
|
|
|
|
export * from './Serialization/BehaviorTreeAssetSerializer';
|
|
|
|
|
|
export * from './Serialization/EditorToBehaviorTreeDataConverter';
|
|
|
|
|
|
|
|
|
|
|
|
// Services
|
|
|
|
|
|
export * from './Services/GlobalBlackboardService';
|
|
|
|
|
|
|
|
|
|
|
|
// Blackboard types (excluding BlackboardValueType which is already exported from TaskStatus)
|
|
|
|
|
|
export type { BlackboardTypeDefinition } from './Blackboard/BlackboardTypes';
|
|
|
|
|
|
export { BlackboardTypes } from './Blackboard/BlackboardTypes';
|
|
|
|
|
|
|
|
|
|
|
|
// Service tokens (using ecs-framework's createServiceToken, not engine-core)
|
|
|
|
|
|
export { BehaviorTreeSystemToken } from './tokens';
|
2025-12-30 20:31:52 +08:00
|
|
|
|
|
|
|
|
|
|
// Plugin
|
|
|
|
|
|
export { BehaviorTreePlugin } from './BehaviorTreePlugin';
|