@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.
- package/LICENSE +21 -0
- package/dist/index.d.ts +2012 -0
- package/dist/index.js +4692 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -29
- package/index.cjs +0 -2
- package/index.cjs.map +0 -1
- package/index.d.ts +0 -2875
- package/index.es5.js +0 -4
- package/index.es5.js.map +0 -1
- package/index.mjs +0 -2
- package/index.mjs.map +0 -1
- package/index.umd.js +0 -2
- package/index.umd.js.map +0 -1
package/index.d.ts
DELETED
|
@@ -1,2875 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @esengine/behavior-tree v1.0.0
|
|
3
|
-
* TypeScript definitions
|
|
4
|
-
*/
|
|
5
|
-
import { IService, Component, Entity, EntitySystem, IPlugin, Core, ServiceContainer, IScene } from '@esengine/ecs-framework';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 任务执行状态
|
|
9
|
-
*/
|
|
10
|
-
declare enum TaskStatus {
|
|
11
|
-
/** 无效状态 - 节点未初始化或已被重置 */
|
|
12
|
-
Invalid = 0,
|
|
13
|
-
/** 成功 - 节点执行成功完成 */
|
|
14
|
-
Success = 1,
|
|
15
|
-
/** 失败 - 节点执行失败 */
|
|
16
|
-
Failure = 2,
|
|
17
|
-
/** 运行中 - 节点正在执行,需要在后续帧继续 */
|
|
18
|
-
Running = 3
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* 节点类型
|
|
22
|
-
*/
|
|
23
|
-
declare enum NodeType {
|
|
24
|
-
/** 复合节点 - 有多个子节点 */
|
|
25
|
-
Composite = "composite",
|
|
26
|
-
/** 装饰器节点 - 有一个子节点 */
|
|
27
|
-
Decorator = "decorator",
|
|
28
|
-
/** 动作节点 - 叶子节点 */
|
|
29
|
-
Action = "action",
|
|
30
|
-
/** 条件节点 - 叶子节点 */
|
|
31
|
-
Condition = "condition"
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* 复合节点类型
|
|
35
|
-
*/
|
|
36
|
-
declare enum CompositeType {
|
|
37
|
-
/** 序列 - 按顺序执行,全部成功才成功 */
|
|
38
|
-
Sequence = "sequence",
|
|
39
|
-
/** 选择 - 按顺序执行,任一成功则成功 */
|
|
40
|
-
Selector = "selector",
|
|
41
|
-
/** 并行 - 同时执行所有子节点 */
|
|
42
|
-
Parallel = "parallel",
|
|
43
|
-
/** 并行选择 - 并行执行,任一成功则成功 */
|
|
44
|
-
ParallelSelector = "parallel-selector",
|
|
45
|
-
/** 随机序列 - 随机顺序执行序列 */
|
|
46
|
-
RandomSequence = "random-sequence",
|
|
47
|
-
/** 随机选择 - 随机顺序执行选择 */
|
|
48
|
-
RandomSelector = "random-selector"
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* 装饰器节点类型
|
|
52
|
-
*/
|
|
53
|
-
declare enum DecoratorType {
|
|
54
|
-
/** 反转 - 反转子节点结果 */
|
|
55
|
-
Inverter = "inverter",
|
|
56
|
-
/** 重复 - 重复执行子节点 */
|
|
57
|
-
Repeater = "repeater",
|
|
58
|
-
/** 直到成功 - 重复直到成功 */
|
|
59
|
-
UntilSuccess = "until-success",
|
|
60
|
-
/** 直到失败 - 重复直到失败 */
|
|
61
|
-
UntilFail = "until-fail",
|
|
62
|
-
/** 总是成功 - 无论子节点结果都返回成功 */
|
|
63
|
-
AlwaysSucceed = "always-succeed",
|
|
64
|
-
/** 总是失败 - 无论子节点结果都返回失败 */
|
|
65
|
-
AlwaysFail = "always-fail",
|
|
66
|
-
/** 条件装饰器 - 基于条件执行子节点 */
|
|
67
|
-
Conditional = "conditional",
|
|
68
|
-
/** 冷却 - 冷却时间内阻止执行 */
|
|
69
|
-
Cooldown = "cooldown",
|
|
70
|
-
/** 超时 - 超时则返回失败 */
|
|
71
|
-
Timeout = "timeout"
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* 中止类型
|
|
75
|
-
*
|
|
76
|
-
* 用于动态优先级和条件重新评估
|
|
77
|
-
*/
|
|
78
|
-
declare enum AbortType {
|
|
79
|
-
/** 无 - 不中止任何节点 */
|
|
80
|
-
None = "none",
|
|
81
|
-
/** 自身 - 条件变化时可以中止自身的执行 */
|
|
82
|
-
Self = "self",
|
|
83
|
-
/** 低优先级 - 条件满足时可以中止低优先级的兄弟节点 */
|
|
84
|
-
LowerPriority = "lower-priority",
|
|
85
|
-
/** 两者 - 可以中止自身和低优先级节点 */
|
|
86
|
-
Both = "both"
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* 黑板变量类型
|
|
90
|
-
*/
|
|
91
|
-
declare enum BlackboardValueType {
|
|
92
|
-
String = "string",
|
|
93
|
-
Number = "number",
|
|
94
|
-
Boolean = "boolean",
|
|
95
|
-
Vector2 = "vector2",
|
|
96
|
-
Vector3 = "vector3",
|
|
97
|
-
Object = "object",
|
|
98
|
-
Array = "array"
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* 全局黑板配置
|
|
103
|
-
*/
|
|
104
|
-
interface GlobalBlackboardConfig {
|
|
105
|
-
version: string;
|
|
106
|
-
variables: BlackboardVariable[];
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* 全局黑板服务
|
|
110
|
-
*
|
|
111
|
-
* 提供所有行为树共享的全局变量存储
|
|
112
|
-
*
|
|
113
|
-
* 使用方式:
|
|
114
|
-
* ```typescript
|
|
115
|
-
* // 注册服务(在 BehaviorTreePlugin.install 中自动完成)
|
|
116
|
-
* core.services.registerSingleton(GlobalBlackboardService);
|
|
117
|
-
*
|
|
118
|
-
* // 获取服务
|
|
119
|
-
* const blackboard = core.services.resolve(GlobalBlackboardService);
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
declare class GlobalBlackboardService implements IService {
|
|
123
|
-
private variables;
|
|
124
|
-
dispose(): void;
|
|
125
|
-
/**
|
|
126
|
-
* 定义全局变量
|
|
127
|
-
*/
|
|
128
|
-
defineVariable(name: string, type: BlackboardValueType, initialValue: any, options?: {
|
|
129
|
-
readonly?: boolean;
|
|
130
|
-
description?: string;
|
|
131
|
-
}): void;
|
|
132
|
-
/**
|
|
133
|
-
* 获取全局变量值
|
|
134
|
-
*/
|
|
135
|
-
getValue<T = any>(name: string): T | undefined;
|
|
136
|
-
/**
|
|
137
|
-
* 设置全局变量值
|
|
138
|
-
*/
|
|
139
|
-
setValue(name: string, value: any, force?: boolean): boolean;
|
|
140
|
-
/**
|
|
141
|
-
* 检查全局变量是否存在
|
|
142
|
-
*/
|
|
143
|
-
hasVariable(name: string): boolean;
|
|
144
|
-
/**
|
|
145
|
-
* 删除全局变量
|
|
146
|
-
*/
|
|
147
|
-
removeVariable(name: string): boolean;
|
|
148
|
-
/**
|
|
149
|
-
* 获取所有变量名
|
|
150
|
-
*/
|
|
151
|
-
getVariableNames(): string[];
|
|
152
|
-
/**
|
|
153
|
-
* 获取所有变量
|
|
154
|
-
*/
|
|
155
|
-
getAllVariables(): BlackboardVariable[];
|
|
156
|
-
/**
|
|
157
|
-
* 清空所有全局变量
|
|
158
|
-
*/
|
|
159
|
-
clear(): void;
|
|
160
|
-
/**
|
|
161
|
-
* 批量设置变量
|
|
162
|
-
*/
|
|
163
|
-
setVariables(values: Record<string, any>): void;
|
|
164
|
-
/**
|
|
165
|
-
* 批量获取变量
|
|
166
|
-
*/
|
|
167
|
-
getVariables(names: string[]): Record<string, any>;
|
|
168
|
-
/**
|
|
169
|
-
* 导出配置
|
|
170
|
-
*/
|
|
171
|
-
exportConfig(): GlobalBlackboardConfig;
|
|
172
|
-
/**
|
|
173
|
-
* 导入配置
|
|
174
|
-
*/
|
|
175
|
-
importConfig(config: GlobalBlackboardConfig): void;
|
|
176
|
-
/**
|
|
177
|
-
* 序列化为 JSON
|
|
178
|
-
*/
|
|
179
|
-
toJSON(): string;
|
|
180
|
-
/**
|
|
181
|
-
* 从 JSON 反序列化
|
|
182
|
-
*/
|
|
183
|
-
static fromJSON(json: string): GlobalBlackboardConfig;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* 黑板变量定义
|
|
188
|
-
*/
|
|
189
|
-
interface BlackboardVariable {
|
|
190
|
-
name: string;
|
|
191
|
-
type: BlackboardValueType;
|
|
192
|
-
value: any;
|
|
193
|
-
readonly?: boolean;
|
|
194
|
-
description?: string;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* 黑板组件 - 用于节点间共享数据
|
|
198
|
-
*
|
|
199
|
-
* 支持分层查找:
|
|
200
|
-
* 1. 先查找本地变量
|
|
201
|
-
* 2. 如果找不到,自动查找全局 Blackboard
|
|
202
|
-
*
|
|
203
|
-
* 通常附加到行为树的根节点上
|
|
204
|
-
*/
|
|
205
|
-
declare class BlackboardComponent extends Component {
|
|
206
|
-
/** 存储的本地变量 */
|
|
207
|
-
private variables;
|
|
208
|
-
/** 是否启用全局 Blackboard 查找 */
|
|
209
|
-
private useGlobalBlackboard;
|
|
210
|
-
/**
|
|
211
|
-
* 定义一个新变量
|
|
212
|
-
*/
|
|
213
|
-
defineVariable(name: string, type: BlackboardValueType, initialValue: any, options?: {
|
|
214
|
-
readonly?: boolean;
|
|
215
|
-
description?: string;
|
|
216
|
-
}): void;
|
|
217
|
-
/**
|
|
218
|
-
* 获取变量值
|
|
219
|
-
* 先查找本地变量,找不到则查找全局变量
|
|
220
|
-
*/
|
|
221
|
-
getValue<T = any>(name: string): T | undefined;
|
|
222
|
-
/**
|
|
223
|
-
* 获取本地变量值(不查找全局)
|
|
224
|
-
*/
|
|
225
|
-
getLocalValue<T = any>(name: string): T | undefined;
|
|
226
|
-
/**
|
|
227
|
-
* 设置变量值
|
|
228
|
-
* 优先设置本地变量,如果本地不存在且全局存在,则设置全局变量
|
|
229
|
-
*/
|
|
230
|
-
setValue(name: string, value: any, force?: boolean): boolean;
|
|
231
|
-
/**
|
|
232
|
-
* 设置本地变量值(不影响全局)
|
|
233
|
-
*/
|
|
234
|
-
setLocalValue(name: string, value: any, force?: boolean): boolean;
|
|
235
|
-
/**
|
|
236
|
-
* 检查变量是否存在(包括本地和全局)
|
|
237
|
-
*/
|
|
238
|
-
hasVariable(name: string): boolean;
|
|
239
|
-
/**
|
|
240
|
-
* 检查本地变量是否存在
|
|
241
|
-
*/
|
|
242
|
-
hasLocalVariable(name: string): boolean;
|
|
243
|
-
/**
|
|
244
|
-
* 删除变量
|
|
245
|
-
*/
|
|
246
|
-
removeVariable(name: string): boolean;
|
|
247
|
-
/**
|
|
248
|
-
* 获取所有变量名
|
|
249
|
-
*/
|
|
250
|
-
getVariableNames(): string[];
|
|
251
|
-
/**
|
|
252
|
-
* 清空所有本地变量
|
|
253
|
-
*/
|
|
254
|
-
clear(): void;
|
|
255
|
-
/**
|
|
256
|
-
* 启用/禁用全局 Blackboard 查找
|
|
257
|
-
*/
|
|
258
|
-
setUseGlobalBlackboard(enabled: boolean): void;
|
|
259
|
-
/**
|
|
260
|
-
* 是否启用全局 Blackboard 查找
|
|
261
|
-
*/
|
|
262
|
-
isUsingGlobalBlackboard(): boolean;
|
|
263
|
-
/**
|
|
264
|
-
* 获取所有变量(包括本地和全局)
|
|
265
|
-
*/
|
|
266
|
-
getAllVariables(): BlackboardVariable[];
|
|
267
|
-
/**
|
|
268
|
-
* 获取全局 Blackboard 服务的引用
|
|
269
|
-
*/
|
|
270
|
-
static getGlobalBlackboard(): GlobalBlackboardService;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* 自定义动作函数类型
|
|
275
|
-
*/
|
|
276
|
-
type CustomActionFunction = (entity: Entity, blackboard?: BlackboardComponent, deltaTime?: number) => TaskStatus;
|
|
277
|
-
/**
|
|
278
|
-
* 执行自定义函数动作组件
|
|
279
|
-
*
|
|
280
|
-
* 允许用户提供自定义的动作执行函数
|
|
281
|
-
*/
|
|
282
|
-
declare class ExecuteAction extends Component {
|
|
283
|
-
actionCode?: string;
|
|
284
|
-
parameters: Record<string, any>;
|
|
285
|
-
/** 编译后的函数(不序列化) */
|
|
286
|
-
private compiledFunction?;
|
|
287
|
-
/**
|
|
288
|
-
* 获取或编译执行函数
|
|
289
|
-
*/
|
|
290
|
-
getFunction(): CustomActionFunction | undefined;
|
|
291
|
-
/**
|
|
292
|
-
* 设置自定义函数(运行时使用)
|
|
293
|
-
*/
|
|
294
|
-
setFunction(func: CustomActionFunction): void;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* 等待动作组件
|
|
299
|
-
*
|
|
300
|
-
* 等待指定时间后返回成功
|
|
301
|
-
*/
|
|
302
|
-
declare class WaitAction extends Component {
|
|
303
|
-
waitTime: number;
|
|
304
|
-
/** 已等待时间(秒) */
|
|
305
|
-
elapsedTime: number;
|
|
306
|
-
/**
|
|
307
|
-
* 重置等待状态
|
|
308
|
-
*/
|
|
309
|
-
reset(): void;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* 日志动作组件
|
|
314
|
-
*
|
|
315
|
-
* 输出日志信息
|
|
316
|
-
*/
|
|
317
|
-
declare class LogAction extends Component {
|
|
318
|
-
message: string;
|
|
319
|
-
level: 'log' | 'info' | 'warn' | 'error';
|
|
320
|
-
includeEntityInfo: boolean;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* 设置黑板变量值动作组件
|
|
325
|
-
*
|
|
326
|
-
* 将指定值或另一个黑板变量的值设置到目标变量
|
|
327
|
-
*/
|
|
328
|
-
declare class SetBlackboardValueAction extends Component {
|
|
329
|
-
variableName: string;
|
|
330
|
-
value: any;
|
|
331
|
-
sourceVariable?: string;
|
|
332
|
-
force: boolean;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* 修改操作类型
|
|
337
|
-
*/
|
|
338
|
-
declare enum ModifyOperation {
|
|
339
|
-
/** 加法 */
|
|
340
|
-
Add = "add",
|
|
341
|
-
/** 减法 */
|
|
342
|
-
Subtract = "subtract",
|
|
343
|
-
/** 乘法 */
|
|
344
|
-
Multiply = "multiply",
|
|
345
|
-
/** 除法 */
|
|
346
|
-
Divide = "divide",
|
|
347
|
-
/** 取模 */
|
|
348
|
-
Modulo = "modulo",
|
|
349
|
-
/** 追加(数组/字符串) */
|
|
350
|
-
Append = "append",
|
|
351
|
-
/** 移除(数组) */
|
|
352
|
-
Remove = "remove"
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* 修改黑板变量值动作组件
|
|
356
|
-
*
|
|
357
|
-
* 对黑板变量执行数学或逻辑操作
|
|
358
|
-
*/
|
|
359
|
-
declare class ModifyBlackboardValueAction extends Component {
|
|
360
|
-
variableName: string;
|
|
361
|
-
operation: ModifyOperation;
|
|
362
|
-
operand: any;
|
|
363
|
-
force: boolean;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* 比较运算符
|
|
368
|
-
*/
|
|
369
|
-
declare enum CompareOperator {
|
|
370
|
-
/** 等于 */
|
|
371
|
-
Equal = "equal",
|
|
372
|
-
/** 不等于 */
|
|
373
|
-
NotEqual = "notEqual",
|
|
374
|
-
/** 大于 */
|
|
375
|
-
Greater = "greater",
|
|
376
|
-
/** 大于等于 */
|
|
377
|
-
GreaterOrEqual = "greaterOrEqual",
|
|
378
|
-
/** 小于 */
|
|
379
|
-
Less = "less",
|
|
380
|
-
/** 小于等于 */
|
|
381
|
-
LessOrEqual = "lessOrEqual",
|
|
382
|
-
/** 包含(字符串/数组) */
|
|
383
|
-
Contains = "contains",
|
|
384
|
-
/** 正则匹配 */
|
|
385
|
-
Matches = "matches"
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* 黑板变量比较条件组件
|
|
389
|
-
*
|
|
390
|
-
* 比较黑板变量与指定值或另一个变量
|
|
391
|
-
*/
|
|
392
|
-
declare class BlackboardCompareCondition extends Component {
|
|
393
|
-
variableName: string;
|
|
394
|
-
operator: CompareOperator;
|
|
395
|
-
compareValue: any;
|
|
396
|
-
invertResult: boolean;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* 黑板变量存在性检查条件组件
|
|
401
|
-
*
|
|
402
|
-
* 检查黑板变量是否存在
|
|
403
|
-
*/
|
|
404
|
-
declare class BlackboardExistsCondition extends Component {
|
|
405
|
-
variableName: string;
|
|
406
|
-
checkNotNull: boolean;
|
|
407
|
-
invertResult: boolean;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* 随机概率条件组件
|
|
412
|
-
*
|
|
413
|
-
* 根据概率返回成功或失败
|
|
414
|
-
*/
|
|
415
|
-
declare class RandomProbabilityCondition extends Component {
|
|
416
|
-
probability: number;
|
|
417
|
-
alwaysRandomize: boolean;
|
|
418
|
-
/** 缓存的随机结果(不序列化) */
|
|
419
|
-
private cachedResult?;
|
|
420
|
-
/**
|
|
421
|
-
* 评估随机概率
|
|
422
|
-
*/
|
|
423
|
-
evaluate(): boolean;
|
|
424
|
-
/**
|
|
425
|
-
* 重置缓存
|
|
426
|
-
*/
|
|
427
|
-
reset(): void;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* 自定义条件函数类型
|
|
432
|
-
*/
|
|
433
|
-
type CustomConditionFunction = (entity: Entity, blackboard?: BlackboardComponent, deltaTime?: number) => boolean;
|
|
434
|
-
/**
|
|
435
|
-
* 执行自定义条件组件
|
|
436
|
-
*
|
|
437
|
-
* 允许用户提供自定义的条件检查函数
|
|
438
|
-
*/
|
|
439
|
-
declare class ExecuteCondition extends Component {
|
|
440
|
-
conditionCode?: string;
|
|
441
|
-
parameters: Record<string, any>;
|
|
442
|
-
invertResult: boolean;
|
|
443
|
-
/** 编译后的函数(不序列化) */
|
|
444
|
-
private compiledFunction?;
|
|
445
|
-
/**
|
|
446
|
-
* 获取或编译条件函数
|
|
447
|
-
*/
|
|
448
|
-
getFunction(): CustomConditionFunction | undefined;
|
|
449
|
-
/**
|
|
450
|
-
* 设置自定义函数(运行时使用)
|
|
451
|
-
*/
|
|
452
|
-
setFunction(func: CustomConditionFunction): void;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
/**
|
|
456
|
-
* 复合节点组件
|
|
457
|
-
*
|
|
458
|
-
* 用于标识复合节点类型(Sequence, Selector, Parallel等)
|
|
459
|
-
*/
|
|
460
|
-
declare class CompositeNodeComponent extends Component {
|
|
461
|
-
/** 复合节点类型 */
|
|
462
|
-
compositeType: CompositeType;
|
|
463
|
-
/** 随机化的子节点索引顺序 */
|
|
464
|
-
protected shuffledIndices: number[];
|
|
465
|
-
/** 是否在重启时重新洗牌(子类可选) */
|
|
466
|
-
protected reshuffleOnRestart: boolean;
|
|
467
|
-
/**
|
|
468
|
-
* 获取下一个子节点索引
|
|
469
|
-
*/
|
|
470
|
-
getNextChildIndex(currentIndex: number, totalChildren: number): number;
|
|
471
|
-
/**
|
|
472
|
-
* 洗牌子节点索引
|
|
473
|
-
*/
|
|
474
|
-
private shuffleIndices;
|
|
475
|
-
/**
|
|
476
|
-
* 重置洗牌状态
|
|
477
|
-
*/
|
|
478
|
-
resetShuffle(): void;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
* 序列节点
|
|
483
|
-
*
|
|
484
|
-
* 按顺序执行所有子节点,全部成功才成功
|
|
485
|
-
*/
|
|
486
|
-
declare class SequenceNode extends CompositeNodeComponent {
|
|
487
|
-
abortType: AbortType;
|
|
488
|
-
constructor();
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* 选择节点
|
|
493
|
-
*
|
|
494
|
-
* 按顺序执行子节点,任一成功则成功
|
|
495
|
-
*/
|
|
496
|
-
declare class SelectorNode extends CompositeNodeComponent {
|
|
497
|
-
abortType: AbortType;
|
|
498
|
-
constructor();
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
/**
|
|
502
|
-
* 并行节点
|
|
503
|
-
*
|
|
504
|
-
* 同时执行所有子节点
|
|
505
|
-
*/
|
|
506
|
-
declare class ParallelNode extends CompositeNodeComponent {
|
|
507
|
-
successPolicy: 'all' | 'one';
|
|
508
|
-
failurePolicy: 'one' | 'all';
|
|
509
|
-
constructor();
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* 并行选择节点
|
|
514
|
-
*
|
|
515
|
-
* 并行执行子节点,任一成功则成功
|
|
516
|
-
*/
|
|
517
|
-
declare class ParallelSelectorNode extends CompositeNodeComponent {
|
|
518
|
-
failurePolicy: 'one' | 'all';
|
|
519
|
-
constructor();
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
/**
|
|
523
|
-
* 随机序列节点
|
|
524
|
-
*
|
|
525
|
-
* 随机顺序执行子节点序列
|
|
526
|
-
*/
|
|
527
|
-
declare class RandomSequenceNode extends CompositeNodeComponent {
|
|
528
|
-
reshuffleOnRestart: boolean;
|
|
529
|
-
constructor();
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
/**
|
|
533
|
-
* 随机选择节点
|
|
534
|
-
*
|
|
535
|
-
* 随机顺序执行子节点选择
|
|
536
|
-
*/
|
|
537
|
-
declare class RandomSelectorNode extends CompositeNodeComponent {
|
|
538
|
-
reshuffleOnRestart: boolean;
|
|
539
|
-
constructor();
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* SubTree 节点 - 引用其他行为树作为子树
|
|
544
|
-
*
|
|
545
|
-
* 允许将其他行为树嵌入到当前树中,实现行为树的复用和模块化。
|
|
546
|
-
*
|
|
547
|
-
* 注意:SubTreeNode 是一个特殊的叶子节点,它不会执行编辑器中静态连接的子节点,
|
|
548
|
-
* 只会执行从 assetId 动态加载的外部行为树文件。
|
|
549
|
-
*
|
|
550
|
-
* @example
|
|
551
|
-
* ```typescript
|
|
552
|
-
* const subTree = entity.addComponent(SubTreeNode);
|
|
553
|
-
* subTree.assetId = 'patrol';
|
|
554
|
-
* subTree.inheritParentBlackboard = true;
|
|
555
|
-
* ```
|
|
556
|
-
*/
|
|
557
|
-
declare class SubTreeNode extends CompositeNodeComponent {
|
|
558
|
-
/**
|
|
559
|
-
* 引用的子树资产ID
|
|
560
|
-
* 逻辑标识符,例如 'patrol' 或 'ai/patrol'
|
|
561
|
-
* 实际的文件路径由 AssetLoader 决定
|
|
562
|
-
*/
|
|
563
|
-
assetId: string;
|
|
564
|
-
/**
|
|
565
|
-
* 是否将父黑板传递给子树
|
|
566
|
-
*
|
|
567
|
-
* - true: 子树可以访问和修改父树的黑板变量
|
|
568
|
-
* - false: 子树使用独立的黑板实例
|
|
569
|
-
*/
|
|
570
|
-
inheritParentBlackboard: boolean;
|
|
571
|
-
/**
|
|
572
|
-
* 子树执行失败时是否传播失败状态
|
|
573
|
-
*
|
|
574
|
-
* - true: 子树失败时,SubTree 节点返回 Failure
|
|
575
|
-
* - false: 子树失败时,SubTree 节点返回 Success(忽略失败)
|
|
576
|
-
*/
|
|
577
|
-
propagateFailure: boolean;
|
|
578
|
-
/**
|
|
579
|
-
* 是否在行为树启动时预加载子树
|
|
580
|
-
*
|
|
581
|
-
* - true: 在根节点开始执行前预加载此子树,确保执行时子树已就绪
|
|
582
|
-
* - false: 运行时异步加载,执行到此节点时才开始加载(可能会有延迟)
|
|
583
|
-
*/
|
|
584
|
-
preload: boolean;
|
|
585
|
-
/**
|
|
586
|
-
* 子树的根实体(运行时)
|
|
587
|
-
* 在执行时动态创建,执行结束后销毁
|
|
588
|
-
*/
|
|
589
|
-
private subTreeRoot?;
|
|
590
|
-
/**
|
|
591
|
-
* 子树是否已完成
|
|
592
|
-
*/
|
|
593
|
-
private subTreeCompleted;
|
|
594
|
-
/**
|
|
595
|
-
* 子树的最终状态
|
|
596
|
-
*/
|
|
597
|
-
private subTreeResult;
|
|
598
|
-
/**
|
|
599
|
-
* 获取子树根实体
|
|
600
|
-
*/
|
|
601
|
-
getSubTreeRoot(): Entity | undefined;
|
|
602
|
-
/**
|
|
603
|
-
* 设置子树根实体(由执行系统调用)
|
|
604
|
-
*/
|
|
605
|
-
setSubTreeRoot(root: Entity | undefined): void;
|
|
606
|
-
/**
|
|
607
|
-
* 标记子树完成(由执行系统调用)
|
|
608
|
-
*/
|
|
609
|
-
markSubTreeCompleted(result: TaskStatus): void;
|
|
610
|
-
/**
|
|
611
|
-
* 检查子树是否已完成
|
|
612
|
-
*/
|
|
613
|
-
isSubTreeCompleted(): boolean;
|
|
614
|
-
/**
|
|
615
|
-
* 获取子树执行结果
|
|
616
|
-
*/
|
|
617
|
-
getSubTreeResult(): TaskStatus;
|
|
618
|
-
/**
|
|
619
|
-
* 重置子树状态
|
|
620
|
-
*/
|
|
621
|
-
reset(): void;
|
|
622
|
-
/**
|
|
623
|
-
* 重置完成状态(用于复用预加载的子树)
|
|
624
|
-
* 保留子树根引用,只重置完成标记
|
|
625
|
-
*/
|
|
626
|
-
resetCompletionState(): void;
|
|
627
|
-
/**
|
|
628
|
-
* 验证配置
|
|
629
|
-
*/
|
|
630
|
-
validate(): string[];
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
/**
|
|
634
|
-
* 装饰器节点组件基类
|
|
635
|
-
*
|
|
636
|
-
* 只包含通用的装饰器类型标识
|
|
637
|
-
* 具体的属性由各个子类自己定义
|
|
638
|
-
*/
|
|
639
|
-
declare class DecoratorNodeComponent extends Component {
|
|
640
|
-
/** 装饰器类型 */
|
|
641
|
-
decoratorType: DecoratorType;
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
/**
|
|
645
|
-
* 反转节点
|
|
646
|
-
*
|
|
647
|
-
* 反转子节点的执行结果
|
|
648
|
-
*/
|
|
649
|
-
declare class InverterNode extends DecoratorNodeComponent {
|
|
650
|
-
constructor();
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
/**
|
|
654
|
-
* 重复节点
|
|
655
|
-
*
|
|
656
|
-
* 重复执行子节点指定次数
|
|
657
|
-
*/
|
|
658
|
-
declare class RepeaterNode extends DecoratorNodeComponent {
|
|
659
|
-
constructor();
|
|
660
|
-
repeatCount: number;
|
|
661
|
-
endOnFailure: boolean;
|
|
662
|
-
/** 当前已重复次数 */
|
|
663
|
-
currentRepeatCount: number;
|
|
664
|
-
/**
|
|
665
|
-
* 增加重复计数
|
|
666
|
-
*/
|
|
667
|
-
incrementRepeat(): void;
|
|
668
|
-
/**
|
|
669
|
-
* 检查是否应该继续重复
|
|
670
|
-
*/
|
|
671
|
-
shouldContinueRepeat(): boolean;
|
|
672
|
-
/**
|
|
673
|
-
* 重置状态
|
|
674
|
-
*/
|
|
675
|
-
reset(): void;
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
/**
|
|
679
|
-
* 直到成功节点
|
|
680
|
-
*
|
|
681
|
-
* 重复执行子节点直到成功
|
|
682
|
-
*/
|
|
683
|
-
declare class UntilSuccessNode extends DecoratorNodeComponent {
|
|
684
|
-
constructor();
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
/**
|
|
688
|
-
* 直到失败节点
|
|
689
|
-
*
|
|
690
|
-
* 重复执行子节点直到失败
|
|
691
|
-
*/
|
|
692
|
-
declare class UntilFailNode extends DecoratorNodeComponent {
|
|
693
|
-
constructor();
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
/**
|
|
697
|
-
* 总是成功节点
|
|
698
|
-
*
|
|
699
|
-
* 无论子节点结果如何都返回成功
|
|
700
|
-
*/
|
|
701
|
-
declare class AlwaysSucceedNode extends DecoratorNodeComponent {
|
|
702
|
-
constructor();
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
* 总是失败节点
|
|
707
|
-
*
|
|
708
|
-
* 无论子节点结果如何都返回失败
|
|
709
|
-
*/
|
|
710
|
-
declare class AlwaysFailNode extends DecoratorNodeComponent {
|
|
711
|
-
constructor();
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
/**
|
|
715
|
-
* 条件装饰器节点
|
|
716
|
-
*
|
|
717
|
-
* 基于条件判断是否执行子节点
|
|
718
|
-
*/
|
|
719
|
-
declare class ConditionalNode extends DecoratorNodeComponent {
|
|
720
|
-
constructor();
|
|
721
|
-
conditionCode?: string;
|
|
722
|
-
shouldReevaluate: boolean;
|
|
723
|
-
/** 编译后的条件函数(不序列化) */
|
|
724
|
-
private compiledCondition?;
|
|
725
|
-
/**
|
|
726
|
-
* 评估条件
|
|
727
|
-
*/
|
|
728
|
-
evaluateCondition(entity: Entity, blackboard?: BlackboardComponent): boolean;
|
|
729
|
-
/**
|
|
730
|
-
* 设置条件函数(运行时使用)
|
|
731
|
-
*/
|
|
732
|
-
setConditionFunction(func: (entity: Entity, blackboard?: BlackboardComponent) => boolean): void;
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
/**
|
|
736
|
-
* 冷却节点
|
|
737
|
-
*
|
|
738
|
-
* 在冷却时间内阻止子节点执行
|
|
739
|
-
*/
|
|
740
|
-
declare class CooldownNode extends DecoratorNodeComponent {
|
|
741
|
-
constructor();
|
|
742
|
-
cooldownTime: number;
|
|
743
|
-
/** 上次执行时间 */
|
|
744
|
-
lastExecutionTime: number;
|
|
745
|
-
/**
|
|
746
|
-
* 检查是否可以执行
|
|
747
|
-
*/
|
|
748
|
-
canExecute(currentTime: number): boolean;
|
|
749
|
-
/**
|
|
750
|
-
* 记录执行时间
|
|
751
|
-
*/
|
|
752
|
-
recordExecution(currentTime: number): void;
|
|
753
|
-
/**
|
|
754
|
-
* 重置状态
|
|
755
|
-
*/
|
|
756
|
-
reset(): void;
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
/**
|
|
760
|
-
* 超时节点
|
|
761
|
-
*
|
|
762
|
-
* 子节点执行超时则返回失败
|
|
763
|
-
*/
|
|
764
|
-
declare class TimeoutNode extends DecoratorNodeComponent {
|
|
765
|
-
constructor();
|
|
766
|
-
timeoutDuration: number;
|
|
767
|
-
/** 开始执行时间 */
|
|
768
|
-
startTime: number;
|
|
769
|
-
/**
|
|
770
|
-
* 记录开始时间
|
|
771
|
-
*/
|
|
772
|
-
recordStartTime(currentTime: number): void;
|
|
773
|
-
/**
|
|
774
|
-
* 检查是否超时
|
|
775
|
-
*/
|
|
776
|
-
isTimeout(currentTime: number): boolean;
|
|
777
|
-
/**
|
|
778
|
-
* 重置状态
|
|
779
|
-
*/
|
|
780
|
-
reset(): void;
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
/**
|
|
784
|
-
* 行为树节点基础组件
|
|
785
|
-
*
|
|
786
|
-
* 所有行为树节点都必须包含此组件
|
|
787
|
-
*/
|
|
788
|
-
declare class BehaviorTreeNode extends Component {
|
|
789
|
-
/** 节点类型 */
|
|
790
|
-
nodeType: NodeType;
|
|
791
|
-
/** 节点名称(用于调试) */
|
|
792
|
-
nodeName: string;
|
|
793
|
-
/** 当前执行状态 */
|
|
794
|
-
status: TaskStatus;
|
|
795
|
-
/** 当前执行的子节点索引(用于复合节点) */
|
|
796
|
-
currentChildIndex: number;
|
|
797
|
-
/**
|
|
798
|
-
* 重置节点状态
|
|
799
|
-
*/
|
|
800
|
-
reset(): void;
|
|
801
|
-
/**
|
|
802
|
-
* 标记节点为失效(递归重置子节点)
|
|
803
|
-
* 注意:此方法只重置当前节点,子节点需要在 System 中处理
|
|
804
|
-
*/
|
|
805
|
-
invalidate(): void;
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
/**
|
|
809
|
-
* 活跃节点标记组件
|
|
810
|
-
*
|
|
811
|
-
* 标记当前应该被执行的节点。
|
|
812
|
-
* 只有带有此组件的节点才会被各个执行系统处理。
|
|
813
|
-
*
|
|
814
|
-
* 这是一个标记组件(Tag Component),不包含数据,只用于标识。
|
|
815
|
-
*
|
|
816
|
-
* 执行流程:
|
|
817
|
-
* 1. 初始时只有根节点带有 ActiveNode
|
|
818
|
-
* 2. 父节点决定激活哪个子节点时,为子节点添加 ActiveNode
|
|
819
|
-
* 3. 节点执行完成后移除 ActiveNode
|
|
820
|
-
* 4. 通过这种方式实现按需执行,避免每帧遍历整棵树
|
|
821
|
-
*/
|
|
822
|
-
declare class ActiveNode extends Component {
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
/**
|
|
826
|
-
* 属性绑定组件
|
|
827
|
-
* 记录节点属性到黑板变量的绑定关系
|
|
828
|
-
*/
|
|
829
|
-
declare class PropertyBindings extends Component {
|
|
830
|
-
/**
|
|
831
|
-
* 属性绑定映射
|
|
832
|
-
* key: 属性名称 (如 'message')
|
|
833
|
-
* value: 黑板变量名 (如 'test1')
|
|
834
|
-
*/
|
|
835
|
-
bindings: Map<string, string>;
|
|
836
|
-
/**
|
|
837
|
-
* 添加属性绑定
|
|
838
|
-
*/
|
|
839
|
-
addBinding(propertyName: string, blackboardKey: string): void;
|
|
840
|
-
/**
|
|
841
|
-
* 获取属性绑定的黑板变量名
|
|
842
|
-
*/
|
|
843
|
-
getBinding(propertyName: string): string | undefined;
|
|
844
|
-
/**
|
|
845
|
-
* 检查属性是否绑定到黑板变量
|
|
846
|
-
*/
|
|
847
|
-
hasBinding(propertyName: string): boolean;
|
|
848
|
-
/**
|
|
849
|
-
* 清除所有绑定
|
|
850
|
-
*/
|
|
851
|
-
clearBindings(): void;
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
/**
|
|
855
|
-
* 日志输出组件
|
|
856
|
-
*
|
|
857
|
-
* 存储运行时输出的日志信息,用于在UI中显示
|
|
858
|
-
*/
|
|
859
|
-
declare class LogOutput extends Component {
|
|
860
|
-
/**
|
|
861
|
-
* 日志消息列表
|
|
862
|
-
*/
|
|
863
|
-
messages: Array<{
|
|
864
|
-
timestamp: number;
|
|
865
|
-
message: string;
|
|
866
|
-
level: 'log' | 'info' | 'warn' | 'error';
|
|
867
|
-
}>;
|
|
868
|
-
/**
|
|
869
|
-
* 添加日志消息
|
|
870
|
-
*/
|
|
871
|
-
addMessage(message: string, level?: 'log' | 'info' | 'warn' | 'error'): void;
|
|
872
|
-
/**
|
|
873
|
-
* 清空日志
|
|
874
|
-
*/
|
|
875
|
-
clear(): void;
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
/**
|
|
879
|
-
* 资产元数据组件
|
|
880
|
-
*
|
|
881
|
-
* 附加到从资产实例化的行为树根节点上,
|
|
882
|
-
* 用于标记资产ID和版本信息,便于循环引用检测和调试。
|
|
883
|
-
*
|
|
884
|
-
* @example
|
|
885
|
-
* ```typescript
|
|
886
|
-
* const rootEntity = BehaviorTreeAssetLoader.instantiate(asset, scene);
|
|
887
|
-
*
|
|
888
|
-
* // 添加元数据
|
|
889
|
-
* const metadata = rootEntity.addComponent(new BehaviorTreeAssetMetadata());
|
|
890
|
-
* metadata.assetId = 'patrol';
|
|
891
|
-
* metadata.assetVersion = '1.0.0';
|
|
892
|
-
* ```
|
|
893
|
-
*/
|
|
894
|
-
declare class BehaviorTreeAssetMetadata extends Component {
|
|
895
|
-
/**
|
|
896
|
-
* 资产ID
|
|
897
|
-
*/
|
|
898
|
-
assetId: string;
|
|
899
|
-
/**
|
|
900
|
-
* 资产版本
|
|
901
|
-
*/
|
|
902
|
-
assetVersion: string;
|
|
903
|
-
/**
|
|
904
|
-
* 资产名称
|
|
905
|
-
*/
|
|
906
|
-
assetName: string;
|
|
907
|
-
/**
|
|
908
|
-
* 加载时间
|
|
909
|
-
*/
|
|
910
|
-
loadedAt: number;
|
|
911
|
-
/**
|
|
912
|
-
* 资产描述
|
|
913
|
-
*/
|
|
914
|
-
description: string;
|
|
915
|
-
/**
|
|
916
|
-
* 初始化
|
|
917
|
-
*/
|
|
918
|
-
initialize(assetId: string, assetVersion: string, assetName?: string): void;
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
/**
|
|
922
|
-
* 根节点
|
|
923
|
-
*
|
|
924
|
-
* 行为树的根节点,简单地激活第一个子节点
|
|
925
|
-
*/
|
|
926
|
-
declare class RootNode extends CompositeNodeComponent {
|
|
927
|
-
constructor();
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
/**
|
|
931
|
-
* 根节点执行系统
|
|
932
|
-
*
|
|
933
|
-
* 专门处理根节点的执行逻辑
|
|
934
|
-
* 根节点的职责:
|
|
935
|
-
* 1. 扫描并预加载所有标记为 preload=true 的子树
|
|
936
|
-
* 2. 激活第一个子节点,并根据子节点的状态来设置自己的状态
|
|
937
|
-
*
|
|
938
|
-
* updateOrder: 350 (在所有其他执行系统之后)
|
|
939
|
-
*/
|
|
940
|
-
declare class RootExecutionSystem extends EntitySystem {
|
|
941
|
-
/** 跟踪每个根节点的预加载状态 */
|
|
942
|
-
private preloadStates;
|
|
943
|
-
/** 跟踪预加载任务 */
|
|
944
|
-
private preloadTasks;
|
|
945
|
-
/** AssetLoader 实例 */
|
|
946
|
-
private assetLoader?;
|
|
947
|
-
constructor();
|
|
948
|
-
protected process(entities: readonly Entity[]): void;
|
|
949
|
-
/**
|
|
950
|
-
* 执行根节点逻辑
|
|
951
|
-
*/
|
|
952
|
-
private executeRoot;
|
|
953
|
-
/**
|
|
954
|
-
* 开始预加载子树
|
|
955
|
-
*/
|
|
956
|
-
private startPreload;
|
|
957
|
-
/**
|
|
958
|
-
* 扫描所有需要预加载的子树节点
|
|
959
|
-
*/
|
|
960
|
-
private scanSubTreeNodes;
|
|
961
|
-
/**
|
|
962
|
-
* 预加载所有子树
|
|
963
|
-
*/
|
|
964
|
-
private preloadAllSubTrees;
|
|
965
|
-
/**
|
|
966
|
-
* 预加载单个子树
|
|
967
|
-
*/
|
|
968
|
-
private preloadSingleSubTree;
|
|
969
|
-
/**
|
|
970
|
-
* 设置黑板继承
|
|
971
|
-
*/
|
|
972
|
-
private setupBlackboardInheritance;
|
|
973
|
-
/**
|
|
974
|
-
* 查找黑板组件
|
|
975
|
-
*/
|
|
976
|
-
private findBlackboard;
|
|
977
|
-
/**
|
|
978
|
-
* 查找根实体
|
|
979
|
-
*/
|
|
980
|
-
private findRootEntity;
|
|
981
|
-
/**
|
|
982
|
-
* 统一的日志输出方法
|
|
983
|
-
*/
|
|
984
|
-
private outputLog;
|
|
985
|
-
/**
|
|
986
|
-
* 递归打印子树结构(用于调试)
|
|
987
|
-
*/
|
|
988
|
-
private logSubTreeStructure;
|
|
989
|
-
/**
|
|
990
|
-
* 清理资源
|
|
991
|
-
*/
|
|
992
|
-
protected onDestroy(): void;
|
|
993
|
-
protected getLoggerName(): string;
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
/**
|
|
997
|
-
* 叶子节点执行系统
|
|
998
|
-
*
|
|
999
|
-
* 负责执行所有活跃的叶子节点(Action 和 Condition)
|
|
1000
|
-
* 只处理带有 ActiveNode 标记的节点
|
|
1001
|
-
*
|
|
1002
|
-
* updateOrder: 100 (最先执行)
|
|
1003
|
-
*/
|
|
1004
|
-
declare class LeafExecutionSystem extends EntitySystem {
|
|
1005
|
-
constructor();
|
|
1006
|
-
protected process(entities: readonly Entity[]): void;
|
|
1007
|
-
/**
|
|
1008
|
-
* 执行动作节点
|
|
1009
|
-
*/
|
|
1010
|
-
private executeAction;
|
|
1011
|
-
/**
|
|
1012
|
-
* 执行等待动作
|
|
1013
|
-
*/
|
|
1014
|
-
private executeWaitAction;
|
|
1015
|
-
/**
|
|
1016
|
-
* 执行日志动作
|
|
1017
|
-
*/
|
|
1018
|
-
private executeLogAction;
|
|
1019
|
-
/**
|
|
1020
|
-
* 查找根实体
|
|
1021
|
-
*/
|
|
1022
|
-
private findRootEntity;
|
|
1023
|
-
/**
|
|
1024
|
-
* 执行设置黑板变量值
|
|
1025
|
-
*/
|
|
1026
|
-
private executeSetBlackboardValue;
|
|
1027
|
-
/**
|
|
1028
|
-
* 执行修改黑板变量值
|
|
1029
|
-
*/
|
|
1030
|
-
private executeModifyBlackboardValue;
|
|
1031
|
-
/**
|
|
1032
|
-
* 执行自定义动作
|
|
1033
|
-
*/
|
|
1034
|
-
private executeCustomAction;
|
|
1035
|
-
/**
|
|
1036
|
-
* 执行条件节点
|
|
1037
|
-
*/
|
|
1038
|
-
private executeCondition;
|
|
1039
|
-
/**
|
|
1040
|
-
* 评估黑板比较条件
|
|
1041
|
-
*/
|
|
1042
|
-
private evaluateBlackboardCompare;
|
|
1043
|
-
/**
|
|
1044
|
-
* 评估黑板变量存在性
|
|
1045
|
-
*/
|
|
1046
|
-
private evaluateBlackboardExists;
|
|
1047
|
-
/**
|
|
1048
|
-
* 评估随机概率
|
|
1049
|
-
*/
|
|
1050
|
-
private evaluateRandomProbability;
|
|
1051
|
-
/**
|
|
1052
|
-
* 评估自定义条件
|
|
1053
|
-
*/
|
|
1054
|
-
private evaluateCustomCondition;
|
|
1055
|
-
/**
|
|
1056
|
-
* 解析属性值
|
|
1057
|
-
* 如果属性绑定到黑板变量,从黑板读取最新值
|
|
1058
|
-
*/
|
|
1059
|
-
private resolvePropertyValue;
|
|
1060
|
-
/**
|
|
1061
|
-
* 移除节点的活跃标记
|
|
1062
|
-
*/
|
|
1063
|
-
private deactivateNode;
|
|
1064
|
-
/**
|
|
1065
|
-
* 通知父节点子节点已完成
|
|
1066
|
-
*/
|
|
1067
|
-
private notifyParent;
|
|
1068
|
-
/**
|
|
1069
|
-
* 查找黑板组件(向上遍历父节点)
|
|
1070
|
-
*/
|
|
1071
|
-
private findBlackboard;
|
|
1072
|
-
/**
|
|
1073
|
-
* 从Entity提取节点显示名称和ID
|
|
1074
|
-
*/
|
|
1075
|
-
private getNodeInfo;
|
|
1076
|
-
/**
|
|
1077
|
-
* 统一的日志输出方法
|
|
1078
|
-
* 同时输出到控制台和LogOutput组件,确保用户在UI中能看到
|
|
1079
|
-
*/
|
|
1080
|
-
private outputLog;
|
|
1081
|
-
protected getLoggerName(): string;
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
/**
|
|
1085
|
-
* 装饰器节点执行系统
|
|
1086
|
-
*
|
|
1087
|
-
* 负责处理所有活跃的装饰器节点
|
|
1088
|
-
* 读取子节点状态,根据装饰器规则决定自己的状态
|
|
1089
|
-
*
|
|
1090
|
-
* updateOrder: 200 (在叶子节点之后执行)
|
|
1091
|
-
*/
|
|
1092
|
-
declare class DecoratorExecutionSystem extends EntitySystem {
|
|
1093
|
-
constructor();
|
|
1094
|
-
protected process(entities: readonly Entity[]): void;
|
|
1095
|
-
/**
|
|
1096
|
-
* 执行装饰器逻辑
|
|
1097
|
-
*/
|
|
1098
|
-
private executeDecorator;
|
|
1099
|
-
/**
|
|
1100
|
-
* 反转装饰器
|
|
1101
|
-
*/
|
|
1102
|
-
private handleInverter;
|
|
1103
|
-
/**
|
|
1104
|
-
* 重复装饰器
|
|
1105
|
-
*/
|
|
1106
|
-
private handleRepeater;
|
|
1107
|
-
/**
|
|
1108
|
-
* 直到成功装饰器
|
|
1109
|
-
*/
|
|
1110
|
-
private handleUntilSuccess;
|
|
1111
|
-
/**
|
|
1112
|
-
* 直到失败装饰器
|
|
1113
|
-
*/
|
|
1114
|
-
private handleUntilFail;
|
|
1115
|
-
/**
|
|
1116
|
-
* 总是成功装饰器
|
|
1117
|
-
*/
|
|
1118
|
-
private handleAlwaysSucceed;
|
|
1119
|
-
/**
|
|
1120
|
-
* 总是失败装饰器
|
|
1121
|
-
*/
|
|
1122
|
-
private handleAlwaysFail;
|
|
1123
|
-
/**
|
|
1124
|
-
* 条件装饰器
|
|
1125
|
-
*/
|
|
1126
|
-
private handleConditional;
|
|
1127
|
-
/**
|
|
1128
|
-
* 冷却装饰器
|
|
1129
|
-
*/
|
|
1130
|
-
private handleCooldown;
|
|
1131
|
-
/**
|
|
1132
|
-
* 超时装饰器
|
|
1133
|
-
*/
|
|
1134
|
-
private handleTimeout;
|
|
1135
|
-
/**
|
|
1136
|
-
* 完成节点执行
|
|
1137
|
-
*/
|
|
1138
|
-
private completeNode;
|
|
1139
|
-
/**
|
|
1140
|
-
* 查找黑板组件(向上遍历父节点)
|
|
1141
|
-
*/
|
|
1142
|
-
private findBlackboard;
|
|
1143
|
-
/**
|
|
1144
|
-
* 解析属性值
|
|
1145
|
-
* 如果属性绑定到黑板变量,从黑板读取最新值
|
|
1146
|
-
*/
|
|
1147
|
-
private resolvePropertyValue;
|
|
1148
|
-
/**
|
|
1149
|
-
* 查找根实体
|
|
1150
|
-
*/
|
|
1151
|
-
private findRootEntity;
|
|
1152
|
-
/**
|
|
1153
|
-
* 统一的日志输出方法
|
|
1154
|
-
* 同时输出到控制台和LogOutput组件,确保用户在UI中能看到
|
|
1155
|
-
*/
|
|
1156
|
-
private outputLog;
|
|
1157
|
-
protected getLoggerName(): string;
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
/**
|
|
1161
|
-
* 复合节点执行系统
|
|
1162
|
-
*
|
|
1163
|
-
* 负责处理所有活跃的复合节点
|
|
1164
|
-
* 读取子节点状态,根据复合规则决定自己的状态和激活哪些子节点
|
|
1165
|
-
*
|
|
1166
|
-
* updateOrder: 300 (在叶子节点和装饰器之后执行)
|
|
1167
|
-
*/
|
|
1168
|
-
declare class CompositeExecutionSystem extends EntitySystem {
|
|
1169
|
-
constructor();
|
|
1170
|
-
protected process(entities: readonly Entity[]): void;
|
|
1171
|
-
/**
|
|
1172
|
-
* 执行复合节点逻辑
|
|
1173
|
-
*/
|
|
1174
|
-
private executeComposite;
|
|
1175
|
-
/**
|
|
1176
|
-
* 序列节点:所有子节点都成功才成功
|
|
1177
|
-
*/
|
|
1178
|
-
private handleSequence;
|
|
1179
|
-
/**
|
|
1180
|
-
* 选择器节点:任一子节点成功就成功
|
|
1181
|
-
*/
|
|
1182
|
-
private handleSelector;
|
|
1183
|
-
/**
|
|
1184
|
-
* 并行节点:所有子节点都执行,全部成功才成功
|
|
1185
|
-
*/
|
|
1186
|
-
private handleParallel;
|
|
1187
|
-
/**
|
|
1188
|
-
* 并行选择器:任一成功则成功
|
|
1189
|
-
*/
|
|
1190
|
-
private handleParallelSelector;
|
|
1191
|
-
/**
|
|
1192
|
-
* 随机序列
|
|
1193
|
-
*/
|
|
1194
|
-
private handleRandomSequence;
|
|
1195
|
-
/**
|
|
1196
|
-
* 随机选择器
|
|
1197
|
-
*/
|
|
1198
|
-
private handleRandomSelector;
|
|
1199
|
-
/**
|
|
1200
|
-
* 检查是否应该中止当前执行
|
|
1201
|
-
*/
|
|
1202
|
-
private shouldAbort;
|
|
1203
|
-
/**
|
|
1204
|
-
* 评估条件节点
|
|
1205
|
-
*/
|
|
1206
|
-
private evaluateCondition;
|
|
1207
|
-
/**
|
|
1208
|
-
* 评估黑板比较条件
|
|
1209
|
-
*/
|
|
1210
|
-
private evaluateBlackboardCompare;
|
|
1211
|
-
/**
|
|
1212
|
-
* 评估黑板变量存在性
|
|
1213
|
-
*/
|
|
1214
|
-
private evaluateBlackboardExists;
|
|
1215
|
-
/**
|
|
1216
|
-
* 评估随机概率
|
|
1217
|
-
*/
|
|
1218
|
-
private evaluateRandomProbability;
|
|
1219
|
-
/**
|
|
1220
|
-
* 评估自定义条件
|
|
1221
|
-
*/
|
|
1222
|
-
private evaluateCustomCondition;
|
|
1223
|
-
/**
|
|
1224
|
-
* 解析字符串中的变量引用
|
|
1225
|
-
*/
|
|
1226
|
-
private resolveVariableReferences;
|
|
1227
|
-
/**
|
|
1228
|
-
* 查找黑板组件
|
|
1229
|
-
*/
|
|
1230
|
-
private findBlackboard;
|
|
1231
|
-
/**
|
|
1232
|
-
* 中止当前执行
|
|
1233
|
-
*/
|
|
1234
|
-
private abortExecution;
|
|
1235
|
-
/**
|
|
1236
|
-
* 递归停用节点及其所有子节点
|
|
1237
|
-
*/
|
|
1238
|
-
private deactivateNode;
|
|
1239
|
-
/**
|
|
1240
|
-
* 递归重置所有子节点的状态
|
|
1241
|
-
*/
|
|
1242
|
-
private resetAllChildren;
|
|
1243
|
-
/**
|
|
1244
|
-
* 完成节点执行
|
|
1245
|
-
*/
|
|
1246
|
-
private completeNode;
|
|
1247
|
-
protected getLoggerName(): string;
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
/**
|
|
1251
|
-
* 资产加载状态
|
|
1252
|
-
*/
|
|
1253
|
-
declare enum LoadingState {
|
|
1254
|
-
/** 未开始 */
|
|
1255
|
-
Idle = "idle",
|
|
1256
|
-
/** 即将开始 */
|
|
1257
|
-
Pending = "pending",
|
|
1258
|
-
/** 加载中 */
|
|
1259
|
-
Loading = "loading",
|
|
1260
|
-
/** 加载成功 */
|
|
1261
|
-
Loaded = "loaded",
|
|
1262
|
-
/** 加载失败 */
|
|
1263
|
-
Failed = "failed",
|
|
1264
|
-
/** 加载超时 */
|
|
1265
|
-
Timeout = "timeout",
|
|
1266
|
-
/** 已取消 */
|
|
1267
|
-
Cancelled = "cancelled"
|
|
1268
|
-
}
|
|
1269
|
-
/**
|
|
1270
|
-
* 加载任务
|
|
1271
|
-
*/
|
|
1272
|
-
interface LoadingTask {
|
|
1273
|
-
/** 资产ID */
|
|
1274
|
-
assetId: string;
|
|
1275
|
-
/** 加载Promise */
|
|
1276
|
-
promise: Promise<Entity>;
|
|
1277
|
-
/** 开始时间 */
|
|
1278
|
-
startTime: number;
|
|
1279
|
-
/** 上次重试时间 */
|
|
1280
|
-
lastRetryTime: number;
|
|
1281
|
-
/** 当前重试次数 */
|
|
1282
|
-
retryCount: number;
|
|
1283
|
-
/** 最大重试次数 */
|
|
1284
|
-
maxRetries: number;
|
|
1285
|
-
/** 超时时间(毫秒) */
|
|
1286
|
-
timeoutMs: number;
|
|
1287
|
-
/** 当前状态 */
|
|
1288
|
-
state: LoadingState;
|
|
1289
|
-
/** 错误信息 */
|
|
1290
|
-
error?: Error;
|
|
1291
|
-
/** 父实体ID */
|
|
1292
|
-
parentEntityId: number;
|
|
1293
|
-
/** 父实体引用(需要在使用前检查isDestroyed) */
|
|
1294
|
-
parentEntity: Entity;
|
|
1295
|
-
/** 父资产ID(用于循环检测) */
|
|
1296
|
-
parentAssetId?: string;
|
|
1297
|
-
/** 加载结果(缓存) */
|
|
1298
|
-
result?: Entity;
|
|
1299
|
-
}
|
|
1300
|
-
/**
|
|
1301
|
-
* 加载任务句柄
|
|
1302
|
-
*/
|
|
1303
|
-
interface LoadingTaskHandle {
|
|
1304
|
-
/** 资产ID */
|
|
1305
|
-
assetId: string;
|
|
1306
|
-
/** 获取当前状态 */
|
|
1307
|
-
getState(): LoadingState;
|
|
1308
|
-
/** 获取错误信息 */
|
|
1309
|
-
getError(): Error | undefined;
|
|
1310
|
-
/** 获取加载进度信息 */
|
|
1311
|
-
getProgress(): LoadingProgress;
|
|
1312
|
-
/** 取消加载 */
|
|
1313
|
-
cancel(): void;
|
|
1314
|
-
/** 加载Promise */
|
|
1315
|
-
promise: Promise<Entity>;
|
|
1316
|
-
}
|
|
1317
|
-
/**
|
|
1318
|
-
* 加载进度信息
|
|
1319
|
-
*/
|
|
1320
|
-
interface LoadingProgress {
|
|
1321
|
-
/** 当前状态 */
|
|
1322
|
-
state: LoadingState;
|
|
1323
|
-
/** 已耗时(毫秒) */
|
|
1324
|
-
elapsedMs: number;
|
|
1325
|
-
/** 剩余超时时间(毫秒) */
|
|
1326
|
-
remainingTimeoutMs: number;
|
|
1327
|
-
/** 当前重试次数 */
|
|
1328
|
-
retryCount: number;
|
|
1329
|
-
/** 最大重试次数 */
|
|
1330
|
-
maxRetries: number;
|
|
1331
|
-
}
|
|
1332
|
-
/**
|
|
1333
|
-
* 加载选项
|
|
1334
|
-
*/
|
|
1335
|
-
interface LoadingOptions {
|
|
1336
|
-
/** 超时时间(毫秒),默认5000 */
|
|
1337
|
-
timeoutMs?: number;
|
|
1338
|
-
/** 最大重试次数,默认3 */
|
|
1339
|
-
maxRetries?: number;
|
|
1340
|
-
/** 父资产ID(用于循环检测) */
|
|
1341
|
-
parentAssetId?: string;
|
|
1342
|
-
/** 重试延迟基数(毫秒),默认100 */
|
|
1343
|
-
retryDelayBase?: number;
|
|
1344
|
-
/** 最大重试延迟(毫秒),默认2000 */
|
|
1345
|
-
maxRetryDelay?: number;
|
|
1346
|
-
}
|
|
1347
|
-
/**
|
|
1348
|
-
* 超时错误
|
|
1349
|
-
*/
|
|
1350
|
-
declare class TimeoutError extends Error {
|
|
1351
|
-
constructor(message: string);
|
|
1352
|
-
}
|
|
1353
|
-
/**
|
|
1354
|
-
* 循环依赖错误
|
|
1355
|
-
*/
|
|
1356
|
-
declare class CircularDependencyError extends Error {
|
|
1357
|
-
constructor(message: string);
|
|
1358
|
-
}
|
|
1359
|
-
/**
|
|
1360
|
-
* 实体已销毁错误
|
|
1361
|
-
*/
|
|
1362
|
-
declare class EntityDestroyedError extends Error {
|
|
1363
|
-
constructor(message: string);
|
|
1364
|
-
}
|
|
1365
|
-
|
|
1366
|
-
/**
|
|
1367
|
-
* 资产加载管理器
|
|
1368
|
-
*
|
|
1369
|
-
* 统一管理行为树资产的异步加载,提供:
|
|
1370
|
-
* - 超时检测和自动重试
|
|
1371
|
-
* - 循环引用检测
|
|
1372
|
-
* - 实体生命周期安全
|
|
1373
|
-
* - 加载状态追踪
|
|
1374
|
-
*
|
|
1375
|
-
* @example
|
|
1376
|
-
* ```typescript
|
|
1377
|
-
* const manager = new AssetLoadingManager();
|
|
1378
|
-
*
|
|
1379
|
-
* const handle = manager.startLoading(
|
|
1380
|
-
* 'patrol',
|
|
1381
|
-
* parentEntity,
|
|
1382
|
-
* () => assetLoader.loadBehaviorTree('patrol'),
|
|
1383
|
-
* { timeoutMs: 5000, maxRetries: 3 }
|
|
1384
|
-
* );
|
|
1385
|
-
*
|
|
1386
|
-
* // 在系统的 process() 中轮询检查
|
|
1387
|
-
* const state = handle.getState();
|
|
1388
|
-
* if (state === LoadingState.Loaded) {
|
|
1389
|
-
* const entity = await handle.promise;
|
|
1390
|
-
* // 使用加载的实体
|
|
1391
|
-
* }
|
|
1392
|
-
* ```
|
|
1393
|
-
*/
|
|
1394
|
-
declare class AssetLoadingManager implements IService {
|
|
1395
|
-
/** 正在进行的加载任务 */
|
|
1396
|
-
private tasks;
|
|
1397
|
-
/** 加载栈(用于循环检测) */
|
|
1398
|
-
private loadingStack;
|
|
1399
|
-
/** 默认配置 */
|
|
1400
|
-
private defaultOptions;
|
|
1401
|
-
/**
|
|
1402
|
-
* 开始加载资产
|
|
1403
|
-
*
|
|
1404
|
-
* @param assetId 资产ID
|
|
1405
|
-
* @param parentEntity 父实体(用于生命周期检查)
|
|
1406
|
-
* @param loader 加载函数
|
|
1407
|
-
* @param options 加载选项
|
|
1408
|
-
* @returns 加载任务句柄
|
|
1409
|
-
*/
|
|
1410
|
-
startLoading(assetId: string, parentEntity: Entity, loader: () => Promise<Entity>, options?: LoadingOptions): LoadingTaskHandle;
|
|
1411
|
-
/**
|
|
1412
|
-
* 带超时和重试的加载
|
|
1413
|
-
*/
|
|
1414
|
-
private loadWithTimeoutAndRetry;
|
|
1415
|
-
/**
|
|
1416
|
-
* Promise 超时包装
|
|
1417
|
-
*/
|
|
1418
|
-
private withTimeout;
|
|
1419
|
-
/**
|
|
1420
|
-
* 循环依赖检测
|
|
1421
|
-
*/
|
|
1422
|
-
private detectCircularDependency;
|
|
1423
|
-
/**
|
|
1424
|
-
* 获取任务状态
|
|
1425
|
-
*/
|
|
1426
|
-
getTaskState(assetId: string): LoadingState;
|
|
1427
|
-
/**
|
|
1428
|
-
* 获取任务
|
|
1429
|
-
*/
|
|
1430
|
-
getTask(assetId: string): LoadingTask | undefined;
|
|
1431
|
-
/**
|
|
1432
|
-
* 取消加载
|
|
1433
|
-
*/
|
|
1434
|
-
cancelLoading(assetId: string): void;
|
|
1435
|
-
/**
|
|
1436
|
-
* 清理任务
|
|
1437
|
-
*/
|
|
1438
|
-
private cleanup;
|
|
1439
|
-
/**
|
|
1440
|
-
* 延迟
|
|
1441
|
-
*/
|
|
1442
|
-
private delay;
|
|
1443
|
-
/**
|
|
1444
|
-
* 创建任务句柄
|
|
1445
|
-
*/
|
|
1446
|
-
private createHandle;
|
|
1447
|
-
/**
|
|
1448
|
-
* 获取所有正在加载的资产
|
|
1449
|
-
*/
|
|
1450
|
-
getLoadingAssets(): string[];
|
|
1451
|
-
/**
|
|
1452
|
-
* 获取加载统计信息
|
|
1453
|
-
*/
|
|
1454
|
-
getStats(): {
|
|
1455
|
-
totalTasks: number;
|
|
1456
|
-
loadingTasks: number;
|
|
1457
|
-
failedTasks: number;
|
|
1458
|
-
timeoutTasks: number;
|
|
1459
|
-
};
|
|
1460
|
-
/**
|
|
1461
|
-
* 清空所有任务
|
|
1462
|
-
*/
|
|
1463
|
-
clear(): void;
|
|
1464
|
-
/**
|
|
1465
|
-
* 释放资源
|
|
1466
|
-
*/
|
|
1467
|
-
dispose(): void;
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
|
-
/**
|
|
1471
|
-
* SubTree 执行系统
|
|
1472
|
-
*
|
|
1473
|
-
* 处理 SubTree 节点的执行,包括:
|
|
1474
|
-
* - 子树资产加载
|
|
1475
|
-
* - 子树实例化
|
|
1476
|
-
* - 黑板继承
|
|
1477
|
-
* - 子树执行和状态管理
|
|
1478
|
-
*
|
|
1479
|
-
* updateOrder: 300 (与 CompositeExecutionSystem 同级)
|
|
1480
|
-
*/
|
|
1481
|
-
declare class SubTreeExecutionSystem extends EntitySystem {
|
|
1482
|
-
private assetLoader?;
|
|
1483
|
-
private assetLoaderInitialized;
|
|
1484
|
-
private hasLoggedMissingAssetLoader;
|
|
1485
|
-
private loadingManager;
|
|
1486
|
-
private loadingTasks;
|
|
1487
|
-
constructor(loadingManager?: AssetLoadingManager);
|
|
1488
|
-
protected onInitialize(): void;
|
|
1489
|
-
protected process(entities: readonly Entity[]): void;
|
|
1490
|
-
/**
|
|
1491
|
-
* 执行子树节点
|
|
1492
|
-
*/
|
|
1493
|
-
private executeSubTree;
|
|
1494
|
-
/**
|
|
1495
|
-
* 延迟初始化 AssetLoader
|
|
1496
|
-
*/
|
|
1497
|
-
private ensureAssetLoaderInitialized;
|
|
1498
|
-
/**
|
|
1499
|
-
* 加载并实例化子树(使用加载管理器)
|
|
1500
|
-
*/
|
|
1501
|
-
private loadAndInstantiateSubTree;
|
|
1502
|
-
/**
|
|
1503
|
-
* 开始新的加载任务
|
|
1504
|
-
*/
|
|
1505
|
-
private startNewLoading;
|
|
1506
|
-
/**
|
|
1507
|
-
* 加载完成时的处理
|
|
1508
|
-
*/
|
|
1509
|
-
private onLoadingComplete;
|
|
1510
|
-
/**
|
|
1511
|
-
* 加载资产
|
|
1512
|
-
*/
|
|
1513
|
-
private loadAsset;
|
|
1514
|
-
/**
|
|
1515
|
-
* 设置黑板继承
|
|
1516
|
-
*/
|
|
1517
|
-
private setupBlackboardInheritance;
|
|
1518
|
-
/**
|
|
1519
|
-
* 查找黑板
|
|
1520
|
-
*/
|
|
1521
|
-
private findBlackboard;
|
|
1522
|
-
/**
|
|
1523
|
-
* 开始子树执行
|
|
1524
|
-
*/
|
|
1525
|
-
private startSubTreeExecution;
|
|
1526
|
-
/**
|
|
1527
|
-
* 更新子树状态
|
|
1528
|
-
*/
|
|
1529
|
-
private updateSubTree;
|
|
1530
|
-
/**
|
|
1531
|
-
* 子树完成时的处理
|
|
1532
|
-
*/
|
|
1533
|
-
private onSubTreeCompleted;
|
|
1534
|
-
/**
|
|
1535
|
-
* 清理子树
|
|
1536
|
-
*/
|
|
1537
|
-
private cleanupSubTree;
|
|
1538
|
-
/**
|
|
1539
|
-
* 递归重置子树的所有节点
|
|
1540
|
-
*/
|
|
1541
|
-
private resetSubTreeRecursively;
|
|
1542
|
-
/**
|
|
1543
|
-
* 完成节点执行
|
|
1544
|
-
*/
|
|
1545
|
-
private completeNode;
|
|
1546
|
-
/**
|
|
1547
|
-
* 获取父树的资产ID(用于循环检测)
|
|
1548
|
-
*/
|
|
1549
|
-
private getParentTreeAssetId;
|
|
1550
|
-
/**
|
|
1551
|
-
* 系统销毁时清理
|
|
1552
|
-
*/
|
|
1553
|
-
protected onDestroy(): void;
|
|
1554
|
-
/**
|
|
1555
|
-
* 查找根实体
|
|
1556
|
-
*/
|
|
1557
|
-
private findRootEntity;
|
|
1558
|
-
/**
|
|
1559
|
-
* 统一的日志输出方法
|
|
1560
|
-
* 同时输出到控制台和LogOutput组件,确保用户在UI中能看到
|
|
1561
|
-
*/
|
|
1562
|
-
private outputLog;
|
|
1563
|
-
/**
|
|
1564
|
-
* 递归打印子树结构(用于调试)
|
|
1565
|
-
*/
|
|
1566
|
-
private logSubTreeStructure;
|
|
1567
|
-
protected getLoggerName(): string;
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
/**
|
|
1571
|
-
* 资产类型
|
|
1572
|
-
*/
|
|
1573
|
-
declare enum AssetType {
|
|
1574
|
-
BehaviorTree = "behavior-tree",
|
|
1575
|
-
Blackboard = "blackboard",
|
|
1576
|
-
Unknown = "unknown"
|
|
1577
|
-
}
|
|
1578
|
-
/**
|
|
1579
|
-
* 资产注册信息
|
|
1580
|
-
*/
|
|
1581
|
-
interface AssetRegistry {
|
|
1582
|
-
/** 资产唯一ID */
|
|
1583
|
-
id: string;
|
|
1584
|
-
/** 资产名称 */
|
|
1585
|
-
name: string;
|
|
1586
|
-
/** 资产相对路径(相对于工作区根目录) */
|
|
1587
|
-
path: string;
|
|
1588
|
-
/** 资产类型 */
|
|
1589
|
-
type: AssetType;
|
|
1590
|
-
/** 依赖的其他资产ID列表 */
|
|
1591
|
-
dependencies: string[];
|
|
1592
|
-
/** 最后修改时间 */
|
|
1593
|
-
lastModified?: number;
|
|
1594
|
-
/** 资产元数据 */
|
|
1595
|
-
metadata?: Record<string, any>;
|
|
1596
|
-
}
|
|
1597
|
-
/**
|
|
1598
|
-
* 工作区配置
|
|
1599
|
-
*/
|
|
1600
|
-
interface WorkspaceConfig {
|
|
1601
|
-
/** 工作区名称 */
|
|
1602
|
-
name: string;
|
|
1603
|
-
/** 工作区版本 */
|
|
1604
|
-
version: string;
|
|
1605
|
-
/** 工作区根目录(绝对路径) */
|
|
1606
|
-
rootPath: string;
|
|
1607
|
-
/** 资产目录配置 */
|
|
1608
|
-
assetPaths: {
|
|
1609
|
-
/** 行为树目录 */
|
|
1610
|
-
behaviorTrees: string;
|
|
1611
|
-
/** 黑板目录 */
|
|
1612
|
-
blackboards: string;
|
|
1613
|
-
};
|
|
1614
|
-
/** 资产注册表 */
|
|
1615
|
-
assets: AssetRegistry[];
|
|
1616
|
-
}
|
|
1617
|
-
/**
|
|
1618
|
-
* 工作区服务
|
|
1619
|
-
*
|
|
1620
|
-
* 管理项目的工作区配置和资产注册表,提供:
|
|
1621
|
-
* - 工作区配置的加载和保存
|
|
1622
|
-
* - 资产注册和查询
|
|
1623
|
-
* - 依赖关系追踪
|
|
1624
|
-
* - 循环依赖检测
|
|
1625
|
-
*/
|
|
1626
|
-
declare class WorkspaceService implements IService {
|
|
1627
|
-
private config;
|
|
1628
|
-
private assetMap;
|
|
1629
|
-
private assetPathMap;
|
|
1630
|
-
/**
|
|
1631
|
-
* 初始化工作区
|
|
1632
|
-
*/
|
|
1633
|
-
initialize(config: WorkspaceConfig): void;
|
|
1634
|
-
/**
|
|
1635
|
-
* 重建资产映射表
|
|
1636
|
-
*/
|
|
1637
|
-
private rebuildAssetMaps;
|
|
1638
|
-
/**
|
|
1639
|
-
* 获取工作区配置
|
|
1640
|
-
*/
|
|
1641
|
-
getConfig(): WorkspaceConfig | null;
|
|
1642
|
-
/**
|
|
1643
|
-
* 更新工作区配置
|
|
1644
|
-
*/
|
|
1645
|
-
updateConfig(config: WorkspaceConfig): void;
|
|
1646
|
-
/**
|
|
1647
|
-
* 注册资产
|
|
1648
|
-
*/
|
|
1649
|
-
registerAsset(asset: AssetRegistry): void;
|
|
1650
|
-
/**
|
|
1651
|
-
* 取消注册资产
|
|
1652
|
-
*/
|
|
1653
|
-
unregisterAsset(assetId: string): void;
|
|
1654
|
-
/**
|
|
1655
|
-
* 通过ID获取资产
|
|
1656
|
-
*/
|
|
1657
|
-
getAssetById(assetId: string): AssetRegistry | undefined;
|
|
1658
|
-
/**
|
|
1659
|
-
* 通过路径获取资产
|
|
1660
|
-
*/
|
|
1661
|
-
getAssetByPath(path: string): AssetRegistry | undefined;
|
|
1662
|
-
/**
|
|
1663
|
-
* 获取所有资产
|
|
1664
|
-
*/
|
|
1665
|
-
getAllAssets(): AssetRegistry[];
|
|
1666
|
-
/**
|
|
1667
|
-
* 按类型获取资产
|
|
1668
|
-
*/
|
|
1669
|
-
getAssetsByType(type: AssetType): AssetRegistry[];
|
|
1670
|
-
/**
|
|
1671
|
-
* 获取行为树资产列表
|
|
1672
|
-
*/
|
|
1673
|
-
getBehaviorTreeAssets(): AssetRegistry[];
|
|
1674
|
-
/**
|
|
1675
|
-
* 获取黑板资产列表
|
|
1676
|
-
*/
|
|
1677
|
-
getBlackboardAssets(): AssetRegistry[];
|
|
1678
|
-
/**
|
|
1679
|
-
* 获取资产的所有依赖(递归)
|
|
1680
|
-
*/
|
|
1681
|
-
getAssetDependencies(assetId: string, visited?: Set<string>): AssetRegistry[];
|
|
1682
|
-
/**
|
|
1683
|
-
* 检测循环依赖
|
|
1684
|
-
*
|
|
1685
|
-
* @param assetId 要检查的资产ID
|
|
1686
|
-
* @returns 如果存在循环依赖,返回循环路径;否则返回 null
|
|
1687
|
-
*/
|
|
1688
|
-
detectCircularDependency(assetId: string): string[] | null;
|
|
1689
|
-
/**
|
|
1690
|
-
* 检查是否可以添加依赖(不会造成循环依赖)
|
|
1691
|
-
*
|
|
1692
|
-
* @param assetId 资产ID
|
|
1693
|
-
* @param dependencyId 要添加的依赖ID
|
|
1694
|
-
* @returns 是否可以安全添加
|
|
1695
|
-
*/
|
|
1696
|
-
canAddDependency(assetId: string, dependencyId: string): boolean;
|
|
1697
|
-
/**
|
|
1698
|
-
* 添加资产依赖
|
|
1699
|
-
*/
|
|
1700
|
-
addAssetDependency(assetId: string, dependencyId: string): boolean;
|
|
1701
|
-
/**
|
|
1702
|
-
* 移除资产依赖
|
|
1703
|
-
*/
|
|
1704
|
-
removeAssetDependency(assetId: string, dependencyId: string): void;
|
|
1705
|
-
/**
|
|
1706
|
-
* 解析资产路径(支持相对路径和绝对路径)
|
|
1707
|
-
*/
|
|
1708
|
-
resolveAssetPath(path: string): string;
|
|
1709
|
-
/**
|
|
1710
|
-
* 获取资产的相对路径
|
|
1711
|
-
*/
|
|
1712
|
-
getRelativePath(absolutePath: string): string;
|
|
1713
|
-
/**
|
|
1714
|
-
* 清理资源
|
|
1715
|
-
*/
|
|
1716
|
-
dispose(): void;
|
|
1717
|
-
}
|
|
1718
|
-
|
|
1719
|
-
/**
|
|
1720
|
-
* 行为树资产元数据
|
|
1721
|
-
*/
|
|
1722
|
-
interface AssetMetadata {
|
|
1723
|
-
name: string;
|
|
1724
|
-
description?: string;
|
|
1725
|
-
version: string;
|
|
1726
|
-
createdAt?: string;
|
|
1727
|
-
modifiedAt?: string;
|
|
1728
|
-
}
|
|
1729
|
-
/**
|
|
1730
|
-
* 黑板变量定义
|
|
1731
|
-
*/
|
|
1732
|
-
interface BlackboardVariableDefinition {
|
|
1733
|
-
name: string;
|
|
1734
|
-
type: BlackboardValueType;
|
|
1735
|
-
defaultValue: any;
|
|
1736
|
-
readonly?: boolean;
|
|
1737
|
-
description?: string;
|
|
1738
|
-
}
|
|
1739
|
-
/**
|
|
1740
|
-
* 行为树节点数据(运行时格式)
|
|
1741
|
-
*/
|
|
1742
|
-
interface BehaviorTreeNodeData {
|
|
1743
|
-
id: string;
|
|
1744
|
-
name: string;
|
|
1745
|
-
nodeType: NodeType;
|
|
1746
|
-
data: Record<string, any>;
|
|
1747
|
-
children: string[];
|
|
1748
|
-
}
|
|
1749
|
-
/**
|
|
1750
|
-
* 属性绑定定义
|
|
1751
|
-
*/
|
|
1752
|
-
interface PropertyBinding {
|
|
1753
|
-
nodeId: string;
|
|
1754
|
-
propertyName: string;
|
|
1755
|
-
variableName: string;
|
|
1756
|
-
}
|
|
1757
|
-
/**
|
|
1758
|
-
* 行为树资产(运行时格式)
|
|
1759
|
-
*
|
|
1760
|
-
* 这是用于游戏运行时的优化格式,不包含编辑器UI信息
|
|
1761
|
-
*/
|
|
1762
|
-
interface BehaviorTreeAsset {
|
|
1763
|
-
/**
|
|
1764
|
-
* 资产格式版本
|
|
1765
|
-
*/
|
|
1766
|
-
version: string;
|
|
1767
|
-
/**
|
|
1768
|
-
* 元数据
|
|
1769
|
-
*/
|
|
1770
|
-
metadata: AssetMetadata;
|
|
1771
|
-
/**
|
|
1772
|
-
* 根节点ID
|
|
1773
|
-
*/
|
|
1774
|
-
rootNodeId: string;
|
|
1775
|
-
/**
|
|
1776
|
-
* 所有节点数据(扁平化存储,通过children建立层级)
|
|
1777
|
-
*/
|
|
1778
|
-
nodes: BehaviorTreeNodeData[];
|
|
1779
|
-
/**
|
|
1780
|
-
* 黑板变量定义
|
|
1781
|
-
*/
|
|
1782
|
-
blackboard: BlackboardVariableDefinition[];
|
|
1783
|
-
/**
|
|
1784
|
-
* 属性绑定
|
|
1785
|
-
*/
|
|
1786
|
-
propertyBindings?: PropertyBinding[];
|
|
1787
|
-
}
|
|
1788
|
-
/**
|
|
1789
|
-
* 资产验证结果
|
|
1790
|
-
*/
|
|
1791
|
-
interface AssetValidationResult {
|
|
1792
|
-
valid: boolean;
|
|
1793
|
-
errors?: string[];
|
|
1794
|
-
warnings?: string[];
|
|
1795
|
-
}
|
|
1796
|
-
/**
|
|
1797
|
-
* 资产验证器
|
|
1798
|
-
*/
|
|
1799
|
-
declare class BehaviorTreeAssetValidator {
|
|
1800
|
-
/**
|
|
1801
|
-
* 验证资产数据的完整性和正确性
|
|
1802
|
-
*/
|
|
1803
|
-
static validate(asset: BehaviorTreeAsset): AssetValidationResult;
|
|
1804
|
-
/**
|
|
1805
|
-
* 获取资产统计信息
|
|
1806
|
-
*/
|
|
1807
|
-
static getStats(asset: BehaviorTreeAsset): {
|
|
1808
|
-
nodeCount: number;
|
|
1809
|
-
actionCount: number;
|
|
1810
|
-
conditionCount: number;
|
|
1811
|
-
compositeCount: number;
|
|
1812
|
-
decoratorCount: number;
|
|
1813
|
-
blackboardVariableCount: number;
|
|
1814
|
-
propertyBindingCount: number;
|
|
1815
|
-
maxDepth: number;
|
|
1816
|
-
};
|
|
1817
|
-
}
|
|
1818
|
-
|
|
1819
|
-
/**
|
|
1820
|
-
* 资产加载器接口
|
|
1821
|
-
*
|
|
1822
|
-
* 提供可扩展的资产加载机制,允许用户自定义资产加载逻辑。
|
|
1823
|
-
* 支持从文件系统、网络、数据库、自定义打包格式等加载资产。
|
|
1824
|
-
*
|
|
1825
|
-
* @example
|
|
1826
|
-
* ```typescript
|
|
1827
|
-
* // 使用默认的文件系统加载器
|
|
1828
|
-
* const loader = new FileSystemAssetLoader({
|
|
1829
|
-
* basePath: 'assets/behavior-trees',
|
|
1830
|
-
* format: 'json'
|
|
1831
|
-
* });
|
|
1832
|
-
* core.services.registerInstance(FileSystemAssetLoader, loader);
|
|
1833
|
-
*
|
|
1834
|
-
* // 或实现自定义加载器
|
|
1835
|
-
* class NetworkAssetLoader implements IAssetLoader {
|
|
1836
|
-
* async loadBehaviorTree(assetId: string): Promise<BehaviorTreeAsset> {
|
|
1837
|
-
* const response = await fetch(`/api/assets/${assetId}`);
|
|
1838
|
-
* return response.json();
|
|
1839
|
-
* }
|
|
1840
|
-
*
|
|
1841
|
-
* async exists(assetId: string): Promise<boolean> {
|
|
1842
|
-
* const response = await fetch(`/api/assets/${assetId}/exists`);
|
|
1843
|
-
* return response.json();
|
|
1844
|
-
* }
|
|
1845
|
-
* }
|
|
1846
|
-
* core.services.registerInstance(FileSystemAssetLoader, new NetworkAssetLoader());
|
|
1847
|
-
* ```
|
|
1848
|
-
*/
|
|
1849
|
-
interface IAssetLoader {
|
|
1850
|
-
/**
|
|
1851
|
-
* 加载行为树资产
|
|
1852
|
-
*
|
|
1853
|
-
* @param assetId 资产逻辑ID,例如 'patrol' 或 'ai/patrol'
|
|
1854
|
-
* @returns 行为树资产对象
|
|
1855
|
-
* @throws 如果资产不存在或加载失败
|
|
1856
|
-
*/
|
|
1857
|
-
loadBehaviorTree(assetId: string): Promise<BehaviorTreeAsset>;
|
|
1858
|
-
/**
|
|
1859
|
-
* 检查资产是否存在
|
|
1860
|
-
*
|
|
1861
|
-
* @param assetId 资产逻辑ID
|
|
1862
|
-
* @returns 资产是否存在
|
|
1863
|
-
*/
|
|
1864
|
-
exists(assetId: string): Promise<boolean>;
|
|
1865
|
-
/**
|
|
1866
|
-
* 预加载资产(可选)
|
|
1867
|
-
*
|
|
1868
|
-
* 用于提前加载资产到缓存,减少运行时延迟
|
|
1869
|
-
*
|
|
1870
|
-
* @param assetIds 要预加载的资产ID列表
|
|
1871
|
-
*/
|
|
1872
|
-
preload?(assetIds: string[]): Promise<void>;
|
|
1873
|
-
/**
|
|
1874
|
-
* 卸载资产(可选)
|
|
1875
|
-
*
|
|
1876
|
-
* 释放资产占用的内存
|
|
1877
|
-
*
|
|
1878
|
-
* @param assetId 资产ID
|
|
1879
|
-
*/
|
|
1880
|
-
unload?(assetId: string): void;
|
|
1881
|
-
}
|
|
1882
|
-
|
|
1883
|
-
/**
|
|
1884
|
-
* 文件系统资产加载器配置
|
|
1885
|
-
*/
|
|
1886
|
-
interface FileSystemAssetLoaderConfig {
|
|
1887
|
-
/** 资产基础路径 */
|
|
1888
|
-
basePath: string;
|
|
1889
|
-
/** 资产格式 */
|
|
1890
|
-
format: 'json' | 'binary';
|
|
1891
|
-
/** 文件扩展名(可选,默认根据格式自动设置) */
|
|
1892
|
-
extension?: string;
|
|
1893
|
-
/** 是否启用缓存 */
|
|
1894
|
-
enableCache?: boolean;
|
|
1895
|
-
/** 自定义文件读取函数(可选) */
|
|
1896
|
-
readFile?: (path: string) => Promise<string | Uint8Array>;
|
|
1897
|
-
}
|
|
1898
|
-
/**
|
|
1899
|
-
* 文件系统资产加载器
|
|
1900
|
-
*
|
|
1901
|
-
* 从文件系统加载行为树资产,支持 JSON 和 Binary 格式。
|
|
1902
|
-
* 提供资产缓存和预加载功能。
|
|
1903
|
-
*
|
|
1904
|
-
* @example
|
|
1905
|
-
* ```typescript
|
|
1906
|
-
* // 创建加载器
|
|
1907
|
-
* const loader = new FileSystemAssetLoader({
|
|
1908
|
-
* basePath: 'assets/behavior-trees',
|
|
1909
|
-
* format: 'json',
|
|
1910
|
-
* enableCache: true
|
|
1911
|
-
* });
|
|
1912
|
-
*
|
|
1913
|
-
* // 加载资产
|
|
1914
|
-
* const asset = await loader.loadBehaviorTree('patrol');
|
|
1915
|
-
* ```
|
|
1916
|
-
*/
|
|
1917
|
-
declare class FileSystemAssetLoader implements IAssetLoader, IService {
|
|
1918
|
-
private config;
|
|
1919
|
-
private cache;
|
|
1920
|
-
constructor(config: FileSystemAssetLoaderConfig);
|
|
1921
|
-
/**
|
|
1922
|
-
* 加载行为树资产
|
|
1923
|
-
*/
|
|
1924
|
-
loadBehaviorTree(assetId: string): Promise<BehaviorTreeAsset>;
|
|
1925
|
-
/**
|
|
1926
|
-
* 检查资产是否存在
|
|
1927
|
-
*/
|
|
1928
|
-
exists(assetId: string): Promise<boolean>;
|
|
1929
|
-
/**
|
|
1930
|
-
* 预加载资产
|
|
1931
|
-
*/
|
|
1932
|
-
preload(assetIds: string[]): Promise<void>;
|
|
1933
|
-
/**
|
|
1934
|
-
* 卸载资产
|
|
1935
|
-
*/
|
|
1936
|
-
unload(assetId: string): void;
|
|
1937
|
-
/**
|
|
1938
|
-
* 清空缓存
|
|
1939
|
-
*/
|
|
1940
|
-
clearCache(): void;
|
|
1941
|
-
/**
|
|
1942
|
-
* 获取缓存的资产数量
|
|
1943
|
-
*/
|
|
1944
|
-
getCacheSize(): number;
|
|
1945
|
-
/**
|
|
1946
|
-
* 释放资源
|
|
1947
|
-
*/
|
|
1948
|
-
dispose(): void;
|
|
1949
|
-
/**
|
|
1950
|
-
* 解析资产路径
|
|
1951
|
-
*/
|
|
1952
|
-
private resolveAssetPath;
|
|
1953
|
-
/**
|
|
1954
|
-
* 默认文件读取实现
|
|
1955
|
-
*
|
|
1956
|
-
* 注意:此实现依赖运行环境
|
|
1957
|
-
* - 浏览器:需要通过 fetch 或 XMLHttpRequest
|
|
1958
|
-
* - Node.js:需要使用 fs
|
|
1959
|
-
* - 游戏引擎:需要使用引擎的文件 API
|
|
1960
|
-
*
|
|
1961
|
-
* 用户应该提供自己的 readFile 实现
|
|
1962
|
-
*/
|
|
1963
|
-
private defaultReadFile;
|
|
1964
|
-
}
|
|
1965
|
-
|
|
1966
|
-
/**
|
|
1967
|
-
* 行为树插件
|
|
1968
|
-
*
|
|
1969
|
-
* 提供便捷方法向场景添加行为树系统
|
|
1970
|
-
*
|
|
1971
|
-
* @example
|
|
1972
|
-
* ```typescript
|
|
1973
|
-
* const core = Core.create();
|
|
1974
|
-
* const plugin = new BehaviorTreePlugin();
|
|
1975
|
-
* await core.pluginManager.install(plugin);
|
|
1976
|
-
*
|
|
1977
|
-
* // 为场景添加行为树系统
|
|
1978
|
-
* const scene = new Scene();
|
|
1979
|
-
* plugin.setupScene(scene);
|
|
1980
|
-
* ```
|
|
1981
|
-
*/
|
|
1982
|
-
declare class BehaviorTreePlugin implements IPlugin {
|
|
1983
|
-
readonly name = "@esengine/behavior-tree";
|
|
1984
|
-
readonly version = "1.0.0";
|
|
1985
|
-
private worldManager;
|
|
1986
|
-
private services;
|
|
1987
|
-
/**
|
|
1988
|
-
* 安装插件
|
|
1989
|
-
*/
|
|
1990
|
-
install(core: Core, services: ServiceContainer): Promise<void>;
|
|
1991
|
-
/**
|
|
1992
|
-
* 卸载插件
|
|
1993
|
-
*/
|
|
1994
|
-
uninstall(): Promise<void>;
|
|
1995
|
-
/**
|
|
1996
|
-
* 为场景设置行为树系统
|
|
1997
|
-
*
|
|
1998
|
-
* 向场景添加所有必需的行为树系统:
|
|
1999
|
-
* - LeafExecutionSystem (updateOrder: 100)
|
|
2000
|
-
* - DecoratorExecutionSystem (updateOrder: 200)
|
|
2001
|
-
* - CompositeExecutionSystem (updateOrder: 300)
|
|
2002
|
-
* - SubTreeExecutionSystem (updateOrder: 300)
|
|
2003
|
-
*
|
|
2004
|
-
* @param scene 目标场景
|
|
2005
|
-
*
|
|
2006
|
-
* @example
|
|
2007
|
-
* ```typescript
|
|
2008
|
-
* const scene = new Scene();
|
|
2009
|
-
* behaviorTreePlugin.setupScene(scene);
|
|
2010
|
-
* ```
|
|
2011
|
-
*/
|
|
2012
|
-
setupScene(scene: IScene): void;
|
|
2013
|
-
/**
|
|
2014
|
-
* 为所有现有场景设置行为树系统
|
|
2015
|
-
*/
|
|
2016
|
-
setupAllScenes(): void;
|
|
2017
|
-
}
|
|
2018
|
-
|
|
2019
|
-
/**
|
|
2020
|
-
* 行为树启动/停止辅助类
|
|
2021
|
-
*
|
|
2022
|
-
* 提供便捷方法来启动、停止和暂停行为树
|
|
2023
|
-
*/
|
|
2024
|
-
declare class BehaviorTreeStarter {
|
|
2025
|
-
/**
|
|
2026
|
-
* 启动行为树
|
|
2027
|
-
*
|
|
2028
|
-
* 给根节点添加 ActiveNode 组件,使行为树开始执行
|
|
2029
|
-
*
|
|
2030
|
-
* @param rootEntity 行为树根节点实体
|
|
2031
|
-
*
|
|
2032
|
-
* @example
|
|
2033
|
-
* ```typescript
|
|
2034
|
-
* const aiRoot = scene.createEntity('aiRoot');
|
|
2035
|
-
* // ... 构建行为树结构
|
|
2036
|
-
* BehaviorTreeStarter.start(aiRoot);
|
|
2037
|
-
* ```
|
|
2038
|
-
*/
|
|
2039
|
-
static start(rootEntity: Entity): void;
|
|
2040
|
-
/**
|
|
2041
|
-
* 停止行为树
|
|
2042
|
-
*
|
|
2043
|
-
* 移除所有节点的 ActiveNode 组件,停止执行
|
|
2044
|
-
*
|
|
2045
|
-
* @param rootEntity 行为树根节点实体
|
|
2046
|
-
*
|
|
2047
|
-
* @example
|
|
2048
|
-
* ```typescript
|
|
2049
|
-
* BehaviorTreeStarter.stop(aiRoot);
|
|
2050
|
-
* ```
|
|
2051
|
-
*/
|
|
2052
|
-
static stop(rootEntity: Entity): void;
|
|
2053
|
-
/**
|
|
2054
|
-
* 递归停止所有子节点
|
|
2055
|
-
*/
|
|
2056
|
-
private static stopRecursive;
|
|
2057
|
-
/**
|
|
2058
|
-
* 暂停行为树
|
|
2059
|
-
*
|
|
2060
|
-
* 移除 ActiveNode 但保留节点状态,可以恢复执行
|
|
2061
|
-
*
|
|
2062
|
-
* @param rootEntity 行为树根节点实体
|
|
2063
|
-
*
|
|
2064
|
-
* @example
|
|
2065
|
-
* ```typescript
|
|
2066
|
-
* // 暂停
|
|
2067
|
-
* BehaviorTreeStarter.pause(aiRoot);
|
|
2068
|
-
*
|
|
2069
|
-
* // 恢复
|
|
2070
|
-
* BehaviorTreeStarter.resume(aiRoot);
|
|
2071
|
-
* ```
|
|
2072
|
-
*/
|
|
2073
|
-
static pause(rootEntity: Entity): void;
|
|
2074
|
-
/**
|
|
2075
|
-
* 递归暂停所有子节点
|
|
2076
|
-
*/
|
|
2077
|
-
private static pauseRecursive;
|
|
2078
|
-
/**
|
|
2079
|
-
* 恢复行为树执行
|
|
2080
|
-
*
|
|
2081
|
-
* 从暂停状态恢复,重新添加 ActiveNode 到之前正在执行的节点
|
|
2082
|
-
*
|
|
2083
|
-
* @param rootEntity 行为树根节点实体
|
|
2084
|
-
*
|
|
2085
|
-
* @example
|
|
2086
|
-
* ```typescript
|
|
2087
|
-
* BehaviorTreeStarter.resume(aiRoot);
|
|
2088
|
-
* ```
|
|
2089
|
-
*/
|
|
2090
|
-
static resume(rootEntity: Entity): void;
|
|
2091
|
-
/**
|
|
2092
|
-
* 递归恢复所有正在执行的节点
|
|
2093
|
-
*/
|
|
2094
|
-
private static resumeRecursive;
|
|
2095
|
-
/**
|
|
2096
|
-
* 重启行为树
|
|
2097
|
-
*
|
|
2098
|
-
* 停止并重置所有节点,然后重新启动
|
|
2099
|
-
*
|
|
2100
|
-
* @param rootEntity 行为树根节点实体
|
|
2101
|
-
*
|
|
2102
|
-
* @example
|
|
2103
|
-
* ```typescript
|
|
2104
|
-
* BehaviorTreeStarter.restart(aiRoot);
|
|
2105
|
-
* ```
|
|
2106
|
-
*/
|
|
2107
|
-
static restart(rootEntity: Entity): void;
|
|
2108
|
-
/**
|
|
2109
|
-
* 检查行为树是否正在运行
|
|
2110
|
-
*
|
|
2111
|
-
* @param rootEntity 行为树根节点实体
|
|
2112
|
-
* @returns 是否正在运行
|
|
2113
|
-
*
|
|
2114
|
-
* @example
|
|
2115
|
-
* ```typescript
|
|
2116
|
-
* if (BehaviorTreeStarter.isRunning(aiRoot)) {
|
|
2117
|
-
* console.log('AI is active');
|
|
2118
|
-
* }
|
|
2119
|
-
* ```
|
|
2120
|
-
*/
|
|
2121
|
-
static isRunning(rootEntity: Entity): boolean;
|
|
2122
|
-
}
|
|
2123
|
-
|
|
2124
|
-
/**
|
|
2125
|
-
* 行为树构建器
|
|
2126
|
-
*
|
|
2127
|
-
* 提供流式 API 来构建行为树结构
|
|
2128
|
-
*
|
|
2129
|
-
* @example
|
|
2130
|
-
* ```typescript
|
|
2131
|
-
* const aiRoot = BehaviorTreeBuilder.create(scene, 'AI')
|
|
2132
|
-
* .blackboard()
|
|
2133
|
-
* .defineVariable('health', BlackboardValueType.Number, 100)
|
|
2134
|
-
* .defineVariable('target', BlackboardValueType.Object, null)
|
|
2135
|
-
* .endBlackboard()
|
|
2136
|
-
* .selector('MainSelector')
|
|
2137
|
-
* .sequence('AttackSequence')
|
|
2138
|
-
* .condition((entity, blackboard) => {
|
|
2139
|
-
* return blackboard?.getValue('health') > 50;
|
|
2140
|
-
* })
|
|
2141
|
-
* .action('Attack', (entity) => TaskStatus.Success)
|
|
2142
|
-
* .end()
|
|
2143
|
-
* .action('Flee', (entity) => TaskStatus.Success)
|
|
2144
|
-
* .end()
|
|
2145
|
-
* .build();
|
|
2146
|
-
* ```
|
|
2147
|
-
*/
|
|
2148
|
-
declare class BehaviorTreeBuilder {
|
|
2149
|
-
private scene;
|
|
2150
|
-
private currentEntity;
|
|
2151
|
-
private entityStack;
|
|
2152
|
-
private blackboardEntity?;
|
|
2153
|
-
private constructor();
|
|
2154
|
-
/**
|
|
2155
|
-
* 创建行为树构建器
|
|
2156
|
-
*
|
|
2157
|
-
* @param scene 场景实例
|
|
2158
|
-
* @param rootName 根节点名称
|
|
2159
|
-
* @returns 构建器实例
|
|
2160
|
-
*/
|
|
2161
|
-
static create(scene: IScene, rootName?: string): BehaviorTreeBuilder;
|
|
2162
|
-
/**
|
|
2163
|
-
* 添加黑板组件到根节点
|
|
2164
|
-
*/
|
|
2165
|
-
blackboard(): BehaviorTreeBuilder;
|
|
2166
|
-
/**
|
|
2167
|
-
* 定义黑板变量
|
|
2168
|
-
*/
|
|
2169
|
-
defineVariable(name: string, type: BlackboardValueType, initialValue: any, options?: {
|
|
2170
|
-
readonly?: boolean;
|
|
2171
|
-
description?: string;
|
|
2172
|
-
}): BehaviorTreeBuilder;
|
|
2173
|
-
/**
|
|
2174
|
-
* 结束黑板定义
|
|
2175
|
-
*/
|
|
2176
|
-
endBlackboard(): BehaviorTreeBuilder;
|
|
2177
|
-
/**
|
|
2178
|
-
* 创建序列节点
|
|
2179
|
-
*/
|
|
2180
|
-
sequence(name?: string): BehaviorTreeBuilder;
|
|
2181
|
-
/**
|
|
2182
|
-
* 创建选择器节点
|
|
2183
|
-
*/
|
|
2184
|
-
selector(name?: string): BehaviorTreeBuilder;
|
|
2185
|
-
/**
|
|
2186
|
-
* 创建并行节点
|
|
2187
|
-
*/
|
|
2188
|
-
parallel(name?: string): BehaviorTreeBuilder;
|
|
2189
|
-
/**
|
|
2190
|
-
* 创建并行选择器节点
|
|
2191
|
-
*/
|
|
2192
|
-
parallelSelector(name?: string): BehaviorTreeBuilder;
|
|
2193
|
-
/**
|
|
2194
|
-
* 创建随机序列节点
|
|
2195
|
-
*/
|
|
2196
|
-
randomSequence(name?: string): BehaviorTreeBuilder;
|
|
2197
|
-
/**
|
|
2198
|
-
* 创建随机选择器节点
|
|
2199
|
-
*/
|
|
2200
|
-
randomSelector(name?: string): BehaviorTreeBuilder;
|
|
2201
|
-
/**
|
|
2202
|
-
* 创建复合节点
|
|
2203
|
-
*/
|
|
2204
|
-
private composite;
|
|
2205
|
-
/**
|
|
2206
|
-
* 创建反转装饰器
|
|
2207
|
-
*/
|
|
2208
|
-
inverter(name?: string): BehaviorTreeBuilder;
|
|
2209
|
-
/**
|
|
2210
|
-
* 创建重复装饰器
|
|
2211
|
-
*/
|
|
2212
|
-
repeater(name?: string, count?: number, endOnFailure?: boolean): BehaviorTreeBuilder;
|
|
2213
|
-
/**
|
|
2214
|
-
* 创建直到成功装饰器
|
|
2215
|
-
*/
|
|
2216
|
-
untilSuccess(name?: string): BehaviorTreeBuilder;
|
|
2217
|
-
/**
|
|
2218
|
-
* 创建直到失败装饰器
|
|
2219
|
-
*/
|
|
2220
|
-
untilFail(name?: string): BehaviorTreeBuilder;
|
|
2221
|
-
/**
|
|
2222
|
-
* 创建总是成功装饰器
|
|
2223
|
-
*/
|
|
2224
|
-
alwaysSucceed(name?: string): BehaviorTreeBuilder;
|
|
2225
|
-
/**
|
|
2226
|
-
* 创建总是失败装饰器
|
|
2227
|
-
*/
|
|
2228
|
-
alwaysFail(name?: string): BehaviorTreeBuilder;
|
|
2229
|
-
/**
|
|
2230
|
-
* 创建条件装饰器
|
|
2231
|
-
*/
|
|
2232
|
-
conditional(name: string, conditionCode: string): BehaviorTreeBuilder;
|
|
2233
|
-
/**
|
|
2234
|
-
* 创建冷却装饰器
|
|
2235
|
-
*/
|
|
2236
|
-
cooldown(name?: string, cooldownTime?: number): BehaviorTreeBuilder;
|
|
2237
|
-
/**
|
|
2238
|
-
* 创建超时装饰器
|
|
2239
|
-
*/
|
|
2240
|
-
timeout(name?: string, timeoutDuration?: number): BehaviorTreeBuilder;
|
|
2241
|
-
/**
|
|
2242
|
-
* 创建等待动作
|
|
2243
|
-
*/
|
|
2244
|
-
wait(waitTime: number, name?: string): BehaviorTreeBuilder;
|
|
2245
|
-
/**
|
|
2246
|
-
* 创建日志动作
|
|
2247
|
-
*/
|
|
2248
|
-
log(message: string, level?: 'log' | 'info' | 'warn' | 'error', name?: string): BehaviorTreeBuilder;
|
|
2249
|
-
/**
|
|
2250
|
-
* 创建设置黑板值动作
|
|
2251
|
-
*/
|
|
2252
|
-
setBlackboardValue(variableName: string, value: any, name?: string): BehaviorTreeBuilder;
|
|
2253
|
-
/**
|
|
2254
|
-
* 创建修改黑板值动作
|
|
2255
|
-
*/
|
|
2256
|
-
modifyBlackboardValue(variableName: string, operation: ModifyOperation, operand: any, name?: string): BehaviorTreeBuilder;
|
|
2257
|
-
/**
|
|
2258
|
-
* 创建自定义动作
|
|
2259
|
-
*/
|
|
2260
|
-
action(name: string, func: CustomActionFunction): BehaviorTreeBuilder;
|
|
2261
|
-
/**
|
|
2262
|
-
* 创建黑板比较条件
|
|
2263
|
-
*/
|
|
2264
|
-
compareBlackboardValue(variableName: string, operator: CompareOperator, compareValue: any, name?: string): BehaviorTreeBuilder;
|
|
2265
|
-
/**
|
|
2266
|
-
* 创建黑板变量存在条件
|
|
2267
|
-
*/
|
|
2268
|
-
checkBlackboardExists(variableName: string, checkNotNull?: boolean, name?: string): BehaviorTreeBuilder;
|
|
2269
|
-
/**
|
|
2270
|
-
* 创建随机概率条件
|
|
2271
|
-
*/
|
|
2272
|
-
randomProbability(probability: number, name?: string): BehaviorTreeBuilder;
|
|
2273
|
-
/**
|
|
2274
|
-
* 创建自定义条件
|
|
2275
|
-
*/
|
|
2276
|
-
condition(func: CustomConditionFunction, name?: string): BehaviorTreeBuilder;
|
|
2277
|
-
/**
|
|
2278
|
-
* 结束当前节点,返回父节点
|
|
2279
|
-
*/
|
|
2280
|
-
end(): BehaviorTreeBuilder;
|
|
2281
|
-
/**
|
|
2282
|
-
* 构建并返回根节点实体
|
|
2283
|
-
*/
|
|
2284
|
-
build(): Entity;
|
|
2285
|
-
}
|
|
2286
|
-
|
|
2287
|
-
/**
|
|
2288
|
-
* 行为树持久化工具
|
|
2289
|
-
*
|
|
2290
|
-
* 使用框架的序列化系统进行二进制/JSON序列化
|
|
2291
|
-
*/
|
|
2292
|
-
declare class BehaviorTreePersistence {
|
|
2293
|
-
/**
|
|
2294
|
-
* 序列化行为树(JSON格式)
|
|
2295
|
-
*
|
|
2296
|
-
* @param rootEntity 行为树根实体
|
|
2297
|
-
* @param pretty 是否格式化
|
|
2298
|
-
* @returns 序列化数据(JSON字符串或二进制)
|
|
2299
|
-
*
|
|
2300
|
-
* @example
|
|
2301
|
-
* ```typescript
|
|
2302
|
-
* const data = BehaviorTreePersistence.serialize(aiRoot);
|
|
2303
|
-
* ```
|
|
2304
|
-
*/
|
|
2305
|
-
static serialize(rootEntity: Entity, pretty?: boolean): string | Uint8Array;
|
|
2306
|
-
/**
|
|
2307
|
-
* 从序列化数据加载行为树
|
|
2308
|
-
*
|
|
2309
|
-
* @param scene 场景实例
|
|
2310
|
-
* @param data 序列化数据(JSON字符串或二进制)
|
|
2311
|
-
*
|
|
2312
|
-
* @example
|
|
2313
|
-
* ```typescript
|
|
2314
|
-
* // 从文件读取
|
|
2315
|
-
* const json = await readFile('behavior-tree.json');
|
|
2316
|
-
*
|
|
2317
|
-
* // 恢复行为树到场景
|
|
2318
|
-
* BehaviorTreePersistence.deserialize(scene, json);
|
|
2319
|
-
* ```
|
|
2320
|
-
*/
|
|
2321
|
-
static deserialize(scene: IScene, data: string | Uint8Array): void;
|
|
2322
|
-
/**
|
|
2323
|
-
* 序列化为 JSON 字符串
|
|
2324
|
-
*
|
|
2325
|
-
* @param rootEntity 行为树根实体
|
|
2326
|
-
* @param pretty 是否格式化
|
|
2327
|
-
* @returns JSON 字符串
|
|
2328
|
-
*/
|
|
2329
|
-
static toJSON(rootEntity: Entity, pretty?: boolean): string;
|
|
2330
|
-
/**
|
|
2331
|
-
* 从 JSON 字符串加载
|
|
2332
|
-
*
|
|
2333
|
-
* @param scene 场景实例
|
|
2334
|
-
* @param json JSON 字符串
|
|
2335
|
-
*/
|
|
2336
|
-
static fromJSON(scene: IScene, json: string): void;
|
|
2337
|
-
/**
|
|
2338
|
-
* 保存到文件(需要 Tauri 环境)
|
|
2339
|
-
*
|
|
2340
|
-
* @param rootEntity 行为树根实体
|
|
2341
|
-
* @param filePath 文件路径
|
|
2342
|
-
*
|
|
2343
|
-
* @example
|
|
2344
|
-
* ```typescript
|
|
2345
|
-
* await BehaviorTreePersistence.saveToFile(aiRoot, 'ai-behavior.json');
|
|
2346
|
-
* ```
|
|
2347
|
-
*/
|
|
2348
|
-
static saveToFile(rootEntity: Entity, filePath: string): Promise<void>;
|
|
2349
|
-
/**
|
|
2350
|
-
* 从文件加载(需要 Tauri 环境)
|
|
2351
|
-
*
|
|
2352
|
-
* @param scene 场景实例
|
|
2353
|
-
* @param filePath 文件路径
|
|
2354
|
-
* @returns 恢复的根实体
|
|
2355
|
-
*
|
|
2356
|
-
* @example
|
|
2357
|
-
* ```typescript
|
|
2358
|
-
* const aiRoot = await BehaviorTreePersistence.loadFromFile(scene, 'ai-behavior.json');
|
|
2359
|
-
* ```
|
|
2360
|
-
*/
|
|
2361
|
-
static loadFromFile(scene: IScene, filePath: string): Promise<Entity>;
|
|
2362
|
-
/**
|
|
2363
|
-
* 验证是否为有效的行为树数据
|
|
2364
|
-
*
|
|
2365
|
-
* @param data 序列化数据(字符串格式)
|
|
2366
|
-
* @returns 是否有效
|
|
2367
|
-
*/
|
|
2368
|
-
static validate(data: string): boolean;
|
|
2369
|
-
/**
|
|
2370
|
-
* 克隆行为树
|
|
2371
|
-
*
|
|
2372
|
-
* @param scene 场景实例
|
|
2373
|
-
* @param rootEntity 要克隆的行为树根实体
|
|
2374
|
-
* @returns 克隆的新实体
|
|
2375
|
-
*
|
|
2376
|
-
* @example
|
|
2377
|
-
* ```typescript
|
|
2378
|
-
* const clonedAI = BehaviorTreePersistence.clone(scene, originalAI);
|
|
2379
|
-
* ```
|
|
2380
|
-
*/
|
|
2381
|
-
static clone(scene: IScene, rootEntity: Entity): Entity;
|
|
2382
|
-
}
|
|
2383
|
-
|
|
2384
|
-
/**
|
|
2385
|
-
* 节点数据JSON格式(用于编辑器)
|
|
2386
|
-
*/
|
|
2387
|
-
interface NodeDataJSON {
|
|
2388
|
-
nodeType: string;
|
|
2389
|
-
compositeType?: string;
|
|
2390
|
-
decoratorType?: string;
|
|
2391
|
-
[key: string]: any;
|
|
2392
|
-
}
|
|
2393
|
-
/**
|
|
2394
|
-
* 属性定义(用于编辑器)
|
|
2395
|
-
*/
|
|
2396
|
-
interface PropertyDefinition {
|
|
2397
|
-
name: string;
|
|
2398
|
-
type: 'string' | 'number' | 'boolean' | 'select' | 'blackboard' | 'code' | 'variable' | 'asset';
|
|
2399
|
-
label: string;
|
|
2400
|
-
description?: string;
|
|
2401
|
-
defaultValue?: any;
|
|
2402
|
-
options?: Array<{
|
|
2403
|
-
label: string;
|
|
2404
|
-
value: any;
|
|
2405
|
-
}>;
|
|
2406
|
-
min?: number;
|
|
2407
|
-
max?: number;
|
|
2408
|
-
step?: number;
|
|
2409
|
-
required?: boolean;
|
|
2410
|
-
}
|
|
2411
|
-
/**
|
|
2412
|
-
* 节点模板(用于编辑器)
|
|
2413
|
-
*/
|
|
2414
|
-
interface NodeTemplate {
|
|
2415
|
-
type: NodeType;
|
|
2416
|
-
displayName: string;
|
|
2417
|
-
category: string;
|
|
2418
|
-
icon?: string;
|
|
2419
|
-
description: string;
|
|
2420
|
-
color?: string;
|
|
2421
|
-
className?: string;
|
|
2422
|
-
requiresChildren?: boolean;
|
|
2423
|
-
defaultConfig: Partial<NodeDataJSON>;
|
|
2424
|
-
properties: PropertyDefinition[];
|
|
2425
|
-
}
|
|
2426
|
-
/**
|
|
2427
|
-
* 编辑器节点模板库
|
|
2428
|
-
*
|
|
2429
|
-
* 使用装饰器系统管理所有节点
|
|
2430
|
-
*/
|
|
2431
|
-
declare class NodeTemplates {
|
|
2432
|
-
/**
|
|
2433
|
-
* 获取所有节点模板(通过装饰器注册)
|
|
2434
|
-
*/
|
|
2435
|
-
static getAllTemplates(): NodeTemplate[];
|
|
2436
|
-
/**
|
|
2437
|
-
* 根据类型和子类型获取模板
|
|
2438
|
-
*/
|
|
2439
|
-
static getTemplate(type: NodeType, subType: string): NodeTemplate | undefined;
|
|
2440
|
-
}
|
|
2441
|
-
|
|
2442
|
-
/**
|
|
2443
|
-
* 序列化格式
|
|
2444
|
-
*/
|
|
2445
|
-
type SerializationFormat = 'json' | 'binary';
|
|
2446
|
-
/**
|
|
2447
|
-
* 序列化选项
|
|
2448
|
-
*/
|
|
2449
|
-
interface SerializationOptions {
|
|
2450
|
-
/**
|
|
2451
|
-
* 序列化格式
|
|
2452
|
-
*/
|
|
2453
|
-
format: SerializationFormat;
|
|
2454
|
-
/**
|
|
2455
|
-
* 是否美化JSON输出(仅format='json'时有效)
|
|
2456
|
-
*/
|
|
2457
|
-
pretty?: boolean;
|
|
2458
|
-
/**
|
|
2459
|
-
* 是否在序列化前验证资产
|
|
2460
|
-
*/
|
|
2461
|
-
validate?: boolean;
|
|
2462
|
-
}
|
|
2463
|
-
/**
|
|
2464
|
-
* 反序列化选项
|
|
2465
|
-
*/
|
|
2466
|
-
interface DeserializationOptions {
|
|
2467
|
-
/**
|
|
2468
|
-
* 是否在反序列化后验证资产
|
|
2469
|
-
*/
|
|
2470
|
-
validate?: boolean;
|
|
2471
|
-
/**
|
|
2472
|
-
* 是否严格模式(验证失败抛出异常)
|
|
2473
|
-
*/
|
|
2474
|
-
strict?: boolean;
|
|
2475
|
-
}
|
|
2476
|
-
/**
|
|
2477
|
-
* 行为树资产序列化器
|
|
2478
|
-
*
|
|
2479
|
-
* 支持JSON和二进制(MessagePack)两种格式
|
|
2480
|
-
*/
|
|
2481
|
-
declare class BehaviorTreeAssetSerializer {
|
|
2482
|
-
/**
|
|
2483
|
-
* 序列化资产
|
|
2484
|
-
*
|
|
2485
|
-
* @param asset 行为树资产
|
|
2486
|
-
* @param options 序列化选项
|
|
2487
|
-
* @returns 序列化后的数据(字符串或Uint8Array)
|
|
2488
|
-
*
|
|
2489
|
-
* @example
|
|
2490
|
-
* ```typescript
|
|
2491
|
-
* // JSON格式
|
|
2492
|
-
* const jsonData = BehaviorTreeAssetSerializer.serialize(asset, { format: 'json', pretty: true });
|
|
2493
|
-
*
|
|
2494
|
-
* // 二进制格式
|
|
2495
|
-
* const binaryData = BehaviorTreeAssetSerializer.serialize(asset, { format: 'binary' });
|
|
2496
|
-
* ```
|
|
2497
|
-
*/
|
|
2498
|
-
static serialize(asset: BehaviorTreeAsset, options?: SerializationOptions): string | Uint8Array;
|
|
2499
|
-
/**
|
|
2500
|
-
* 序列化为JSON格式
|
|
2501
|
-
*/
|
|
2502
|
-
private static serializeToJSON;
|
|
2503
|
-
/**
|
|
2504
|
-
* 序列化为二进制格式(MessagePack)
|
|
2505
|
-
*/
|
|
2506
|
-
private static serializeToBinary;
|
|
2507
|
-
/**
|
|
2508
|
-
* 反序列化资产
|
|
2509
|
-
*
|
|
2510
|
-
* @param data 序列化的数据(字符串或Uint8Array)
|
|
2511
|
-
* @param options 反序列化选项
|
|
2512
|
-
* @returns 行为树资产
|
|
2513
|
-
*
|
|
2514
|
-
* @example
|
|
2515
|
-
* ```typescript
|
|
2516
|
-
* // 从JSON加载
|
|
2517
|
-
* const asset = BehaviorTreeAssetSerializer.deserialize(jsonString);
|
|
2518
|
-
*
|
|
2519
|
-
* // 从二进制加载
|
|
2520
|
-
* const asset = BehaviorTreeAssetSerializer.deserialize(binaryData);
|
|
2521
|
-
* ```
|
|
2522
|
-
*/
|
|
2523
|
-
static deserialize(data: string | Uint8Array, options?: DeserializationOptions): BehaviorTreeAsset;
|
|
2524
|
-
/**
|
|
2525
|
-
* 从JSON反序列化
|
|
2526
|
-
*/
|
|
2527
|
-
private static deserializeFromJSON;
|
|
2528
|
-
/**
|
|
2529
|
-
* 从二进制反序列化
|
|
2530
|
-
*/
|
|
2531
|
-
private static deserializeFromBinary;
|
|
2532
|
-
/**
|
|
2533
|
-
* 检测数据格式
|
|
2534
|
-
*
|
|
2535
|
-
* @param data 序列化的数据
|
|
2536
|
-
* @returns 格式类型
|
|
2537
|
-
*/
|
|
2538
|
-
static detectFormat(data: string | Uint8Array): SerializationFormat;
|
|
2539
|
-
/**
|
|
2540
|
-
* 获取序列化数据的信息(不完全反序列化)
|
|
2541
|
-
*
|
|
2542
|
-
* @param data 序列化的数据
|
|
2543
|
-
* @returns 资产元信息
|
|
2544
|
-
*/
|
|
2545
|
-
static getInfo(data: string | Uint8Array): {
|
|
2546
|
-
format: SerializationFormat;
|
|
2547
|
-
name: string;
|
|
2548
|
-
version: string;
|
|
2549
|
-
nodeCount: number;
|
|
2550
|
-
blackboardVariableCount: number;
|
|
2551
|
-
size: number;
|
|
2552
|
-
} | null;
|
|
2553
|
-
/**
|
|
2554
|
-
* 转换格式
|
|
2555
|
-
*
|
|
2556
|
-
* @param data 源数据
|
|
2557
|
-
* @param targetFormat 目标格式
|
|
2558
|
-
* @param pretty 是否美化JSON(仅当目标格式为json时有效)
|
|
2559
|
-
* @returns 转换后的数据
|
|
2560
|
-
*
|
|
2561
|
-
* @example
|
|
2562
|
-
* ```typescript
|
|
2563
|
-
* // JSON转二进制
|
|
2564
|
-
* const binary = BehaviorTreeAssetSerializer.convert(jsonString, 'binary');
|
|
2565
|
-
*
|
|
2566
|
-
* // 二进制转JSON
|
|
2567
|
-
* const json = BehaviorTreeAssetSerializer.convert(binaryData, 'json', true);
|
|
2568
|
-
* ```
|
|
2569
|
-
*/
|
|
2570
|
-
static convert(data: string | Uint8Array, targetFormat: SerializationFormat, pretty?: boolean): string | Uint8Array;
|
|
2571
|
-
/**
|
|
2572
|
-
* 比较两个资产数据的大小
|
|
2573
|
-
*
|
|
2574
|
-
* @param jsonData JSON格式数据
|
|
2575
|
-
* @param binaryData 二进制格式数据
|
|
2576
|
-
* @returns 压缩率(百分比)
|
|
2577
|
-
*/
|
|
2578
|
-
static compareSize(jsonData: string, binaryData: Uint8Array): {
|
|
2579
|
-
jsonSize: number;
|
|
2580
|
-
binarySize: number;
|
|
2581
|
-
compressionRatio: number;
|
|
2582
|
-
savedBytes: number;
|
|
2583
|
-
};
|
|
2584
|
-
}
|
|
2585
|
-
|
|
2586
|
-
/**
|
|
2587
|
-
* 实例化选项
|
|
2588
|
-
*/
|
|
2589
|
-
interface InstantiateOptions {
|
|
2590
|
-
/**
|
|
2591
|
-
* 实体名称前缀
|
|
2592
|
-
*/
|
|
2593
|
-
namePrefix?: string;
|
|
2594
|
-
/**
|
|
2595
|
-
* 是否共享黑板(如果为true,将使用全局黑板服务)
|
|
2596
|
-
*/
|
|
2597
|
-
sharedBlackboard?: boolean;
|
|
2598
|
-
/**
|
|
2599
|
-
* 黑板变量覆盖(用于运行时动态设置初始值)
|
|
2600
|
-
*/
|
|
2601
|
-
blackboardOverrides?: Record<string, any>;
|
|
2602
|
-
/**
|
|
2603
|
-
* 是否作为子树实例化
|
|
2604
|
-
* 如果为 true,根节点不会添加 RootNode 组件,避免触发预加载逻辑
|
|
2605
|
-
*/
|
|
2606
|
-
asSubTree?: boolean;
|
|
2607
|
-
}
|
|
2608
|
-
/**
|
|
2609
|
-
* 行为树资产加载器
|
|
2610
|
-
*
|
|
2611
|
-
* 将BehaviorTreeAsset实例化为可运行的Entity树
|
|
2612
|
-
*/
|
|
2613
|
-
declare class BehaviorTreeAssetLoader {
|
|
2614
|
-
/**
|
|
2615
|
-
* 从资产实例化行为树
|
|
2616
|
-
*
|
|
2617
|
-
* @param asset 行为树资产
|
|
2618
|
-
* @param scene 目标场景
|
|
2619
|
-
* @param options 实例化选项
|
|
2620
|
-
* @returns 根实体
|
|
2621
|
-
*
|
|
2622
|
-
* @example
|
|
2623
|
-
* ```typescript
|
|
2624
|
-
* const asset = await loadAssetFromFile('enemy-ai.btree.bin');
|
|
2625
|
-
* const aiRoot = BehaviorTreeAssetLoader.instantiate(asset, scene);
|
|
2626
|
-
* BehaviorTreeStarter.start(aiRoot);
|
|
2627
|
-
* ```
|
|
2628
|
-
*/
|
|
2629
|
-
static instantiate(asset: BehaviorTreeAsset, scene: IScene, options?: InstantiateOptions): Entity;
|
|
2630
|
-
/**
|
|
2631
|
-
* 递归创建实体树
|
|
2632
|
-
*/
|
|
2633
|
-
private static createEntityTree;
|
|
2634
|
-
/**
|
|
2635
|
-
* 添加节点特定组件
|
|
2636
|
-
* @param skipRootNode 是否跳过添加 RootNode 组件(用于子树)
|
|
2637
|
-
*/
|
|
2638
|
-
private static addNodeComponents;
|
|
2639
|
-
/**
|
|
2640
|
-
* 添加组合节点组件
|
|
2641
|
-
*/
|
|
2642
|
-
private static addCompositeComponent;
|
|
2643
|
-
/**
|
|
2644
|
-
* 添加装饰器组件
|
|
2645
|
-
*/
|
|
2646
|
-
private static addDecoratorComponent;
|
|
2647
|
-
/**
|
|
2648
|
-
* 添加动作组件
|
|
2649
|
-
*/
|
|
2650
|
-
private static addActionComponent;
|
|
2651
|
-
/**
|
|
2652
|
-
* 添加条件组件
|
|
2653
|
-
*/
|
|
2654
|
-
private static addConditionComponent;
|
|
2655
|
-
/**
|
|
2656
|
-
* 设置黑板
|
|
2657
|
-
*/
|
|
2658
|
-
private static setupBlackboard;
|
|
2659
|
-
/**
|
|
2660
|
-
* 设置属性绑定
|
|
2661
|
-
*/
|
|
2662
|
-
private static setupPropertyBindings;
|
|
2663
|
-
}
|
|
2664
|
-
|
|
2665
|
-
/**
|
|
2666
|
-
* 编辑器节点格式
|
|
2667
|
-
*/
|
|
2668
|
-
interface EditorNode {
|
|
2669
|
-
id: string;
|
|
2670
|
-
template: {
|
|
2671
|
-
displayName: string;
|
|
2672
|
-
category: string;
|
|
2673
|
-
type: NodeType;
|
|
2674
|
-
[key: string]: any;
|
|
2675
|
-
};
|
|
2676
|
-
data: Record<string, any>;
|
|
2677
|
-
position: {
|
|
2678
|
-
x: number;
|
|
2679
|
-
y: number;
|
|
2680
|
-
};
|
|
2681
|
-
children: string[];
|
|
2682
|
-
}
|
|
2683
|
-
/**
|
|
2684
|
-
* 编辑器连接格式
|
|
2685
|
-
*/
|
|
2686
|
-
interface EditorConnection {
|
|
2687
|
-
from: string;
|
|
2688
|
-
to: string;
|
|
2689
|
-
fromProperty?: string;
|
|
2690
|
-
toProperty?: string;
|
|
2691
|
-
connectionType: 'node' | 'property';
|
|
2692
|
-
}
|
|
2693
|
-
/**
|
|
2694
|
-
* 编辑器格式
|
|
2695
|
-
*/
|
|
2696
|
-
interface EditorFormat {
|
|
2697
|
-
version?: string;
|
|
2698
|
-
metadata?: {
|
|
2699
|
-
name: string;
|
|
2700
|
-
description?: string;
|
|
2701
|
-
createdAt?: string;
|
|
2702
|
-
modifiedAt?: string;
|
|
2703
|
-
};
|
|
2704
|
-
nodes: EditorNode[];
|
|
2705
|
-
connections: EditorConnection[];
|
|
2706
|
-
blackboard: Record<string, any>;
|
|
2707
|
-
canvasState?: {
|
|
2708
|
-
offset: {
|
|
2709
|
-
x: number;
|
|
2710
|
-
y: number;
|
|
2711
|
-
};
|
|
2712
|
-
scale: number;
|
|
2713
|
-
};
|
|
2714
|
-
}
|
|
2715
|
-
/**
|
|
2716
|
-
* 编辑器格式转换器
|
|
2717
|
-
*
|
|
2718
|
-
* 将编辑器格式转换为运行时资产格式
|
|
2719
|
-
*/
|
|
2720
|
-
declare class EditorFormatConverter {
|
|
2721
|
-
/**
|
|
2722
|
-
* 转换编辑器格式为资产格式
|
|
2723
|
-
*
|
|
2724
|
-
* @param editorData 编辑器数据
|
|
2725
|
-
* @param metadata 可选的元数据覆盖
|
|
2726
|
-
* @returns 行为树资产
|
|
2727
|
-
*/
|
|
2728
|
-
static toAsset(editorData: EditorFormat, metadata?: Partial<AssetMetadata>): BehaviorTreeAsset;
|
|
2729
|
-
/**
|
|
2730
|
-
* 查找根节点
|
|
2731
|
-
*/
|
|
2732
|
-
private static findRootNode;
|
|
2733
|
-
/**
|
|
2734
|
-
* 转换节点列表
|
|
2735
|
-
*/
|
|
2736
|
-
private static convertNodes;
|
|
2737
|
-
/**
|
|
2738
|
-
* 转换单个节点
|
|
2739
|
-
*/
|
|
2740
|
-
private static convertNode;
|
|
2741
|
-
/**
|
|
2742
|
-
* 转换黑板变量
|
|
2743
|
-
*/
|
|
2744
|
-
private static convertBlackboard;
|
|
2745
|
-
/**
|
|
2746
|
-
* 推断黑板变量类型
|
|
2747
|
-
*/
|
|
2748
|
-
private static inferBlackboardType;
|
|
2749
|
-
/**
|
|
2750
|
-
* 转换属性绑定
|
|
2751
|
-
*/
|
|
2752
|
-
private static convertPropertyBindings;
|
|
2753
|
-
/**
|
|
2754
|
-
* 从资产格式转换回编辑器格式(用于加载)
|
|
2755
|
-
*
|
|
2756
|
-
* @param asset 行为树资产
|
|
2757
|
-
* @returns 编辑器格式数据
|
|
2758
|
-
*/
|
|
2759
|
-
static fromAsset(asset: BehaviorTreeAsset): EditorFormat;
|
|
2760
|
-
/**
|
|
2761
|
-
* 从资产格式转换节点
|
|
2762
|
-
*/
|
|
2763
|
-
private static convertNodesFromAsset;
|
|
2764
|
-
/**
|
|
2765
|
-
* 推断节点分类
|
|
2766
|
-
*/
|
|
2767
|
-
private static inferCategory;
|
|
2768
|
-
/**
|
|
2769
|
-
* 将属性绑定转换为连接
|
|
2770
|
-
*/
|
|
2771
|
-
private static convertPropertyBindingsToConnections;
|
|
2772
|
-
/**
|
|
2773
|
-
* 根据children关系构建节点连接
|
|
2774
|
-
*/
|
|
2775
|
-
private static buildNodeConnections;
|
|
2776
|
-
}
|
|
2777
|
-
|
|
2778
|
-
/**
|
|
2779
|
-
* 行为树节点元数据
|
|
2780
|
-
*/
|
|
2781
|
-
interface BehaviorNodeMetadata {
|
|
2782
|
-
displayName: string;
|
|
2783
|
-
category: string;
|
|
2784
|
-
type: NodeType;
|
|
2785
|
-
icon?: string;
|
|
2786
|
-
description: string;
|
|
2787
|
-
color?: string;
|
|
2788
|
-
className?: string;
|
|
2789
|
-
/**
|
|
2790
|
-
* 是否需要子节点
|
|
2791
|
-
* - true: 节点需要子节点(如 SequenceNode、DecoratorNode)
|
|
2792
|
-
* - false: 节点不需要子节点(如 ActionNode、SubTreeNode)
|
|
2793
|
-
* - undefined: 根据节点类型自动判断
|
|
2794
|
-
*/
|
|
2795
|
-
requiresChildren?: boolean;
|
|
2796
|
-
}
|
|
2797
|
-
/**
|
|
2798
|
-
* 节点类注册表
|
|
2799
|
-
*/
|
|
2800
|
-
declare class NodeClassRegistry {
|
|
2801
|
-
private static nodeClasses;
|
|
2802
|
-
static registerNodeClass(constructor: any, metadata: BehaviorNodeMetadata): void;
|
|
2803
|
-
static getAllNodeClasses(): Array<{
|
|
2804
|
-
metadata: BehaviorNodeMetadata;
|
|
2805
|
-
constructor: any;
|
|
2806
|
-
}>;
|
|
2807
|
-
static getNodeClass(category: string, displayName: string): any;
|
|
2808
|
-
static clear(): void;
|
|
2809
|
-
}
|
|
2810
|
-
/**
|
|
2811
|
-
* 行为树节点装饰器
|
|
2812
|
-
*
|
|
2813
|
-
* 用于标注一个类是可在编辑器中使用的行为树节点
|
|
2814
|
-
*
|
|
2815
|
-
* @example
|
|
2816
|
-
* ```typescript
|
|
2817
|
-
* @BehaviorNode({
|
|
2818
|
-
* displayName: '等待',
|
|
2819
|
-
* category: '动作',
|
|
2820
|
-
* type: NodeType.Action,
|
|
2821
|
-
* icon: 'Clock',
|
|
2822
|
-
* description: '等待指定时间',
|
|
2823
|
-
* color: '#9E9E9E'
|
|
2824
|
-
* })
|
|
2825
|
-
* class WaitNode extends Component {
|
|
2826
|
-
* @BehaviorProperty({
|
|
2827
|
-
* label: '持续时间',
|
|
2828
|
-
* type: 'number',
|
|
2829
|
-
* min: 0,
|
|
2830
|
-
* step: 0.1,
|
|
2831
|
-
* description: '等待时间(秒)'
|
|
2832
|
-
* })
|
|
2833
|
-
* duration: number = 1.0;
|
|
2834
|
-
* }
|
|
2835
|
-
* ```
|
|
2836
|
-
*/
|
|
2837
|
-
declare function BehaviorNode(metadata: BehaviorNodeMetadata): <T extends {
|
|
2838
|
-
new (...args: any[]): any;
|
|
2839
|
-
}>(constructor: T) => T;
|
|
2840
|
-
/**
|
|
2841
|
-
* 行为树属性装饰器
|
|
2842
|
-
*
|
|
2843
|
-
* 用于标注节点的可配置属性,这些属性会在编辑器中显示
|
|
2844
|
-
*
|
|
2845
|
-
* @example
|
|
2846
|
-
* ```typescript
|
|
2847
|
-
* @BehaviorNode({ ... })
|
|
2848
|
-
* class MyNode {
|
|
2849
|
-
* @BehaviorProperty({
|
|
2850
|
-
* label: '速度',
|
|
2851
|
-
* type: 'number',
|
|
2852
|
-
* min: 0,
|
|
2853
|
-
* max: 100,
|
|
2854
|
-
* description: '移动速度'
|
|
2855
|
-
* })
|
|
2856
|
-
* speed: number = 10;
|
|
2857
|
-
* }
|
|
2858
|
-
* ```
|
|
2859
|
-
*/
|
|
2860
|
-
declare function BehaviorProperty(config: Omit<PropertyDefinition, 'name' | 'defaultValue'>): (target: any, propertyKey: string) => void;
|
|
2861
|
-
/**
|
|
2862
|
-
* @deprecated 使用 BehaviorProperty 代替
|
|
2863
|
-
*/
|
|
2864
|
-
declare const NodeProperty: typeof BehaviorProperty;
|
|
2865
|
-
/**
|
|
2866
|
-
* 获取所有注册的节点模板
|
|
2867
|
-
*/
|
|
2868
|
-
declare function getRegisteredNodeTemplates(): NodeTemplate[];
|
|
2869
|
-
/**
|
|
2870
|
-
* 清空所有注册的节点类
|
|
2871
|
-
*/
|
|
2872
|
-
declare function clearRegisteredNodes(): void;
|
|
2873
|
-
|
|
2874
|
-
export { AbortType, ActiveNode, AlwaysFailNode, AlwaysSucceedNode, AssetLoadingManager, AssetType, BehaviorNode, BehaviorProperty, BehaviorTreeAssetLoader, BehaviorTreeAssetMetadata, BehaviorTreeAssetSerializer, BehaviorTreeAssetValidator, BehaviorTreeBuilder, BehaviorTreeNode, BehaviorTreePersistence, BehaviorTreePlugin, BehaviorTreeStarter, BlackboardCompareCondition, BlackboardComponent, BlackboardExistsCondition, BlackboardValueType, CircularDependencyError, CompareOperator, CompositeExecutionSystem, CompositeNodeComponent, CompositeType, ConditionalNode, CooldownNode, DecoratorExecutionSystem, DecoratorNodeComponent, DecoratorType, EditorFormatConverter, EntityDestroyedError, ExecuteAction, ExecuteCondition, FileSystemAssetLoader, GlobalBlackboardService, InverterNode, LeafExecutionSystem, LoadingState, LogAction, LogOutput, ModifyBlackboardValueAction, ModifyOperation, NodeClassRegistry, NodeProperty, NodeTemplates, NodeType, ParallelNode, ParallelSelectorNode, PropertyBindings, RandomProbabilityCondition, RandomSelectorNode, RandomSequenceNode, RepeaterNode, RootExecutionSystem, RootNode, SelectorNode, SequenceNode, SetBlackboardValueAction, SubTreeExecutionSystem, SubTreeNode, TaskStatus, TimeoutError, TimeoutNode, UntilFailNode, UntilSuccessNode, WaitAction, WorkspaceService, clearRegisteredNodes, getRegisteredNodeTemplates };
|
|
2875
|
-
export type { AssetMetadata, AssetRegistry, AssetValidationResult, BehaviorNodeMetadata, BehaviorTreeAsset, BehaviorTreeNodeData, BlackboardVariable, BlackboardVariableDefinition, CustomActionFunction, CustomConditionFunction, DeserializationOptions, EditorConnection, EditorFormat, EditorNode, FileSystemAssetLoaderConfig, GlobalBlackboardConfig, IAssetLoader, InstantiateOptions, LoadingOptions, LoadingProgress, LoadingTask, LoadingTaskHandle, NodeDataJSON, NodeTemplate, PropertyBinding, PropertyDefinition, SerializationFormat, SerializationOptions, WorkspaceConfig };
|