@esengine/behavior-tree 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2012 @@
1
+ import * as _esengine_ecs_framework from '@esengine/ecs-framework';
2
+ import { Component, IService, Entity, EntitySystem, ServiceContainer } from '@esengine/ecs-framework';
3
+
4
+ /**
5
+ * Behavior Tree Constants
6
+ * 行为树常量
7
+ */
8
+ declare const BehaviorTreeAssetType: "behavior-tree";
9
+
10
+ /**
11
+ * 任务执行状态
12
+ */
13
+ declare enum TaskStatus {
14
+ /** 无效状态 - 节点未初始化或已被重置 */
15
+ Invalid = 0,
16
+ /** 成功 - 节点执行成功完成 */
17
+ Success = 1,
18
+ /** 失败 - 节点执行失败 */
19
+ Failure = 2,
20
+ /** 运行中 - 节点正在执行,需要在后续帧继续 */
21
+ Running = 3
22
+ }
23
+ /**
24
+ * 内置节点类型常量
25
+ */
26
+ declare const NodeType: {
27
+ /** 根节点 - 行为树的起始节点 */
28
+ readonly Root: "root";
29
+ /** 复合节点 - 有多个子节点 */
30
+ readonly Composite: "composite";
31
+ /** 装饰器节点 - 有一个子节点 */
32
+ readonly Decorator: "decorator";
33
+ /** 动作节点 - 叶子节点 */
34
+ readonly Action: "action";
35
+ /** 条件节点 - 叶子节点 */
36
+ readonly Condition: "condition";
37
+ };
38
+ /**
39
+ * 节点类型(支持自定义扩展)
40
+ *
41
+ * 使用内置类型或自定义字符串
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * // 使用内置类型
46
+ * type: NodeType.Action
47
+ *
48
+ * // 使用自定义类型
49
+ * type: 'custom-behavior'
50
+ * ```
51
+ */
52
+ type NodeType = typeof NodeType[keyof typeof NodeType] | string;
53
+ /**
54
+ * 复合节点类型
55
+ */
56
+ declare enum CompositeType {
57
+ /** 序列 - 按顺序执行,全部成功才成功 */
58
+ Sequence = "sequence",
59
+ /** 选择 - 按顺序执行,任一成功则成功 */
60
+ Selector = "selector",
61
+ /** 并行 - 同时执行所有子节点 */
62
+ Parallel = "parallel",
63
+ /** 并行选择 - 并行执行,任一成功则成功 */
64
+ ParallelSelector = "parallel-selector",
65
+ /** 随机序列 - 随机顺序执行序列 */
66
+ RandomSequence = "random-sequence",
67
+ /** 随机选择 - 随机顺序执行选择 */
68
+ RandomSelector = "random-selector"
69
+ }
70
+ /**
71
+ * 装饰器节点类型
72
+ */
73
+ declare enum DecoratorType {
74
+ /** 反转 - 反转子节点结果 */
75
+ Inverter = "inverter",
76
+ /** 重复 - 重复执行子节点 */
77
+ Repeater = "repeater",
78
+ /** 直到成功 - 重复直到成功 */
79
+ UntilSuccess = "until-success",
80
+ /** 直到失败 - 重复直到失败 */
81
+ UntilFail = "until-fail",
82
+ /** 总是成功 - 无论子节点结果都返回成功 */
83
+ AlwaysSucceed = "always-succeed",
84
+ /** 总是失败 - 无论子节点结果都返回失败 */
85
+ AlwaysFail = "always-fail",
86
+ /** 条件装饰器 - 基于条件执行子节点 */
87
+ Conditional = "conditional",
88
+ /** 冷却 - 冷却时间内阻止执行 */
89
+ Cooldown = "cooldown",
90
+ /** 超时 - 超时则返回失败 */
91
+ Timeout = "timeout"
92
+ }
93
+ /**
94
+ * 中止类型
95
+ *
96
+ * 用于动态优先级和条件重新评估
97
+ */
98
+ declare enum AbortType {
99
+ /** 无 - 不中止任何节点 */
100
+ None = "none",
101
+ /** 自身 - 条件变化时可以中止自身的执行 */
102
+ Self = "self",
103
+ /** 低优先级 - 条件满足时可以中止低优先级的兄弟节点 */
104
+ LowerPriority = "lower-priority",
105
+ /** 两者 - 可以中止自身和低优先级节点 */
106
+ Both = "both"
107
+ }
108
+ /**
109
+ * 黑板变量类型
110
+ */
111
+ declare enum BlackboardValueType$1 {
112
+ String = "string",
113
+ Number = "number",
114
+ Boolean = "boolean",
115
+ Vector2 = "vector2",
116
+ Vector3 = "vector3",
117
+ Object = "object",
118
+ Array = "array"
119
+ }
120
+ /**
121
+ * 黑板变量定义
122
+ */
123
+ interface BlackboardVariable {
124
+ name: string;
125
+ type: BlackboardValueType$1;
126
+ value: any;
127
+ readonly?: boolean;
128
+ description?: string;
129
+ }
130
+
131
+ /**
132
+ * 行为树节点定义(纯数据结构)
133
+ *
134
+ * 不依赖Entity,可以被多个实例共享
135
+ */
136
+ interface BehaviorNodeData {
137
+ /** 节点唯一ID */
138
+ id: string;
139
+ /** 节点名称(用于调试) */
140
+ name: string;
141
+ /** 节点类型 */
142
+ nodeType: NodeType;
143
+ /** 节点实现类型(对应Component类名) */
144
+ implementationType: string;
145
+ /** 子节点ID列表 */
146
+ children?: string[];
147
+ /** 节点特定配置数据 */
148
+ config: Record<string, any>;
149
+ /** 属性到黑板变量的绑定映射 */
150
+ bindings?: Record<string, string>;
151
+ /** 中止类型(条件装饰器使用) */
152
+ abortType?: AbortType;
153
+ }
154
+ /**
155
+ * 行为树定义(可共享的Asset)
156
+ */
157
+ interface BehaviorTreeData {
158
+ /** 树ID */
159
+ id: string;
160
+ /** 树名称 */
161
+ name: string;
162
+ /** 根节点ID */
163
+ rootNodeId: string;
164
+ /** 所有节点(扁平化存储) */
165
+ nodes: Map<string, BehaviorNodeData>;
166
+ /** 黑板变量定义 */
167
+ blackboardVariables?: Map<string, any>;
168
+ }
169
+ /**
170
+ * 节点运行时状态
171
+ *
172
+ * 每个BehaviorTreeRuntimeComponent实例独立维护
173
+ */
174
+ interface NodeRuntimeState {
175
+ /** 当前执行状态 */
176
+ status: TaskStatus;
177
+ /** 当前执行的子节点索引(复合节点使用) */
178
+ currentChildIndex: number;
179
+ /** 执行顺序号(用于调试和可视化) */
180
+ executionOrder?: number;
181
+ /** 开始执行时间(某些节点需要) */
182
+ startTime?: number;
183
+ /** 上次执行时间(冷却节点使用) */
184
+ lastExecutionTime?: number;
185
+ /** 当前重复次数(重复节点使用) */
186
+ repeatCount?: number;
187
+ /** 缓存的结果(某些条件节点使用) */
188
+ cachedResult?: any;
189
+ /** 洗牌后的索引(随机节点使用) */
190
+ shuffledIndices?: number[];
191
+ /** 是否被中止 */
192
+ isAborted?: boolean;
193
+ /** 上次条件评估结果(条件装饰器使用) */
194
+ lastConditionResult?: boolean;
195
+ /** 正在观察的黑板键(条件装饰器使用) */
196
+ observedKeys?: string[];
197
+ }
198
+ /**
199
+ * 创建默认的运行时状态
200
+ */
201
+ declare function createDefaultRuntimeState(): NodeRuntimeState;
202
+
203
+ /**
204
+ * @zh 资产管理器接口(可选依赖)
205
+ * @en Asset manager interface (optional dependency)
206
+ *
207
+ * @zh 行为树系统的可选资产管理器接口。
208
+ * 当与 ESEngine 的 asset-system 集成时,传入 IAssetManager 实例。
209
+ * 不使用 ESEngine 时,可以直接使用 BehaviorTreeAssetManager.loadFromEditorJSON()。
210
+ *
211
+ * @en Optional asset manager interface for behavior tree system.
212
+ * When integrating with ESEngine's asset-system, pass an IAssetManager instance.
213
+ * When not using ESEngine, use BehaviorTreeAssetManager.loadFromEditorJSON() directly.
214
+ */
215
+
216
+ /**
217
+ * @zh 行为树资产内容
218
+ * @en Behavior tree asset content
219
+ */
220
+ interface IBehaviorTreeAssetContent {
221
+ /** @zh 行为树数据 @en Behavior tree data */
222
+ data: BehaviorTreeData;
223
+ /** @zh 文件路径 @en File path */
224
+ path: string;
225
+ }
226
+ /**
227
+ * @zh 简化的资产管理器接口
228
+ * @en Simplified asset manager interface
229
+ *
230
+ * @zh 这是行为树系统需要的最小资产管理器接口。
231
+ * ESEngine 的 IAssetManager 实现此接口。
232
+ * 其他引擎可以提供自己的实现。
233
+ *
234
+ * @en This is the minimal asset manager interface required by the behavior tree system.
235
+ * ESEngine's IAssetManager implements this interface.
236
+ * Other engines can provide their own implementation.
237
+ */
238
+ interface IBTAssetManager {
239
+ /**
240
+ * @zh 通过 GUID 加载资产
241
+ * @en Load asset by GUID
242
+ */
243
+ loadAsset(guid: string): Promise<{
244
+ asset: IBehaviorTreeAssetContent | null;
245
+ } | null>;
246
+ /**
247
+ * @zh 通过 GUID 获取已加载的资产
248
+ * @en Get loaded asset by GUID
249
+ */
250
+ getAsset<T = IBehaviorTreeAssetContent>(guid: string): T | null;
251
+ }
252
+
253
+ /**
254
+ * 黑板变化监听器
255
+ */
256
+ type BlackboardChangeListener = (key: string, newValue: any, oldValue: any) => void;
257
+ /**
258
+ * 行为树运行时组件
259
+ *
260
+ * 挂载到游戏Entity上,引用共享的BehaviorTreeData
261
+ * 维护该Entity独立的运行时状态
262
+ */
263
+ declare class BehaviorTreeRuntimeComponent extends Component {
264
+ /**
265
+ * 引用的行为树资产ID(可序列化)
266
+ */
267
+ treeAssetId: string;
268
+ /**
269
+ * 是否自动启动
270
+ */
271
+ autoStart: boolean;
272
+ /**
273
+ * 是否正在运行
274
+ */
275
+ isRunning: boolean;
276
+ /**
277
+ * 节点运行时状态(每个节点独立)
278
+ * 不序列化,每次加载时重新初始化
279
+ */
280
+ private nodeStates;
281
+ /**
282
+ * 黑板数据(该Entity独立的数据)
283
+ * 不序列化,通过初始化设置
284
+ */
285
+ private blackboard;
286
+ /**
287
+ * 黑板观察者列表
288
+ */
289
+ private blackboardObservers;
290
+ /**
291
+ * 当前激活的节点ID列表(用于调试)
292
+ */
293
+ activeNodeIds: Set<string>;
294
+ /**
295
+ * 标记是否需要在下一个tick重置状态
296
+ */
297
+ needsReset: boolean;
298
+ /**
299
+ * 需要中止的节点ID列表
300
+ */
301
+ nodesToAbort: Set<string>;
302
+ /**
303
+ * 执行顺序计数器(用于调试和可视化)
304
+ */
305
+ executionOrderCounter: number;
306
+ /**
307
+ * 获取节点运行时状态
308
+ */
309
+ getNodeState(nodeId: string): NodeRuntimeState;
310
+ /**
311
+ * 重置节点状态
312
+ */
313
+ resetNodeState(nodeId: string): void;
314
+ /**
315
+ * 重置所有节点状态
316
+ */
317
+ resetAllStates(): void;
318
+ /**
319
+ * 获取黑板值
320
+ */
321
+ getBlackboardValue<T = any>(key: string): T | undefined;
322
+ /**
323
+ * 设置黑板值
324
+ */
325
+ setBlackboardValue(key: string, value: any): void;
326
+ /**
327
+ * 检查黑板是否有某个键
328
+ */
329
+ hasBlackboardKey(key: string): boolean;
330
+ /**
331
+ * 初始化黑板(从树定义的默认值)
332
+ */
333
+ initializeBlackboard(variables?: Map<string, any>): void;
334
+ /**
335
+ * 清空黑板
336
+ */
337
+ clearBlackboard(): void;
338
+ /**
339
+ * 启动行为树
340
+ */
341
+ start(): void;
342
+ /**
343
+ * 停止行为树
344
+ */
345
+ stop(): void;
346
+ /**
347
+ * 暂停行为树
348
+ */
349
+ pause(): void;
350
+ /**
351
+ * 恢复行为树
352
+ */
353
+ resume(): void;
354
+ /**
355
+ * 注册黑板观察者
356
+ */
357
+ observeBlackboard(nodeId: string, keys: string[], callback: BlackboardChangeListener): void;
358
+ /**
359
+ * 取消注册黑板观察者
360
+ */
361
+ unobserveBlackboard(nodeId: string): void;
362
+ /**
363
+ * 通知黑板变化
364
+ */
365
+ private notifyBlackboardChange;
366
+ /**
367
+ * 请求中止节点
368
+ */
369
+ requestAbort(nodeId: string): void;
370
+ /**
371
+ * 检查节点是否需要中止
372
+ */
373
+ shouldAbort(nodeId: string): boolean;
374
+ /**
375
+ * 清除中止请求
376
+ */
377
+ clearAbortRequest(nodeId: string): void;
378
+ /**
379
+ * 清除所有中止请求
380
+ */
381
+ clearAllAbortRequests(): void;
382
+ }
383
+
384
+ /**
385
+ * 行为树资产管理器(服务)
386
+ *
387
+ * 管理所有共享的BehaviorTreeData
388
+ * 多个实例可以引用同一份数据
389
+ *
390
+ * 使用方式:
391
+ * ```typescript
392
+ * // 注册服务
393
+ * Core.services.registerSingleton(BehaviorTreeAssetManager);
394
+ *
395
+ * // 使用服务
396
+ * const assetManager = Core.services.resolve(BehaviorTreeAssetManager);
397
+ * ```
398
+ */
399
+ declare class BehaviorTreeAssetManager implements IService {
400
+ /**
401
+ * 已加载的行为树资产
402
+ */
403
+ private assets;
404
+ /**
405
+ * 加载行为树资产
406
+ */
407
+ loadAsset(asset: BehaviorTreeData): void;
408
+ /**
409
+ * 从编辑器 JSON 格式加载行为树资产
410
+ *
411
+ * @param json 编辑器导出的 JSON 字符串
412
+ * @returns 加载的行为树数据
413
+ *
414
+ * @example
415
+ * ```typescript
416
+ * const assetManager = Core.services.resolve(BehaviorTreeAssetManager);
417
+ * const jsonContent = await readFile('path/to/tree.btree');
418
+ * const treeData = assetManager.loadFromEditorJSON(jsonContent);
419
+ * ```
420
+ */
421
+ loadFromEditorJSON(json: string): BehaviorTreeData;
422
+ /**
423
+ * 批量加载多个行为树资产(从编辑器JSON)
424
+ *
425
+ * @param jsonDataList JSON字符串列表
426
+ * @returns 成功加载的资产数量
427
+ */
428
+ loadMultipleFromEditorJSON(jsonDataList: string[]): number;
429
+ /**
430
+ * 获取行为树资产
431
+ */
432
+ getAsset(assetId: string): BehaviorTreeData | undefined;
433
+ /**
434
+ * 检查资产是否存在
435
+ */
436
+ hasAsset(assetId: string): boolean;
437
+ /**
438
+ * 卸载行为树资产
439
+ */
440
+ unloadAsset(assetId: string): boolean;
441
+ /**
442
+ * 清空所有资产
443
+ */
444
+ clearAll(): void;
445
+ /**
446
+ * 获取已加载资产数量
447
+ */
448
+ getAssetCount(): number;
449
+ /**
450
+ * 获取所有资产ID
451
+ */
452
+ getAllAssetIds(): string[];
453
+ /**
454
+ * 释放资源(实现IService接口)
455
+ */
456
+ dispose(): void;
457
+ }
458
+
459
+ /**
460
+ * 节点执行上下文
461
+ *
462
+ * 包含执行节点所需的所有信息
463
+ */
464
+ interface NodeExecutionContext {
465
+ /** 游戏Entity(行为树宿主) */
466
+ readonly entity: Entity;
467
+ /** 节点数据 */
468
+ readonly nodeData: BehaviorNodeData;
469
+ /** 节点运行时状态 */
470
+ readonly state: NodeRuntimeState;
471
+ /** 运行时组件(访问黑板等) */
472
+ readonly runtime: BehaviorTreeRuntimeComponent;
473
+ /** 行为树数据(访问子节点等) */
474
+ readonly treeData: BehaviorTreeData;
475
+ /** 当前帧增量时间 */
476
+ readonly deltaTime: number;
477
+ /** 总时间 */
478
+ readonly totalTime: number;
479
+ /** 执行子节点 */
480
+ executeChild(childId: string): TaskStatus;
481
+ }
482
+ /**
483
+ * 节点执行器接口
484
+ *
485
+ * 所有节点类型都需要实现对应的执行器
486
+ * 执行器是无状态的,状态存储在NodeRuntimeState中
487
+ */
488
+ interface INodeExecutor {
489
+ /**
490
+ * 执行节点逻辑
491
+ *
492
+ * @param context 执行上下文
493
+ * @returns 执行结果状态
494
+ */
495
+ execute(context: NodeExecutionContext): TaskStatus;
496
+ /**
497
+ * 重置节点状态(可选)
498
+ *
499
+ * 当节点完成或被中断时调用
500
+ */
501
+ reset?(context: NodeExecutionContext): void;
502
+ }
503
+ /**
504
+ * 绑定辅助工具
505
+ *
506
+ * 处理配置属性的黑板绑定
507
+ */
508
+ declare class BindingHelper {
509
+ /**
510
+ * 获取配置值(考虑黑板绑定)
511
+ *
512
+ * @param context 执行上下文
513
+ * @param configKey 配置键名
514
+ * @param defaultValue 默认值
515
+ * @returns 解析后的值
516
+ */
517
+ static getValue<T = any>(context: NodeExecutionContext, configKey: string, defaultValue?: T): T;
518
+ /**
519
+ * 检查配置是否绑定到黑板变量
520
+ */
521
+ static hasBinding(context: NodeExecutionContext, configKey: string): boolean;
522
+ /**
523
+ * 获取绑定的黑板变量名
524
+ */
525
+ static getBindingKey(context: NodeExecutionContext, configKey: string): string | undefined;
526
+ }
527
+ /**
528
+ * 节点执行器注册表
529
+ *
530
+ * 管理所有节点类型的执行器
531
+ */
532
+ declare class NodeExecutorRegistry {
533
+ private executors;
534
+ /**
535
+ * 注册执行器
536
+ *
537
+ * @param implementationType 节点实现类型(对应BehaviorNodeData.implementationType)
538
+ * @param executor 执行器实例
539
+ */
540
+ register(implementationType: string, executor: INodeExecutor): void;
541
+ /**
542
+ * 获取执行器
543
+ */
544
+ get(implementationType: string): INodeExecutor | undefined;
545
+ /**
546
+ * 检查是否有执行器
547
+ */
548
+ has(implementationType: string): boolean;
549
+ /**
550
+ * 注销执行器
551
+ */
552
+ unregister(implementationType: string): boolean;
553
+ /**
554
+ * 清空所有执行器
555
+ */
556
+ clear(): void;
557
+ }
558
+
559
+ /**
560
+ * 根节点执行器
561
+ *
562
+ * 行为树的入口节点,执行其唯一的子节点
563
+ */
564
+ declare class RootExecutor implements INodeExecutor {
565
+ execute(context: NodeExecutionContext): TaskStatus;
566
+ reset(_context: NodeExecutionContext): void;
567
+ }
568
+
569
+ /**
570
+ * 序列节点执行器
571
+ *
572
+ * 按顺序执行子节点,全部成功才成功,任一失败则失败
573
+ */
574
+ declare class SequenceExecutor implements INodeExecutor {
575
+ execute(context: NodeExecutionContext): TaskStatus;
576
+ reset(context: NodeExecutionContext): void;
577
+ }
578
+
579
+ /**
580
+ * 选择器节点执行器
581
+ *
582
+ * 按顺序执行子节点,任一成功则成功,全部失败才失败
583
+ */
584
+ declare class SelectorExecutor implements INodeExecutor {
585
+ execute(context: NodeExecutionContext): TaskStatus;
586
+ reset(context: NodeExecutionContext): void;
587
+ }
588
+
589
+ /**
590
+ * 并行节点执行器
591
+ *
592
+ * 同时执行所有子节点
593
+ */
594
+ declare class ParallelExecutor implements INodeExecutor {
595
+ execute(context: NodeExecutionContext): TaskStatus;
596
+ private stopAllChildren;
597
+ reset(context: NodeExecutionContext): void;
598
+ }
599
+
600
+ /**
601
+ * 并行选择器执行器
602
+ *
603
+ * 并行执行子节点,任一成功则成功
604
+ */
605
+ declare class ParallelSelectorExecutor implements INodeExecutor {
606
+ execute(context: NodeExecutionContext): TaskStatus;
607
+ private stopAllChildren;
608
+ reset(context: NodeExecutionContext): void;
609
+ }
610
+
611
+ /**
612
+ * 随机序列执行器
613
+ *
614
+ * 随机顺序执行子节点序列,全部成功才成功
615
+ */
616
+ declare class RandomSequenceExecutor implements INodeExecutor {
617
+ execute(context: NodeExecutionContext): TaskStatus;
618
+ private shuffleIndices;
619
+ reset(context: NodeExecutionContext): void;
620
+ }
621
+
622
+ /**
623
+ * 随机选择器执行器
624
+ *
625
+ * 随机顺序执行子节点,任一成功则成功
626
+ */
627
+ declare class RandomSelectorExecutor implements INodeExecutor {
628
+ execute(context: NodeExecutionContext): TaskStatus;
629
+ private shuffleIndices;
630
+ reset(context: NodeExecutionContext): void;
631
+ }
632
+
633
+ /**
634
+ * 反转装饰器执行器
635
+ *
636
+ * 反转子节点的执行结果
637
+ */
638
+ declare class InverterExecutor implements INodeExecutor {
639
+ execute(context: NodeExecutionContext): TaskStatus;
640
+ reset(context: NodeExecutionContext): void;
641
+ }
642
+
643
+ /**
644
+ * 重复装饰器执行器
645
+ *
646
+ * 重复执行子节点指定次数
647
+ */
648
+ declare class RepeaterExecutor implements INodeExecutor {
649
+ execute(context: NodeExecutionContext): TaskStatus;
650
+ reset(context: NodeExecutionContext): void;
651
+ }
652
+
653
+ /**
654
+ * 总是成功装饰器执行器
655
+ *
656
+ * 无论子节点结果如何都返回成功
657
+ */
658
+ declare class AlwaysSucceedExecutor implements INodeExecutor {
659
+ execute(context: NodeExecutionContext): TaskStatus;
660
+ reset(context: NodeExecutionContext): void;
661
+ }
662
+
663
+ /**
664
+ * 总是失败装饰器执行器
665
+ *
666
+ * 无论子节点结果如何都返回失败
667
+ */
668
+ declare class AlwaysFailExecutor implements INodeExecutor {
669
+ execute(context: NodeExecutionContext): TaskStatus;
670
+ reset(context: NodeExecutionContext): void;
671
+ }
672
+
673
+ /**
674
+ * 直到成功装饰器执行器
675
+ *
676
+ * 重复执行子节点直到成功
677
+ */
678
+ declare class UntilSuccessExecutor implements INodeExecutor {
679
+ execute(context: NodeExecutionContext): TaskStatus;
680
+ reset(context: NodeExecutionContext): void;
681
+ }
682
+
683
+ /**
684
+ * 直到失败装饰器执行器
685
+ *
686
+ * 重复执行子节点直到失败
687
+ */
688
+ declare class UntilFailExecutor implements INodeExecutor {
689
+ execute(context: NodeExecutionContext): TaskStatus;
690
+ reset(context: NodeExecutionContext): void;
691
+ }
692
+
693
+ /**
694
+ * 条件装饰器执行器
695
+ *
696
+ * 根据条件决定是否执行子节点
697
+ * 支持动态优先级和中止机制
698
+ */
699
+ declare class ConditionalExecutor implements INodeExecutor {
700
+ execute(context: NodeExecutionContext): TaskStatus;
701
+ private evaluateCondition;
702
+ /**
703
+ * 设置黑板观察者
704
+ */
705
+ private setupObserver;
706
+ /**
707
+ * 处理条件变为true
708
+ */
709
+ private handleConditionBecameTrue;
710
+ /**
711
+ * 处理条件变为false
712
+ */
713
+ private handleConditionBecameFalse;
714
+ /**
715
+ * 请求中止低优先级节点
716
+ */
717
+ private requestAbortLowerPriority;
718
+ reset(context: NodeExecutionContext): void;
719
+ }
720
+
721
+ /**
722
+ * 冷却装饰器执行器
723
+ *
724
+ * 子节点执行成功后进入冷却时间
725
+ */
726
+ declare class CooldownExecutor implements INodeExecutor {
727
+ execute(context: NodeExecutionContext): TaskStatus;
728
+ reset(context: NodeExecutionContext): void;
729
+ }
730
+
731
+ /**
732
+ * 超时装饰器执行器
733
+ *
734
+ * 限制子节点的执行时间
735
+ */
736
+ declare class TimeoutExecutor implements INodeExecutor {
737
+ execute(context: NodeExecutionContext): TaskStatus;
738
+ reset(context: NodeExecutionContext): void;
739
+ }
740
+
741
+ /**
742
+ * Service执行接口
743
+ */
744
+ interface IServiceExecutor {
745
+ /**
746
+ * Service开始执行
747
+ */
748
+ onServiceStart?(context: NodeExecutionContext): void;
749
+ /**
750
+ * Service每帧更新
751
+ */
752
+ onServiceTick(context: NodeExecutionContext): void;
753
+ /**
754
+ * Service结束执行
755
+ */
756
+ onServiceEnd?(context: NodeExecutionContext): void;
757
+ }
758
+ /**
759
+ * Service注册表
760
+ */
761
+ declare class ServiceRegistry {
762
+ private static services;
763
+ static register(name: string, service: IServiceExecutor): void;
764
+ static get(name: string): IServiceExecutor | undefined;
765
+ static has(name: string): boolean;
766
+ static unregister(name: string): boolean;
767
+ }
768
+ /**
769
+ * Service装饰器执行器
770
+ *
771
+ * 在子节点执行期间持续运行后台逻辑
772
+ */
773
+ declare class ServiceDecorator implements INodeExecutor {
774
+ execute(context: NodeExecutionContext): TaskStatus;
775
+ reset(context: NodeExecutionContext): void;
776
+ }
777
+
778
+ /**
779
+ * 等待动作执行器
780
+ *
781
+ * 等待指定时间后返回成功
782
+ */
783
+ declare class WaitAction implements INodeExecutor {
784
+ execute(context: NodeExecutionContext): TaskStatus;
785
+ reset(context: NodeExecutionContext): void;
786
+ }
787
+
788
+ /**
789
+ * 日志动作执行器
790
+ *
791
+ * 输出日志信息
792
+ */
793
+ declare class LogAction implements INodeExecutor {
794
+ execute(context: NodeExecutionContext): TaskStatus;
795
+ private replaceBlackboardVariables;
796
+ private log;
797
+ }
798
+
799
+ /**
800
+ * 设置黑板值动作执行器
801
+ *
802
+ * 设置黑板中的变量值
803
+ */
804
+ declare class SetBlackboardValue implements INodeExecutor {
805
+ execute(context: NodeExecutionContext): TaskStatus;
806
+ }
807
+
808
+ /**
809
+ * 修改黑板值动作执行器
810
+ *
811
+ * 对黑板中的数值进行运算
812
+ */
813
+ declare class ModifyBlackboardValue implements INodeExecutor {
814
+ execute(context: NodeExecutionContext): TaskStatus;
815
+ }
816
+
817
+ /**
818
+ * 执行动作执行器
819
+ *
820
+ * 执行自定义动作逻辑
821
+ */
822
+ declare class ExecuteAction implements INodeExecutor {
823
+ execute(context: NodeExecutionContext): TaskStatus;
824
+ }
825
+
826
+ /**
827
+ * SubTree执行器
828
+ *
829
+ * 引用并执行其他行为树,实现模块化和复用
830
+ */
831
+ declare class SubTreeExecutor implements INodeExecutor {
832
+ private assetManager;
833
+ private getAssetManager;
834
+ execute(context: NodeExecutionContext): TaskStatus;
835
+ private executeSubTreeNode;
836
+ reset(context: NodeExecutionContext): void;
837
+ }
838
+
839
+ /**
840
+ * 黑板比较条件执行器
841
+ *
842
+ * 比较黑板中的值
843
+ */
844
+ declare class BlackboardCompare implements INodeExecutor {
845
+ execute(context: NodeExecutionContext): TaskStatus;
846
+ private compare;
847
+ }
848
+
849
+ /**
850
+ * 黑板存在检查条件执行器
851
+ *
852
+ * 检查黑板中是否存在指定的键
853
+ */
854
+ declare class BlackboardExists implements INodeExecutor {
855
+ execute(context: NodeExecutionContext): TaskStatus;
856
+ }
857
+
858
+ /**
859
+ * 随机概率条件执行器
860
+ *
861
+ * 根据概率返回成功或失败
862
+ */
863
+ declare class RandomProbability implements INodeExecutor {
864
+ execute(context: NodeExecutionContext): TaskStatus;
865
+ }
866
+
867
+ /**
868
+ * 执行条件执行器
869
+ *
870
+ * 执行自定义条件逻辑
871
+ */
872
+ declare class ExecuteCondition implements INodeExecutor {
873
+ execute(context: NodeExecutionContext): TaskStatus;
874
+ }
875
+
876
+ /**
877
+ * 行为树执行系统
878
+ *
879
+ * 统一处理所有行为树的执行
880
+ */
881
+ declare class BehaviorTreeExecutionSystem extends EntitySystem {
882
+ private btAssetManager;
883
+ private executorRegistry;
884
+ private _services;
885
+ /** 引用外部资产管理器(可选,由外部模块设置) */
886
+ private _assetManager;
887
+ /** 已警告过的缺失资产,避免重复警告 */
888
+ private _warnedMissingAssets;
889
+ constructor(services?: ServiceContainer);
890
+ /**
891
+ * @zh 设置外部资产管理器引用(可选)
892
+ * @en Set external asset manager reference (optional)
893
+ *
894
+ * @zh 当与 ESEngine 集成时,由 BehaviorTreeRuntimeModule 调用。
895
+ * 不使用 ESEngine 时,可以不调用此方法,
896
+ * 直接使用 BehaviorTreeAssetManager.loadFromEditorJSON() 加载资产。
897
+ *
898
+ * @en Called by BehaviorTreeRuntimeModule when integrating with ESEngine.
899
+ * When not using ESEngine, you can skip this and use
900
+ * BehaviorTreeAssetManager.loadFromEditorJSON() to load assets directly.
901
+ */
902
+ setAssetManager(assetManager: IBTAssetManager | null): void;
903
+ /**
904
+ * 启动所有 autoStart 的行为树(用于预览模式)
905
+ * Start all autoStart behavior trees (for preview mode)
906
+ *
907
+ * 由于编辑器模式下系统默认禁用,实体添加时 onAdded 不会处理自动启动。
908
+ * 预览开始时需要手动调用此方法来启动所有需要自动启动的行为树。
909
+ */
910
+ startAllAutoStartTrees(): void;
911
+ /**
912
+ * 当实体添加到系统时,处理自动启动
913
+ * Handle auto-start when entity is added to system
914
+ */
915
+ protected onAdded(entity: Entity): void;
916
+ /**
917
+ * 确保行为树资产已加载
918
+ * Ensure behavior tree asset is loaded
919
+ */
920
+ private ensureAssetLoaded;
921
+ private getBTAssetManager;
922
+ /**
923
+ * 获取行为树数据
924
+ * Get behavior tree data from AssetManager or BehaviorTreeAssetManager
925
+ *
926
+ * 优先从 AssetManager 获取(新方式),如果没有再从 BehaviorTreeAssetManager 获取(兼容旧方式)
927
+ */
928
+ private getTreeData;
929
+ /**
930
+ * 注册所有执行器(包括内置和插件提供的)
931
+ */
932
+ private registerBuiltInExecutors;
933
+ /**
934
+ * 获取执行器注册表
935
+ */
936
+ getExecutorRegistry(): NodeExecutorRegistry;
937
+ protected process(entities: readonly Entity[]): void;
938
+ /**
939
+ * 执行整个行为树
940
+ */
941
+ private executeTree;
942
+ /**
943
+ * 执行单个节点
944
+ */
945
+ private executeNode;
946
+ /**
947
+ * 创建执行上下文
948
+ */
949
+ private createContext;
950
+ /**
951
+ * 执行子节点列表
952
+ */
953
+ executeChildren(context: NodeExecutionContext, childIndices?: number[]): TaskStatus[];
954
+ }
955
+
956
+ /**
957
+ * 配置参数定义
958
+ */
959
+ interface ConfigFieldDefinition {
960
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array';
961
+ default?: any;
962
+ description?: string;
963
+ min?: number;
964
+ max?: number;
965
+ options?: string[];
966
+ supportBinding?: boolean;
967
+ allowMultipleConnections?: boolean;
968
+ }
969
+ /**
970
+ * 子节点约束配置
971
+ */
972
+ interface ChildrenConstraints {
973
+ min?: number;
974
+ max?: number;
975
+ required?: boolean;
976
+ }
977
+ /**
978
+ * 节点元数据
979
+ */
980
+ interface NodeMetadata {
981
+ implementationType: string;
982
+ nodeType: NodeType;
983
+ displayName: string;
984
+ description?: string;
985
+ category?: string;
986
+ configSchema?: Record<string, ConfigFieldDefinition>;
987
+ childrenConstraints?: ChildrenConstraints;
988
+ }
989
+ /**
990
+ * 节点元数据注册表
991
+ */
992
+ declare class NodeMetadataRegistry {
993
+ private static metadataMap;
994
+ private static executorClassMap;
995
+ private static executorConstructors;
996
+ static register(target: Function, metadata: NodeMetadata): void;
997
+ static getMetadata(implementationType: string): NodeMetadata | undefined;
998
+ static getAllMetadata(): NodeMetadata[];
999
+ static getByCategory(category: string): NodeMetadata[];
1000
+ static getByNodeType(nodeType: NodeType): NodeMetadata[];
1001
+ static getImplementationType(executorClass: Function): string | undefined;
1002
+ static getExecutorConstructor(implementationType: string): (new () => any) | undefined;
1003
+ static getAllExecutorConstructors(): Map<string, new () => any>;
1004
+ }
1005
+ /**
1006
+ * 节点执行器元数据装饰器
1007
+ */
1008
+ declare function NodeExecutorMetadata(metadata: NodeMetadata): (target: Function) => void;
1009
+
1010
+ /**
1011
+ * 行为树启动辅助类
1012
+ *
1013
+ * 提供便捷方法来启动、停止行为树
1014
+ */
1015
+ declare class BehaviorTreeStarter {
1016
+ /**
1017
+ * 启动行为树
1018
+ *
1019
+ * @param entity 游戏实体
1020
+ * @param treeData 行为树数据
1021
+ * @param autoStart 是否自动开始执行
1022
+ */
1023
+ static start(entity: Entity, treeData: BehaviorTreeData, autoStart?: boolean): void;
1024
+ /**
1025
+ * 停止行为树
1026
+ *
1027
+ * @param entity 游戏实体
1028
+ */
1029
+ static stop(entity: Entity): void;
1030
+ /**
1031
+ * 暂停行为树
1032
+ *
1033
+ * @param entity 游戏实体
1034
+ */
1035
+ static pause(entity: Entity): void;
1036
+ /**
1037
+ * 恢复行为树
1038
+ *
1039
+ * @param entity 游戏实体
1040
+ */
1041
+ static resume(entity: Entity): void;
1042
+ /**
1043
+ * 重启行为树
1044
+ *
1045
+ * @param entity 游戏实体
1046
+ */
1047
+ static restart(entity: Entity): void;
1048
+ }
1049
+
1050
+ /**
1051
+ * 行为树构建器
1052
+ *
1053
+ * 提供流式API构建行为树数据结构
1054
+ */
1055
+ declare class BehaviorTreeBuilder {
1056
+ private treeData;
1057
+ private nodeStack;
1058
+ private nodeIdCounter;
1059
+ private constructor();
1060
+ /**
1061
+ * 创建构建器
1062
+ */
1063
+ static create(treeName?: string): BehaviorTreeBuilder;
1064
+ /**
1065
+ * 定义黑板变量
1066
+ */
1067
+ defineBlackboardVariable(key: string, initialValue: any): BehaviorTreeBuilder;
1068
+ /**
1069
+ * 添加序列节点
1070
+ */
1071
+ sequence(name?: string): BehaviorTreeBuilder;
1072
+ /**
1073
+ * 添加选择器节点
1074
+ */
1075
+ selector(name?: string): BehaviorTreeBuilder;
1076
+ /**
1077
+ * 添加并行节点
1078
+ */
1079
+ parallel(name?: string, config?: {
1080
+ successPolicy?: string;
1081
+ failurePolicy?: string;
1082
+ }): BehaviorTreeBuilder;
1083
+ /**
1084
+ * 添加并行选择器节点
1085
+ */
1086
+ parallelSelector(name?: string, config?: {
1087
+ failurePolicy?: string;
1088
+ }): BehaviorTreeBuilder;
1089
+ /**
1090
+ * 添加随机序列节点
1091
+ */
1092
+ randomSequence(name?: string): BehaviorTreeBuilder;
1093
+ /**
1094
+ * 添加随机选择器节点
1095
+ */
1096
+ randomSelector(name?: string): BehaviorTreeBuilder;
1097
+ /**
1098
+ * 添加反转装饰器
1099
+ */
1100
+ inverter(name?: string): BehaviorTreeBuilder;
1101
+ /**
1102
+ * 添加重复装饰器
1103
+ */
1104
+ repeater(repeatCount: number, name?: string): BehaviorTreeBuilder;
1105
+ /**
1106
+ * 添加总是成功装饰器
1107
+ */
1108
+ alwaysSucceed(name?: string): BehaviorTreeBuilder;
1109
+ /**
1110
+ * 添加总是失败装饰器
1111
+ */
1112
+ alwaysFail(name?: string): BehaviorTreeBuilder;
1113
+ /**
1114
+ * 添加直到成功装饰器
1115
+ */
1116
+ untilSuccess(name?: string): BehaviorTreeBuilder;
1117
+ /**
1118
+ * 添加直到失败装饰器
1119
+ */
1120
+ untilFail(name?: string): BehaviorTreeBuilder;
1121
+ /**
1122
+ * 添加条件装饰器
1123
+ */
1124
+ conditional(blackboardKey: string, expectedValue: any, operator?: string, name?: string): BehaviorTreeBuilder;
1125
+ /**
1126
+ * 添加冷却装饰器
1127
+ */
1128
+ cooldown(cooldownTime: number, name?: string): BehaviorTreeBuilder;
1129
+ /**
1130
+ * 添加超时装饰器
1131
+ */
1132
+ timeout(timeout: number, name?: string): BehaviorTreeBuilder;
1133
+ /**
1134
+ * 添加等待动作
1135
+ */
1136
+ wait(duration: number, name?: string): BehaviorTreeBuilder;
1137
+ /**
1138
+ * 添加日志动作
1139
+ */
1140
+ log(message: string, name?: string): BehaviorTreeBuilder;
1141
+ /**
1142
+ * 添加设置黑板值动作
1143
+ */
1144
+ setBlackboardValue(key: string, value: any, name?: string): BehaviorTreeBuilder;
1145
+ /**
1146
+ * 添加修改黑板值动作
1147
+ */
1148
+ modifyBlackboardValue(key: string, operation: string, value: number, name?: string): BehaviorTreeBuilder;
1149
+ /**
1150
+ * 添加执行动作
1151
+ */
1152
+ executeAction(actionName: string, name?: string): BehaviorTreeBuilder;
1153
+ /**
1154
+ * 添加黑板比较条件
1155
+ */
1156
+ blackboardCompare(key: string, compareValue: any, operator?: string, name?: string): BehaviorTreeBuilder;
1157
+ /**
1158
+ * 添加黑板存在检查条件
1159
+ */
1160
+ blackboardExists(key: string, name?: string): BehaviorTreeBuilder;
1161
+ /**
1162
+ * 添加随机概率条件
1163
+ */
1164
+ randomProbability(probability: number, name?: string): BehaviorTreeBuilder;
1165
+ /**
1166
+ * 添加执行条件
1167
+ */
1168
+ executeCondition(conditionName: string, name?: string): BehaviorTreeBuilder;
1169
+ /**
1170
+ * 结束当前节点,返回父节点
1171
+ */
1172
+ end(): BehaviorTreeBuilder;
1173
+ /**
1174
+ * 构建行为树数据
1175
+ */
1176
+ build(): BehaviorTreeData;
1177
+ private addCompositeNode;
1178
+ private addDecoratorNode;
1179
+ private addActionNode;
1180
+ private addConditionNode;
1181
+ private generateNodeId;
1182
+ }
1183
+
1184
+ /**
1185
+ * 节点数据JSON格式
1186
+ */
1187
+ interface NodeDataJSON {
1188
+ nodeType: string;
1189
+ compositeType?: string;
1190
+ decoratorType?: string;
1191
+ actionType?: string;
1192
+ conditionType?: string;
1193
+ [key: string]: any;
1194
+ }
1195
+ /**
1196
+ * 行为树节点属性类型常量
1197
+ * Behavior tree node property type constants
1198
+ */
1199
+ declare const NodePropertyType: {
1200
+ /** 字符串 */
1201
+ readonly String: "string";
1202
+ /** 数值 */
1203
+ readonly Number: "number";
1204
+ /** 布尔值 */
1205
+ readonly Boolean: "boolean";
1206
+ /** 选择框 */
1207
+ readonly Select: "select";
1208
+ /** 黑板变量引用 */
1209
+ readonly Blackboard: "blackboard";
1210
+ /** 代码编辑器 */
1211
+ readonly Code: "code";
1212
+ /** 变量引用 */
1213
+ readonly Variable: "variable";
1214
+ /** 资产引用 */
1215
+ readonly Asset: "asset";
1216
+ };
1217
+ /**
1218
+ * 节点属性类型(支持自定义扩展)
1219
+ * Node property type (supports custom extensions)
1220
+ *
1221
+ * @example
1222
+ * ```typescript
1223
+ * // 使用内置类型
1224
+ * type: NodePropertyType.String
1225
+ *
1226
+ * // 使用自定义类型
1227
+ * type: 'color-picker'
1228
+ * type: 'curve-editor'
1229
+ * ```
1230
+ */
1231
+ type NodePropertyType = (typeof NodePropertyType)[keyof typeof NodePropertyType] | string;
1232
+ /**
1233
+ * 属性定义(用于编辑器)
1234
+ */
1235
+ interface PropertyDefinition {
1236
+ name: string;
1237
+ type: NodePropertyType;
1238
+ label: string;
1239
+ description?: string;
1240
+ defaultValue?: any;
1241
+ options?: Array<{
1242
+ label: string;
1243
+ value: any;
1244
+ }>;
1245
+ min?: number;
1246
+ max?: number;
1247
+ step?: number;
1248
+ required?: boolean;
1249
+ /**
1250
+ * 字段编辑器配置
1251
+ *
1252
+ * 指定使用哪个字段编辑器以及相关选项
1253
+ *
1254
+ * @example
1255
+ * ```typescript
1256
+ * fieldEditor: {
1257
+ * type: 'asset',
1258
+ * options: { fileExtension: '.btree' }
1259
+ * }
1260
+ * ```
1261
+ */
1262
+ fieldEditor?: {
1263
+ type: string;
1264
+ options?: Record<string, any>;
1265
+ };
1266
+ /**
1267
+ * 自定义渲染配置
1268
+ *
1269
+ * 用于指定编辑器如何渲染此属性
1270
+ *
1271
+ * @example
1272
+ * ```typescript
1273
+ * renderConfig: {
1274
+ * component: 'ColorPicker', // 渲染器组件名称
1275
+ * props: { // 传递给组件的属性
1276
+ * showAlpha: true,
1277
+ * presets: ['#FF0000', '#00FF00']
1278
+ * }
1279
+ * }
1280
+ * ```
1281
+ */
1282
+ renderConfig?: {
1283
+ /** 渲染器组件名称或路径 */
1284
+ component?: string;
1285
+ /** 传递给渲染器的属性配置 */
1286
+ props?: Record<string, any>;
1287
+ /** 渲染器的样式类名 */
1288
+ className?: string;
1289
+ /** 渲染器的内联样式 */
1290
+ style?: Record<string, any>;
1291
+ /** 其他自定义配置 */
1292
+ [key: string]: any;
1293
+ };
1294
+ /**
1295
+ * 验证规则
1296
+ *
1297
+ * 用于在编辑器中验证输入
1298
+ *
1299
+ * @example
1300
+ * ```typescript
1301
+ * validation: {
1302
+ * pattern: /^\d+$/,
1303
+ * message: '只能输入数字',
1304
+ * validator: (value) => value > 0
1305
+ * }
1306
+ * ```
1307
+ */
1308
+ validation?: {
1309
+ /** 正则表达式验证 */
1310
+ pattern?: RegExp | string;
1311
+ /** 验证失败的提示信息 */
1312
+ message?: string;
1313
+ /** 自定义验证函数 */
1314
+ validator?: string;
1315
+ /** 最小长度(字符串) */
1316
+ minLength?: number;
1317
+ /** 最大长度(字符串) */
1318
+ maxLength?: number;
1319
+ };
1320
+ /**
1321
+ * 是否允许多个连接
1322
+ * 默认 false,只允许一个黑板变量连接
1323
+ */
1324
+ allowMultipleConnections?: boolean;
1325
+ }
1326
+ /**
1327
+ * 节点模板(用于编辑器)
1328
+ */
1329
+ interface NodeTemplate {
1330
+ type: NodeType;
1331
+ displayName: string;
1332
+ category: string;
1333
+ icon?: string;
1334
+ description: string;
1335
+ color?: string;
1336
+ className?: string;
1337
+ componentClass?: Function;
1338
+ requiresChildren?: boolean;
1339
+ minChildren?: number;
1340
+ maxChildren?: number;
1341
+ defaultConfig: Partial<NodeDataJSON>;
1342
+ properties: PropertyDefinition[];
1343
+ }
1344
+ /**
1345
+ * 节点模板库
1346
+ */
1347
+ declare class NodeTemplates {
1348
+ /**
1349
+ * 获取所有节点模板
1350
+ */
1351
+ static getAllTemplates(): NodeTemplate[];
1352
+ /**
1353
+ * 根据类型和子类型获取模板
1354
+ */
1355
+ static getTemplate(type: NodeType, subType: string): NodeTemplate | undefined;
1356
+ /**
1357
+ * 将NodeMetadata转换为NodeTemplate
1358
+ */
1359
+ private static convertMetadataToTemplate;
1360
+ /**
1361
+ * 获取节点类型的默认约束
1362
+ */
1363
+ private static getDefaultConstraintsByNodeType;
1364
+ /**
1365
+ * 将ConfigSchema转换为PropertyDefinition数组
1366
+ */
1367
+ private static convertConfigSchemaToProperties;
1368
+ /**
1369
+ * 映射字段类型到属性类型
1370
+ */
1371
+ private static mapFieldTypeToPropertyType;
1372
+ /**
1373
+ * NodeType转字符串
1374
+ */
1375
+ private static nodeTypeToString;
1376
+ /**
1377
+ * 根据NodeType获取默认分类
1378
+ */
1379
+ private static getCategoryByNodeType;
1380
+ /**
1381
+ * 根据节点类型获取默认图标和颜色
1382
+ */
1383
+ private static getIconAndColorByType;
1384
+ }
1385
+
1386
+ /**
1387
+ * 行为树资产元数据
1388
+ */
1389
+ interface AssetMetadata {
1390
+ name: string;
1391
+ description?: string;
1392
+ version: string;
1393
+ createdAt?: string;
1394
+ modifiedAt?: string;
1395
+ }
1396
+ /**
1397
+ * 黑板变量定义
1398
+ */
1399
+ interface BlackboardVariableDefinition {
1400
+ name: string;
1401
+ type: BlackboardValueType$1;
1402
+ defaultValue: any;
1403
+ readonly?: boolean;
1404
+ description?: string;
1405
+ }
1406
+ /**
1407
+ * 行为树节点配置数据
1408
+ */
1409
+ interface BehaviorNodeConfigData {
1410
+ className?: string;
1411
+ [key: string]: any;
1412
+ }
1413
+ /**
1414
+ * 行为树节点数据(运行时格式)
1415
+ */
1416
+ interface BehaviorTreeNodeData {
1417
+ id: string;
1418
+ name: string;
1419
+ nodeType: NodeType;
1420
+ data: BehaviorNodeConfigData;
1421
+ children: string[];
1422
+ }
1423
+ /**
1424
+ * 属性绑定定义
1425
+ */
1426
+ interface PropertyBinding {
1427
+ nodeId: string;
1428
+ propertyName: string;
1429
+ variableName: string;
1430
+ }
1431
+ /**
1432
+ * 行为树资产(运行时格式)
1433
+ *
1434
+ * 这是用于游戏运行时的优化格式,不包含编辑器UI信息
1435
+ */
1436
+ interface BehaviorTreeAsset {
1437
+ /**
1438
+ * 资产格式版本
1439
+ */
1440
+ version: string;
1441
+ /**
1442
+ * 元数据
1443
+ */
1444
+ metadata: AssetMetadata;
1445
+ /**
1446
+ * 根节点ID
1447
+ */
1448
+ rootNodeId: string;
1449
+ /**
1450
+ * 所有节点数据(扁平化存储,通过children建立层级)
1451
+ */
1452
+ nodes: BehaviorTreeNodeData[];
1453
+ /**
1454
+ * 黑板变量定义
1455
+ */
1456
+ blackboard: BlackboardVariableDefinition[];
1457
+ /**
1458
+ * 属性绑定
1459
+ */
1460
+ propertyBindings?: PropertyBinding[];
1461
+ }
1462
+ /**
1463
+ * 资产验证结果
1464
+ */
1465
+ interface AssetValidationResult {
1466
+ valid: boolean;
1467
+ errors?: string[];
1468
+ warnings?: string[];
1469
+ }
1470
+ /**
1471
+ * 资产验证器
1472
+ */
1473
+ declare class BehaviorTreeAssetValidator {
1474
+ /**
1475
+ * 验证资产数据的完整性和正确性
1476
+ */
1477
+ static validate(asset: BehaviorTreeAsset): AssetValidationResult;
1478
+ /**
1479
+ * 获取资产统计信息
1480
+ */
1481
+ static getStats(asset: BehaviorTreeAsset): {
1482
+ nodeCount: number;
1483
+ actionCount: number;
1484
+ conditionCount: number;
1485
+ compositeCount: number;
1486
+ decoratorCount: number;
1487
+ blackboardVariableCount: number;
1488
+ propertyBindingCount: number;
1489
+ maxDepth: number;
1490
+ };
1491
+ }
1492
+
1493
+ /**
1494
+ * 编辑器节点格式
1495
+ */
1496
+ interface EditorNodeTemplate {
1497
+ displayName: string;
1498
+ category: string;
1499
+ type: NodeType;
1500
+ className?: string;
1501
+ [key: string]: any;
1502
+ }
1503
+ interface EditorNodeData {
1504
+ nodeType?: string;
1505
+ className?: string;
1506
+ variableName?: string;
1507
+ name?: string;
1508
+ [key: string]: any;
1509
+ }
1510
+ interface EditorNode$1 {
1511
+ id: string;
1512
+ template: EditorNodeTemplate;
1513
+ data: EditorNodeData;
1514
+ position: {
1515
+ x: number;
1516
+ y: number;
1517
+ };
1518
+ children: string[];
1519
+ }
1520
+ /**
1521
+ * 编辑器连接格式
1522
+ */
1523
+ interface EditorConnection$1 {
1524
+ from: string;
1525
+ to: string;
1526
+ fromProperty?: string;
1527
+ toProperty?: string;
1528
+ connectionType: 'node' | 'property';
1529
+ }
1530
+ /**
1531
+ * 编辑器格式
1532
+ */
1533
+ interface EditorFormat {
1534
+ version?: string;
1535
+ metadata?: {
1536
+ name: string;
1537
+ description?: string;
1538
+ createdAt?: string;
1539
+ modifiedAt?: string;
1540
+ };
1541
+ nodes: EditorNode$1[];
1542
+ connections: EditorConnection$1[];
1543
+ blackboard: Record<string, any>;
1544
+ canvasState?: {
1545
+ offset: {
1546
+ x: number;
1547
+ y: number;
1548
+ };
1549
+ scale: number;
1550
+ };
1551
+ }
1552
+ /**
1553
+ * 编辑器格式转换器
1554
+ *
1555
+ * 将编辑器格式转换为运行时资产格式
1556
+ */
1557
+ declare class EditorFormatConverter {
1558
+ /**
1559
+ * 转换编辑器格式为资产格式
1560
+ *
1561
+ * @param editorData 编辑器数据
1562
+ * @param metadata 可选的元数据覆盖
1563
+ * @returns 行为树资产
1564
+ */
1565
+ static toAsset(editorData: EditorFormat, metadata?: Partial<AssetMetadata>): BehaviorTreeAsset;
1566
+ /**
1567
+ * 查找根节点
1568
+ */
1569
+ private static findRootNode;
1570
+ /**
1571
+ * 转换节点列表
1572
+ */
1573
+ private static convertNodes;
1574
+ /**
1575
+ * 转换单个节点
1576
+ */
1577
+ private static convertNode;
1578
+ /**
1579
+ * 转换黑板变量
1580
+ */
1581
+ private static convertBlackboard;
1582
+ /**
1583
+ * 推断黑板变量类型
1584
+ */
1585
+ private static inferBlackboardType;
1586
+ /**
1587
+ * 转换属性绑定
1588
+ */
1589
+ private static convertPropertyBindings;
1590
+ /**
1591
+ * 从资产格式转换回编辑器格式(用于加载)
1592
+ *
1593
+ * @param asset 行为树资产
1594
+ * @returns 编辑器格式数据
1595
+ */
1596
+ static fromAsset(asset: BehaviorTreeAsset): EditorFormat;
1597
+ /**
1598
+ * 从资产格式转换节点
1599
+ */
1600
+ private static convertNodesFromAsset;
1601
+ /**
1602
+ * 推断节点分类
1603
+ */
1604
+ private static inferCategory;
1605
+ /**
1606
+ * 将属性绑定转换为连接
1607
+ */
1608
+ private static convertPropertyBindingsToConnections;
1609
+ /**
1610
+ * 根据children关系构建节点连接
1611
+ */
1612
+ private static buildNodeConnections;
1613
+ }
1614
+
1615
+ /**
1616
+ * 行为树序列化格式
1617
+ * Behavior tree serialization format
1618
+ */
1619
+ type BehaviorTreeSerializationFormat = 'json' | 'binary';
1620
+ /**
1621
+ * 序列化选项
1622
+ */
1623
+ interface SerializationOptions {
1624
+ /**
1625
+ * 序列化格式
1626
+ */
1627
+ format: BehaviorTreeSerializationFormat;
1628
+ /**
1629
+ * 是否美化JSON输出(仅format='json'时有效)
1630
+ */
1631
+ pretty?: boolean;
1632
+ /**
1633
+ * 是否在序列化前验证资产
1634
+ */
1635
+ validate?: boolean;
1636
+ }
1637
+ /**
1638
+ * 反序列化选项
1639
+ */
1640
+ interface DeserializationOptions {
1641
+ /**
1642
+ * 是否在反序列化后验证资产
1643
+ */
1644
+ validate?: boolean;
1645
+ /**
1646
+ * 是否严格模式(验证失败抛出异常)
1647
+ */
1648
+ strict?: boolean;
1649
+ }
1650
+ /**
1651
+ * 行为树资产序列化器
1652
+ *
1653
+ * 支持JSON和二进制两种格式
1654
+ */
1655
+ declare class BehaviorTreeAssetSerializer {
1656
+ /**
1657
+ * 序列化资产
1658
+ *
1659
+ * @param asset 行为树资产
1660
+ * @param options 序列化选项
1661
+ * @returns 序列化后的数据(字符串或Uint8Array)
1662
+ *
1663
+ * @example
1664
+ * ```typescript
1665
+ * // JSON格式
1666
+ * const jsonData = BehaviorTreeAssetSerializer.serialize(asset, { format: 'json', pretty: true });
1667
+ *
1668
+ * // 二进制格式
1669
+ * const binaryData = BehaviorTreeAssetSerializer.serialize(asset, { format: 'binary' });
1670
+ * ```
1671
+ */
1672
+ static serialize(asset: BehaviorTreeAsset, options?: SerializationOptions): string | Uint8Array;
1673
+ /**
1674
+ * 序列化为JSON格式
1675
+ */
1676
+ private static serializeToJSON;
1677
+ /**
1678
+ * 序列化为二进制格式
1679
+ */
1680
+ private static serializeToBinary;
1681
+ /**
1682
+ * 反序列化资产
1683
+ *
1684
+ * @param data 序列化的数据(字符串或Uint8Array)
1685
+ * @param options 反序列化选项
1686
+ * @returns 行为树资产
1687
+ *
1688
+ * @example
1689
+ * ```typescript
1690
+ * // 从JSON加载
1691
+ * const asset = BehaviorTreeAssetSerializer.deserialize(jsonString);
1692
+ *
1693
+ * // 从二进制加载
1694
+ * const asset = BehaviorTreeAssetSerializer.deserialize(binaryData);
1695
+ * ```
1696
+ */
1697
+ static deserialize(data: string | Uint8Array, options?: DeserializationOptions): BehaviorTreeAsset;
1698
+ /**
1699
+ * 从JSON反序列化
1700
+ */
1701
+ private static deserializeFromJSON;
1702
+ /**
1703
+ * 从二进制反序列化
1704
+ */
1705
+ private static deserializeFromBinary;
1706
+ /**
1707
+ * 检测数据格式
1708
+ *
1709
+ * @param data 序列化的数据
1710
+ * @returns 格式类型
1711
+ */
1712
+ static detectFormat(data: string | Uint8Array): BehaviorTreeSerializationFormat;
1713
+ /**
1714
+ * 获取序列化数据的信息(不完全反序列化)
1715
+ *
1716
+ * @param data 序列化的数据
1717
+ * @returns 资产元信息
1718
+ */
1719
+ static getInfo(data: string | Uint8Array): {
1720
+ format: BehaviorTreeSerializationFormat;
1721
+ name: string;
1722
+ version: string;
1723
+ nodeCount: number;
1724
+ blackboardVariableCount: number;
1725
+ size: number;
1726
+ } | null;
1727
+ /**
1728
+ * 转换格式
1729
+ *
1730
+ * @param data 源数据
1731
+ * @param targetFormat 目标格式
1732
+ * @param pretty 是否美化JSON(仅当目标格式为json时有效)
1733
+ * @returns 转换后的数据
1734
+ *
1735
+ * @example
1736
+ * ```typescript
1737
+ * // JSON转二进制
1738
+ * const binary = BehaviorTreeAssetSerializer.convert(jsonString, 'binary');
1739
+ *
1740
+ * // 二进制转JSON
1741
+ * const json = BehaviorTreeAssetSerializer.convert(binaryData, 'json', true);
1742
+ * ```
1743
+ */
1744
+ static convert(data: string | Uint8Array, targetFormat: BehaviorTreeSerializationFormat, pretty?: boolean): string | Uint8Array;
1745
+ /**
1746
+ * 比较两个资产数据的大小
1747
+ *
1748
+ * @param jsonData JSON格式数据
1749
+ * @param binaryData 二进制格式数据
1750
+ * @returns 压缩率(百分比)
1751
+ */
1752
+ static compareSize(jsonData: string, binaryData: Uint8Array): {
1753
+ jsonSize: number;
1754
+ binarySize: number;
1755
+ compressionRatio: number;
1756
+ savedBytes: number;
1757
+ };
1758
+ }
1759
+
1760
+ /**
1761
+ * 编辑器节点数据接口
1762
+ */
1763
+ interface EditorNode {
1764
+ id: string;
1765
+ template: {
1766
+ type: string;
1767
+ className: string;
1768
+ displayName?: string;
1769
+ };
1770
+ data: Record<string, any>;
1771
+ children?: string[];
1772
+ }
1773
+ /**
1774
+ * 编辑器连接数据接口
1775
+ */
1776
+ interface EditorConnection {
1777
+ from: string;
1778
+ to: string;
1779
+ connectionType: 'node' | 'property';
1780
+ fromProperty?: string;
1781
+ toProperty?: string;
1782
+ }
1783
+ /**
1784
+ * 编辑器行为树数据接口
1785
+ */
1786
+ interface EditorBehaviorTreeData {
1787
+ version?: string;
1788
+ metadata?: {
1789
+ name: string;
1790
+ description?: string;
1791
+ createdAt?: string;
1792
+ modifiedAt?: string;
1793
+ };
1794
+ nodes: EditorNode[];
1795
+ connections?: EditorConnection[];
1796
+ blackboard?: Record<string, any>;
1797
+ }
1798
+ /**
1799
+ * 编辑器格式到运行时格式的转换器
1800
+ *
1801
+ * 负责将编辑器的 JSON 格式(包含UI信息)转换为运行时的 BehaviorTreeData 格式
1802
+ */
1803
+ declare class EditorToBehaviorTreeDataConverter {
1804
+ /**
1805
+ * 将编辑器 JSON 字符串转换为运行时 BehaviorTreeData
1806
+ */
1807
+ static fromEditorJSON(json: string): BehaviorTreeData;
1808
+ /**
1809
+ * 将编辑器数据对象转换为运行时 BehaviorTreeData
1810
+ */
1811
+ static convert(editorData: EditorBehaviorTreeData): BehaviorTreeData;
1812
+ /**
1813
+ * 从连接数据构建属性绑定映射
1814
+ * 处理 connectionType === 'property' 的连接,将黑板变量节点连接到目标节点的属性
1815
+ */
1816
+ private static buildPropertyBindingsMap;
1817
+ /**
1818
+ * 转换单个节点
1819
+ * @param editorNode 编辑器节点数据
1820
+ * @param propertyBindings 从连接中提取的属性绑定(可选)
1821
+ */
1822
+ private static convertNode;
1823
+ /**
1824
+ * 检查是否为不可执行的节点(如黑板变量节点)
1825
+ * 这些节点只在编辑器中使用,不参与运行时执行
1826
+ */
1827
+ private static isNonExecutableNode;
1828
+ /**
1829
+ * 从节点数据中提取实现类型
1830
+ *
1831
+ * 优先级:
1832
+ * 1. template.className(标准方式)
1833
+ * 2. data 中的类型字段(compositeType, actionType 等)
1834
+ * 3. 特殊节点类型的默认值(如 Root)
1835
+ */
1836
+ private static extractImplementationType;
1837
+ /**
1838
+ * 获取节点类型的默认实现
1839
+ * 当无法确定具体实现类型时使用
1840
+ */
1841
+ private static getDefaultImplementationType;
1842
+ /**
1843
+ * 映射节点类型
1844
+ */
1845
+ private static mapNodeType;
1846
+ /**
1847
+ * 提取节点配置(过滤掉内部字段和绑定字段)
1848
+ */
1849
+ private static extractConfig;
1850
+ /**
1851
+ * 提取黑板变量绑定
1852
+ */
1853
+ private static extractBindings;
1854
+ /**
1855
+ * 判断是否为黑板绑定
1856
+ */
1857
+ private static isBinding;
1858
+ /**
1859
+ * 提取黑板绑定的键名
1860
+ */
1861
+ private static extractBindingKey;
1862
+ /**
1863
+ * 提取中止类型(条件装饰器使用)
1864
+ */
1865
+ private static extractAbortType;
1866
+ /**
1867
+ * 生成行为树ID
1868
+ */
1869
+ private static generateTreeId;
1870
+ /**
1871
+ * 将运行时格式转换回编辑器格式(用于双向转换)
1872
+ */
1873
+ static toEditorJSON(treeData: BehaviorTreeData): string;
1874
+ /**
1875
+ * 将运行时 BehaviorTreeData 转换为编辑器格式
1876
+ */
1877
+ static convertToEditor(treeData: BehaviorTreeData): EditorBehaviorTreeData;
1878
+ /**
1879
+ * 将运行时节点转换为编辑器节点
1880
+ */
1881
+ private static convertNodeToEditor;
1882
+ }
1883
+
1884
+ /**
1885
+ * 全局黑板配置
1886
+ */
1887
+ interface GlobalBlackboardConfig {
1888
+ version: string;
1889
+ variables: BlackboardVariable[];
1890
+ }
1891
+ /**
1892
+ * 全局黑板服务
1893
+ *
1894
+ * 提供所有行为树共享的全局变量存储
1895
+ *
1896
+ * 使用方式:
1897
+ * ```typescript
1898
+ * // 注册服务(在 BehaviorTreePlugin.install 中自动完成)
1899
+ * core.services.registerSingleton(GlobalBlackboardService);
1900
+ *
1901
+ * // 获取服务
1902
+ * const blackboard = core.services.resolve(GlobalBlackboardService);
1903
+ * ```
1904
+ */
1905
+ declare class GlobalBlackboardService implements IService {
1906
+ private variables;
1907
+ dispose(): void;
1908
+ /**
1909
+ * 定义全局变量
1910
+ */
1911
+ defineVariable(name: string, type: BlackboardValueType$1, initialValue: any, options?: {
1912
+ readonly?: boolean;
1913
+ description?: string;
1914
+ }): void;
1915
+ /**
1916
+ * 获取全局变量值
1917
+ */
1918
+ getValue<T = any>(name: string): T | undefined;
1919
+ /**
1920
+ * 设置全局变量值
1921
+ */
1922
+ setValue(name: string, value: any, force?: boolean): boolean;
1923
+ /**
1924
+ * 检查全局变量是否存在
1925
+ */
1926
+ hasVariable(name: string): boolean;
1927
+ /**
1928
+ * 删除全局变量
1929
+ */
1930
+ removeVariable(name: string): boolean;
1931
+ /**
1932
+ * 获取所有变量名
1933
+ */
1934
+ getVariableNames(): string[];
1935
+ /**
1936
+ * 获取所有变量
1937
+ */
1938
+ getAllVariables(): BlackboardVariable[];
1939
+ /**
1940
+ * 清空所有全局变量
1941
+ */
1942
+ clear(): void;
1943
+ /**
1944
+ * 批量设置变量
1945
+ */
1946
+ setVariables(values: Record<string, any>): void;
1947
+ /**
1948
+ * 批量获取变量
1949
+ */
1950
+ getVariables(names: string[]): Record<string, any>;
1951
+ /**
1952
+ * 导出配置
1953
+ */
1954
+ exportConfig(): GlobalBlackboardConfig;
1955
+ /**
1956
+ * 导入配置
1957
+ */
1958
+ importConfig(config: GlobalBlackboardConfig): void;
1959
+ /**
1960
+ * 序列化为 JSON
1961
+ */
1962
+ toJSON(): string;
1963
+ /**
1964
+ * 从 JSON 反序列化
1965
+ */
1966
+ static fromJSON(json: string): GlobalBlackboardConfig;
1967
+ }
1968
+
1969
+ declare enum BlackboardValueType {
1970
+ String = "string",
1971
+ Number = "number",
1972
+ Boolean = "boolean",
1973
+ Vector2 = "vector2",
1974
+ Vector3 = "vector3",
1975
+ Vector4 = "vector4",
1976
+ Quaternion = "quaternion",
1977
+ Color = "color",
1978
+ GameObject = "gameObject",
1979
+ Transform = "transform",
1980
+ Component = "component",
1981
+ AssetReference = "assetReference",
1982
+ Array = "array",
1983
+ Map = "map",
1984
+ Enum = "enum",
1985
+ Struct = "struct",
1986
+ Function = "function",
1987
+ EntityId = "entityId",
1988
+ NodePath = "nodePath",
1989
+ ResourcePath = "resourcePath",
1990
+ AnimationState = "animationState",
1991
+ AudioClip = "audioClip",
1992
+ Material = "material",
1993
+ Texture = "texture"
1994
+ }
1995
+ interface BlackboardTypeDefinition {
1996
+ type: BlackboardValueType;
1997
+ displayName: string;
1998
+ category: 'basic' | 'math' | 'reference' | 'collection' | 'advanced' | 'game';
1999
+ defaultValue: any;
2000
+ editorComponent?: string;
2001
+ validator?: (value: any) => boolean;
2002
+ converter?: (value: any) => any;
2003
+ }
2004
+ declare const BlackboardTypes: Record<BlackboardValueType, BlackboardTypeDefinition>;
2005
+
2006
+ /**
2007
+ * 行为树执行系统令牌
2008
+ * Behavior tree execution system token
2009
+ */
2010
+ declare const BehaviorTreeSystemToken: _esengine_ecs_framework.ServiceToken<BehaviorTreeExecutionSystem>;
2011
+
2012
+ export { AbortType, AlwaysFailExecutor, AlwaysSucceedExecutor, type AssetMetadata, type AssetValidationResult, type BehaviorNodeConfigData, type BehaviorNodeData, type BehaviorTreeAsset, BehaviorTreeAssetManager, BehaviorTreeAssetSerializer, BehaviorTreeAssetType, BehaviorTreeAssetValidator, BehaviorTreeBuilder, type BehaviorTreeData, BehaviorTreeExecutionSystem, type BehaviorTreeNodeData, BehaviorTreeRuntimeComponent, type BehaviorTreeSerializationFormat, BehaviorTreeStarter, BehaviorTreeSystemToken, BindingHelper, BlackboardCompare, BlackboardExists, type BlackboardTypeDefinition, BlackboardTypes, BlackboardValueType$1 as BlackboardValueType, type BlackboardVariable, type BlackboardVariableDefinition, CompositeType, ConditionalExecutor, type ConfigFieldDefinition, CooldownExecutor, DecoratorType, type DeserializationOptions, type EditorConnection$1 as EditorConnection, type EditorFormat, EditorFormatConverter, type EditorNode$1 as EditorNode, type EditorNodeData, type EditorNodeTemplate, EditorToBehaviorTreeDataConverter, ExecuteAction, ExecuteCondition, type GlobalBlackboardConfig, GlobalBlackboardService, type IBTAssetManager, type IBehaviorTreeAssetContent, type INodeExecutor, type IServiceExecutor, InverterExecutor, LogAction, ModifyBlackboardValue, type NodeDataJSON, type NodeExecutionContext, NodeExecutorMetadata, NodeExecutorRegistry, type NodeMetadata, NodeMetadataRegistry, NodePropertyType, type NodeRuntimeState, type NodeTemplate, NodeTemplates, NodeType, ParallelExecutor, ParallelSelectorExecutor, type PropertyBinding, type PropertyDefinition, RandomProbability, RandomSelectorExecutor, RandomSequenceExecutor, RepeaterExecutor, RootExecutor, SelectorExecutor, SequenceExecutor, type SerializationOptions, ServiceDecorator, ServiceRegistry, SetBlackboardValue, SubTreeExecutor, TaskStatus, TimeoutExecutor, UntilFailExecutor, UntilSuccessExecutor, WaitAction, createDefaultRuntimeState };