@esengine/behavior-tree 1.0.0 → 1.0.1
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/index.cjs +1 -1
- package/index.cjs.map +1 -1
- package/index.d.ts +944 -2095
- package/index.es5.js +2 -2
- package/index.es5.js.map +1 -1
- package/index.mjs +1 -1
- package/index.mjs.map +1 -1
- package/index.umd.js +1 -1
- package/index.umd.js.map +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @esengine/behavior-tree v1.0.
|
|
2
|
+
* @esengine/behavior-tree v1.0.1
|
|
3
3
|
* TypeScript definitions
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { Component, IService, Entity, EntitySystem, IPlugin, Core, ServiceContainer, IScene } from '@esengine/ecs-framework';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* 任务执行状态
|
|
@@ -18,18 +18,33 @@ declare enum TaskStatus {
|
|
|
18
18
|
Running = 3
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* 内置节点类型常量
|
|
22
22
|
*/
|
|
23
|
-
declare
|
|
23
|
+
declare const NodeType: {
|
|
24
24
|
/** 复合节点 - 有多个子节点 */
|
|
25
|
-
Composite
|
|
25
|
+
readonly Composite: "composite";
|
|
26
26
|
/** 装饰器节点 - 有一个子节点 */
|
|
27
|
-
Decorator
|
|
27
|
+
readonly Decorator: "decorator";
|
|
28
28
|
/** 动作节点 - 叶子节点 */
|
|
29
|
-
Action
|
|
29
|
+
readonly Action: "action";
|
|
30
30
|
/** 条件节点 - 叶子节点 */
|
|
31
|
-
Condition
|
|
32
|
-
}
|
|
31
|
+
readonly Condition: "condition";
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* 节点类型(支持自定义扩展)
|
|
35
|
+
*
|
|
36
|
+
* 使用内置类型或自定义字符串
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // 使用内置类型
|
|
41
|
+
* type: NodeType.Action
|
|
42
|
+
*
|
|
43
|
+
* // 使用自定义类型
|
|
44
|
+
* type: 'custom-behavior'
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
type NodeType = typeof NodeType[keyof typeof NodeType] | string;
|
|
33
48
|
/**
|
|
34
49
|
* 复合节点类型
|
|
35
50
|
*/
|
|
@@ -97,1623 +112,1105 @@ declare enum BlackboardValueType {
|
|
|
97
112
|
Object = "object",
|
|
98
113
|
Array = "array"
|
|
99
114
|
}
|
|
100
|
-
|
|
101
115
|
/**
|
|
102
|
-
*
|
|
116
|
+
* 黑板变量定义
|
|
103
117
|
*/
|
|
104
|
-
interface
|
|
105
|
-
|
|
106
|
-
|
|
118
|
+
interface BlackboardVariable {
|
|
119
|
+
name: string;
|
|
120
|
+
type: BlackboardValueType;
|
|
121
|
+
value: any;
|
|
122
|
+
readonly?: boolean;
|
|
123
|
+
description?: string;
|
|
107
124
|
}
|
|
125
|
+
|
|
108
126
|
/**
|
|
109
|
-
*
|
|
127
|
+
* 行为树节点定义(纯数据结构)
|
|
110
128
|
*
|
|
111
|
-
*
|
|
129
|
+
* 不依赖Entity,可以被多个实例共享
|
|
130
|
+
*/
|
|
131
|
+
interface BehaviorNodeData {
|
|
132
|
+
/** 节点唯一ID */
|
|
133
|
+
id: string;
|
|
134
|
+
/** 节点名称(用于调试) */
|
|
135
|
+
name: string;
|
|
136
|
+
/** 节点类型 */
|
|
137
|
+
nodeType: NodeType;
|
|
138
|
+
/** 节点实现类型(对应Component类名) */
|
|
139
|
+
implementationType: string;
|
|
140
|
+
/** 子节点ID列表 */
|
|
141
|
+
children?: string[];
|
|
142
|
+
/** 节点特定配置数据 */
|
|
143
|
+
config: Record<string, any>;
|
|
144
|
+
/** 属性到黑板变量的绑定映射 */
|
|
145
|
+
bindings?: Record<string, string>;
|
|
146
|
+
/** 中止类型(条件装饰器使用) */
|
|
147
|
+
abortType?: AbortType;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* 行为树定义(可共享的Asset)
|
|
151
|
+
*/
|
|
152
|
+
interface BehaviorTreeData {
|
|
153
|
+
/** 树ID */
|
|
154
|
+
id: string;
|
|
155
|
+
/** 树名称 */
|
|
156
|
+
name: string;
|
|
157
|
+
/** 根节点ID */
|
|
158
|
+
rootNodeId: string;
|
|
159
|
+
/** 所有节点(扁平化存储) */
|
|
160
|
+
nodes: Map<string, BehaviorNodeData>;
|
|
161
|
+
/** 黑板变量定义 */
|
|
162
|
+
blackboardVariables?: Map<string, any>;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* 节点运行时状态
|
|
112
166
|
*
|
|
113
|
-
*
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
167
|
+
* 每个BehaviorTreeRuntimeComponent实例独立维护
|
|
168
|
+
*/
|
|
169
|
+
interface NodeRuntimeState {
|
|
170
|
+
/** 当前执行状态 */
|
|
171
|
+
status: TaskStatus;
|
|
172
|
+
/** 当前执行的子节点索引(复合节点使用) */
|
|
173
|
+
currentChildIndex: number;
|
|
174
|
+
/** 开始执行时间(某些节点需要) */
|
|
175
|
+
startTime?: number;
|
|
176
|
+
/** 上次执行时间(冷却节点使用) */
|
|
177
|
+
lastExecutionTime?: number;
|
|
178
|
+
/** 当前重复次数(重复节点使用) */
|
|
179
|
+
repeatCount?: number;
|
|
180
|
+
/** 缓存的结果(某些条件节点使用) */
|
|
181
|
+
cachedResult?: any;
|
|
182
|
+
/** 洗牌后的索引(随机节点使用) */
|
|
183
|
+
shuffledIndices?: number[];
|
|
184
|
+
/** 是否被中止 */
|
|
185
|
+
isAborted?: boolean;
|
|
186
|
+
/** 上次条件评估结果(条件装饰器使用) */
|
|
187
|
+
lastConditionResult?: boolean;
|
|
188
|
+
/** 正在观察的黑板键(条件装饰器使用) */
|
|
189
|
+
observedKeys?: string[];
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* 创建默认的运行时状态
|
|
193
|
+
*/
|
|
194
|
+
declare function createDefaultRuntimeState(): NodeRuntimeState;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 黑板变化监听器
|
|
198
|
+
*/
|
|
199
|
+
type BlackboardChangeListener = (key: string, newValue: any, oldValue: any) => void;
|
|
200
|
+
/**
|
|
201
|
+
* 行为树运行时组件
|
|
117
202
|
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* ```
|
|
203
|
+
* 挂载到游戏Entity上,引用共享的BehaviorTreeData
|
|
204
|
+
* 维护该Entity独立的运行时状态
|
|
121
205
|
*/
|
|
122
|
-
declare class
|
|
123
|
-
private variables;
|
|
124
|
-
dispose(): void;
|
|
206
|
+
declare class BehaviorTreeRuntimeComponent extends Component {
|
|
125
207
|
/**
|
|
126
|
-
*
|
|
208
|
+
* 引用的行为树资产ID(可序列化)
|
|
127
209
|
*/
|
|
128
|
-
|
|
129
|
-
readonly?: boolean;
|
|
130
|
-
description?: string;
|
|
131
|
-
}): void;
|
|
210
|
+
treeAssetId: string;
|
|
132
211
|
/**
|
|
133
|
-
*
|
|
212
|
+
* 是否自动启动
|
|
134
213
|
*/
|
|
135
|
-
|
|
214
|
+
autoStart: boolean;
|
|
136
215
|
/**
|
|
137
|
-
*
|
|
216
|
+
* 是否正在运行
|
|
138
217
|
*/
|
|
139
|
-
|
|
218
|
+
isRunning: boolean;
|
|
140
219
|
/**
|
|
141
|
-
*
|
|
220
|
+
* 节点运行时状态(每个节点独立)
|
|
221
|
+
* 不序列化,每次加载时重新初始化
|
|
142
222
|
*/
|
|
143
|
-
|
|
223
|
+
private nodeStates;
|
|
144
224
|
/**
|
|
145
|
-
*
|
|
225
|
+
* 黑板数据(该Entity独立的数据)
|
|
226
|
+
* 不序列化,通过初始化设置
|
|
146
227
|
*/
|
|
147
|
-
|
|
228
|
+
private blackboard;
|
|
148
229
|
/**
|
|
149
|
-
*
|
|
230
|
+
* 黑板观察者列表
|
|
150
231
|
*/
|
|
151
|
-
|
|
232
|
+
private blackboardObservers;
|
|
152
233
|
/**
|
|
153
|
-
*
|
|
234
|
+
* 当前激活的节点ID列表(用于调试)
|
|
154
235
|
*/
|
|
155
|
-
|
|
236
|
+
activeNodeIds: Set<string>;
|
|
156
237
|
/**
|
|
157
|
-
*
|
|
238
|
+
* 标记是否需要在下一个tick重置状态
|
|
158
239
|
*/
|
|
159
|
-
|
|
240
|
+
needsReset: boolean;
|
|
160
241
|
/**
|
|
161
|
-
*
|
|
242
|
+
* 需要中止的节点ID列表
|
|
162
243
|
*/
|
|
163
|
-
|
|
244
|
+
nodesToAbort: Set<string>;
|
|
164
245
|
/**
|
|
165
|
-
*
|
|
246
|
+
* 获取节点运行时状态
|
|
166
247
|
*/
|
|
167
|
-
|
|
248
|
+
getNodeState(nodeId: string): NodeRuntimeState;
|
|
168
249
|
/**
|
|
169
|
-
*
|
|
250
|
+
* 重置节点状态
|
|
170
251
|
*/
|
|
171
|
-
|
|
252
|
+
resetNodeState(nodeId: string): void;
|
|
172
253
|
/**
|
|
173
|
-
*
|
|
254
|
+
* 重置所有节点状态
|
|
174
255
|
*/
|
|
175
|
-
|
|
256
|
+
resetAllStates(): void;
|
|
176
257
|
/**
|
|
177
|
-
*
|
|
258
|
+
* 获取黑板值
|
|
178
259
|
*/
|
|
179
|
-
|
|
260
|
+
getBlackboardValue<T = any>(key: string): T | undefined;
|
|
180
261
|
/**
|
|
181
|
-
*
|
|
262
|
+
* 设置黑板值
|
|
182
263
|
*/
|
|
183
|
-
|
|
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;
|
|
264
|
+
setBlackboardValue(key: string, value: any): void;
|
|
210
265
|
/**
|
|
211
|
-
*
|
|
266
|
+
* 检查黑板是否有某个键
|
|
212
267
|
*/
|
|
213
|
-
|
|
214
|
-
readonly?: boolean;
|
|
215
|
-
description?: string;
|
|
216
|
-
}): void;
|
|
268
|
+
hasBlackboardKey(key: string): boolean;
|
|
217
269
|
/**
|
|
218
|
-
*
|
|
219
|
-
* 先查找本地变量,找不到则查找全局变量
|
|
270
|
+
* 初始化黑板(从树定义的默认值)
|
|
220
271
|
*/
|
|
221
|
-
|
|
272
|
+
initializeBlackboard(variables?: Map<string, any>): void;
|
|
222
273
|
/**
|
|
223
|
-
*
|
|
274
|
+
* 清空黑板
|
|
224
275
|
*/
|
|
225
|
-
|
|
276
|
+
clearBlackboard(): void;
|
|
226
277
|
/**
|
|
227
|
-
*
|
|
228
|
-
* 优先设置本地变量,如果本地不存在且全局存在,则设置全局变量
|
|
278
|
+
* 启动行为树
|
|
229
279
|
*/
|
|
230
|
-
|
|
280
|
+
start(): void;
|
|
231
281
|
/**
|
|
232
|
-
*
|
|
282
|
+
* 停止行为树
|
|
233
283
|
*/
|
|
234
|
-
|
|
284
|
+
stop(): void;
|
|
235
285
|
/**
|
|
236
|
-
*
|
|
286
|
+
* 暂停行为树
|
|
237
287
|
*/
|
|
238
|
-
|
|
288
|
+
pause(): void;
|
|
239
289
|
/**
|
|
240
|
-
*
|
|
290
|
+
* 恢复行为树
|
|
241
291
|
*/
|
|
242
|
-
|
|
292
|
+
resume(): void;
|
|
243
293
|
/**
|
|
244
|
-
*
|
|
294
|
+
* 注册黑板观察者
|
|
245
295
|
*/
|
|
246
|
-
|
|
296
|
+
observeBlackboard(nodeId: string, keys: string[], callback: BlackboardChangeListener): void;
|
|
247
297
|
/**
|
|
248
|
-
*
|
|
298
|
+
* 取消注册黑板观察者
|
|
249
299
|
*/
|
|
250
|
-
|
|
300
|
+
unobserveBlackboard(nodeId: string): void;
|
|
251
301
|
/**
|
|
252
|
-
*
|
|
302
|
+
* 通知黑板变化
|
|
253
303
|
*/
|
|
254
|
-
|
|
304
|
+
private notifyBlackboardChange;
|
|
255
305
|
/**
|
|
256
|
-
*
|
|
306
|
+
* 请求中止节点
|
|
257
307
|
*/
|
|
258
|
-
|
|
308
|
+
requestAbort(nodeId: string): void;
|
|
259
309
|
/**
|
|
260
|
-
*
|
|
310
|
+
* 检查节点是否需要中止
|
|
261
311
|
*/
|
|
262
|
-
|
|
312
|
+
shouldAbort(nodeId: string): boolean;
|
|
263
313
|
/**
|
|
264
|
-
*
|
|
314
|
+
* 清除中止请求
|
|
265
315
|
*/
|
|
266
|
-
|
|
316
|
+
clearAbortRequest(nodeId: string): void;
|
|
267
317
|
/**
|
|
268
|
-
*
|
|
318
|
+
* 清除所有中止请求
|
|
269
319
|
*/
|
|
270
|
-
|
|
320
|
+
clearAllAbortRequests(): void;
|
|
271
321
|
}
|
|
272
322
|
|
|
273
323
|
/**
|
|
274
|
-
*
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
* 执行自定义函数动作组件
|
|
324
|
+
* 行为树资产管理器(服务)
|
|
325
|
+
*
|
|
326
|
+
* 管理所有共享的BehaviorTreeData
|
|
327
|
+
* 多个实例可以引用同一份数据
|
|
279
328
|
*
|
|
280
|
-
*
|
|
329
|
+
* 使用方式:
|
|
330
|
+
* ```typescript
|
|
331
|
+
* // 注册服务
|
|
332
|
+
* Core.services.registerSingleton(BehaviorTreeAssetManager);
|
|
333
|
+
*
|
|
334
|
+
* // 使用服务
|
|
335
|
+
* const assetManager = Core.services.resolve(BehaviorTreeAssetManager);
|
|
336
|
+
* ```
|
|
281
337
|
*/
|
|
282
|
-
declare class
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
private
|
|
338
|
+
declare class BehaviorTreeAssetManager implements IService {
|
|
339
|
+
/**
|
|
340
|
+
* 已加载的行为树资产
|
|
341
|
+
*/
|
|
342
|
+
private assets;
|
|
343
|
+
/**
|
|
344
|
+
* 加载行为树资产
|
|
345
|
+
*/
|
|
346
|
+
loadAsset(asset: BehaviorTreeData): void;
|
|
347
|
+
/**
|
|
348
|
+
* 获取行为树资产
|
|
349
|
+
*/
|
|
350
|
+
getAsset(assetId: string): BehaviorTreeData | undefined;
|
|
351
|
+
/**
|
|
352
|
+
* 检查资产是否存在
|
|
353
|
+
*/
|
|
354
|
+
hasAsset(assetId: string): boolean;
|
|
355
|
+
/**
|
|
356
|
+
* 卸载行为树资产
|
|
357
|
+
*/
|
|
358
|
+
unloadAsset(assetId: string): boolean;
|
|
287
359
|
/**
|
|
288
|
-
*
|
|
360
|
+
* 清空所有资产
|
|
289
361
|
*/
|
|
290
|
-
|
|
362
|
+
clearAll(): void;
|
|
291
363
|
/**
|
|
292
|
-
*
|
|
364
|
+
* 获取已加载资产数量
|
|
293
365
|
*/
|
|
294
|
-
|
|
366
|
+
getAssetCount(): number;
|
|
367
|
+
/**
|
|
368
|
+
* 获取所有资产ID
|
|
369
|
+
*/
|
|
370
|
+
getAllAssetIds(): string[];
|
|
371
|
+
/**
|
|
372
|
+
* 释放资源(实现IService接口)
|
|
373
|
+
*/
|
|
374
|
+
dispose(): void;
|
|
295
375
|
}
|
|
296
376
|
|
|
297
377
|
/**
|
|
298
|
-
*
|
|
378
|
+
* 节点执行上下文
|
|
299
379
|
*
|
|
300
|
-
*
|
|
380
|
+
* 包含执行节点所需的所有信息
|
|
381
|
+
*/
|
|
382
|
+
interface NodeExecutionContext {
|
|
383
|
+
/** 游戏Entity(行为树宿主) */
|
|
384
|
+
readonly entity: Entity;
|
|
385
|
+
/** 节点数据 */
|
|
386
|
+
readonly nodeData: BehaviorNodeData;
|
|
387
|
+
/** 节点运行时状态 */
|
|
388
|
+
readonly state: NodeRuntimeState;
|
|
389
|
+
/** 运行时组件(访问黑板等) */
|
|
390
|
+
readonly runtime: BehaviorTreeRuntimeComponent;
|
|
391
|
+
/** 行为树数据(访问子节点等) */
|
|
392
|
+
readonly treeData: BehaviorTreeData;
|
|
393
|
+
/** 当前帧增量时间 */
|
|
394
|
+
readonly deltaTime: number;
|
|
395
|
+
/** 总时间 */
|
|
396
|
+
readonly totalTime: number;
|
|
397
|
+
/** 执行子节点 */
|
|
398
|
+
executeChild(childId: string): TaskStatus;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* 节点执行器接口
|
|
402
|
+
*
|
|
403
|
+
* 所有节点类型都需要实现对应的执行器
|
|
404
|
+
* 执行器是无状态的,状态存储在NodeRuntimeState中
|
|
301
405
|
*/
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
406
|
+
interface INodeExecutor {
|
|
407
|
+
/**
|
|
408
|
+
* 执行节点逻辑
|
|
409
|
+
*
|
|
410
|
+
* @param context 执行上下文
|
|
411
|
+
* @returns 执行结果状态
|
|
412
|
+
*/
|
|
413
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
306
414
|
/**
|
|
307
|
-
*
|
|
415
|
+
* 重置节点状态(可选)
|
|
416
|
+
*
|
|
417
|
+
* 当节点完成或被中断时调用
|
|
308
418
|
*/
|
|
309
|
-
reset(): void;
|
|
419
|
+
reset?(context: NodeExecutionContext): void;
|
|
310
420
|
}
|
|
311
|
-
|
|
312
421
|
/**
|
|
313
|
-
*
|
|
422
|
+
* 绑定辅助工具
|
|
314
423
|
*
|
|
315
|
-
*
|
|
424
|
+
* 处理配置属性的黑板绑定
|
|
316
425
|
*/
|
|
317
|
-
declare class
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
426
|
+
declare class BindingHelper {
|
|
427
|
+
/**
|
|
428
|
+
* 获取配置值(考虑黑板绑定)
|
|
429
|
+
*
|
|
430
|
+
* @param context 执行上下文
|
|
431
|
+
* @param configKey 配置键名
|
|
432
|
+
* @param defaultValue 默认值
|
|
433
|
+
* @returns 解析后的值
|
|
434
|
+
*/
|
|
435
|
+
static getValue<T = any>(context: NodeExecutionContext, configKey: string, defaultValue?: T): T;
|
|
436
|
+
/**
|
|
437
|
+
* 检查配置是否绑定到黑板变量
|
|
438
|
+
*/
|
|
439
|
+
static hasBinding(context: NodeExecutionContext, configKey: string): boolean;
|
|
440
|
+
/**
|
|
441
|
+
* 获取绑定的黑板变量名
|
|
442
|
+
*/
|
|
443
|
+
static getBindingKey(context: NodeExecutionContext, configKey: string): string | undefined;
|
|
321
444
|
}
|
|
322
|
-
|
|
323
445
|
/**
|
|
324
|
-
*
|
|
446
|
+
* 节点执行器注册表
|
|
325
447
|
*
|
|
326
|
-
*
|
|
448
|
+
* 管理所有节点类型的执行器
|
|
327
449
|
*/
|
|
328
|
-
declare class
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
450
|
+
declare class NodeExecutorRegistry {
|
|
451
|
+
private executors;
|
|
452
|
+
/**
|
|
453
|
+
* 注册执行器
|
|
454
|
+
*
|
|
455
|
+
* @param implementationType 节点实现类型(对应BehaviorNodeData.implementationType)
|
|
456
|
+
* @param executor 执行器实例
|
|
457
|
+
*/
|
|
458
|
+
register(implementationType: string, executor: INodeExecutor): void;
|
|
459
|
+
/**
|
|
460
|
+
* 获取执行器
|
|
461
|
+
*/
|
|
462
|
+
get(implementationType: string): INodeExecutor | undefined;
|
|
463
|
+
/**
|
|
464
|
+
* 检查是否有执行器
|
|
465
|
+
*/
|
|
466
|
+
has(implementationType: string): boolean;
|
|
467
|
+
/**
|
|
468
|
+
* 注销执行器
|
|
469
|
+
*/
|
|
470
|
+
unregister(implementationType: string): boolean;
|
|
471
|
+
/**
|
|
472
|
+
* 清空所有执行器
|
|
473
|
+
*/
|
|
474
|
+
clear(): void;
|
|
333
475
|
}
|
|
334
476
|
|
|
335
477
|
/**
|
|
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
|
-
* 修改黑板变量值动作组件
|
|
478
|
+
* 序列节点执行器
|
|
356
479
|
*
|
|
357
|
-
*
|
|
480
|
+
* 按顺序执行子节点,全部成功才成功,任一失败则失败
|
|
358
481
|
*/
|
|
359
|
-
declare class
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
operand: any;
|
|
363
|
-
force: boolean;
|
|
482
|
+
declare class SequenceExecutor implements INodeExecutor {
|
|
483
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
484
|
+
reset(context: NodeExecutionContext): void;
|
|
364
485
|
}
|
|
365
486
|
|
|
366
487
|
/**
|
|
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
|
-
* 黑板变量比较条件组件
|
|
488
|
+
* 选择器节点执行器
|
|
389
489
|
*
|
|
390
|
-
*
|
|
490
|
+
* 按顺序执行子节点,任一成功则成功,全部失败才失败
|
|
391
491
|
*/
|
|
392
|
-
declare class
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
compareValue: any;
|
|
396
|
-
invertResult: boolean;
|
|
492
|
+
declare class SelectorExecutor implements INodeExecutor {
|
|
493
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
494
|
+
reset(context: NodeExecutionContext): void;
|
|
397
495
|
}
|
|
398
496
|
|
|
399
497
|
/**
|
|
400
|
-
*
|
|
498
|
+
* 并行节点执行器
|
|
401
499
|
*
|
|
402
|
-
*
|
|
500
|
+
* 同时执行所有子节点
|
|
403
501
|
*/
|
|
404
|
-
declare class
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
502
|
+
declare class ParallelExecutor implements INodeExecutor {
|
|
503
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
504
|
+
private stopAllChildren;
|
|
505
|
+
reset(context: NodeExecutionContext): void;
|
|
408
506
|
}
|
|
409
507
|
|
|
410
508
|
/**
|
|
411
|
-
*
|
|
509
|
+
* 并行选择器执行器
|
|
412
510
|
*
|
|
413
|
-
*
|
|
511
|
+
* 并行执行子节点,任一成功则成功
|
|
414
512
|
*/
|
|
415
|
-
declare class
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
private cachedResult?;
|
|
420
|
-
/**
|
|
421
|
-
* 评估随机概率
|
|
422
|
-
*/
|
|
423
|
-
evaluate(): boolean;
|
|
424
|
-
/**
|
|
425
|
-
* 重置缓存
|
|
426
|
-
*/
|
|
427
|
-
reset(): void;
|
|
513
|
+
declare class ParallelSelectorExecutor implements INodeExecutor {
|
|
514
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
515
|
+
private stopAllChildren;
|
|
516
|
+
reset(context: NodeExecutionContext): void;
|
|
428
517
|
}
|
|
429
518
|
|
|
430
519
|
/**
|
|
431
|
-
*
|
|
432
|
-
*/
|
|
433
|
-
type CustomConditionFunction = (entity: Entity, blackboard?: BlackboardComponent, deltaTime?: number) => boolean;
|
|
434
|
-
/**
|
|
435
|
-
* 执行自定义条件组件
|
|
520
|
+
* 随机序列执行器
|
|
436
521
|
*
|
|
437
|
-
*
|
|
522
|
+
* 随机顺序执行子节点序列,全部成功才成功
|
|
438
523
|
*/
|
|
439
|
-
declare class
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
/** 编译后的函数(不序列化) */
|
|
444
|
-
private compiledFunction?;
|
|
445
|
-
/**
|
|
446
|
-
* 获取或编译条件函数
|
|
447
|
-
*/
|
|
448
|
-
getFunction(): CustomConditionFunction | undefined;
|
|
449
|
-
/**
|
|
450
|
-
* 设置自定义函数(运行时使用)
|
|
451
|
-
*/
|
|
452
|
-
setFunction(func: CustomConditionFunction): void;
|
|
524
|
+
declare class RandomSequenceExecutor implements INodeExecutor {
|
|
525
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
526
|
+
private shuffleIndices;
|
|
527
|
+
reset(context: NodeExecutionContext): void;
|
|
453
528
|
}
|
|
454
529
|
|
|
455
530
|
/**
|
|
456
|
-
*
|
|
531
|
+
* 随机选择器执行器
|
|
457
532
|
*
|
|
458
|
-
*
|
|
533
|
+
* 随机顺序执行子节点,任一成功则成功
|
|
459
534
|
*/
|
|
460
|
-
declare class
|
|
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
|
-
*/
|
|
535
|
+
declare class RandomSelectorExecutor implements INodeExecutor {
|
|
536
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
474
537
|
private shuffleIndices;
|
|
475
|
-
|
|
476
|
-
* 重置洗牌状态
|
|
477
|
-
*/
|
|
478
|
-
resetShuffle(): void;
|
|
538
|
+
reset(context: NodeExecutionContext): void;
|
|
479
539
|
}
|
|
480
540
|
|
|
481
541
|
/**
|
|
482
|
-
*
|
|
542
|
+
* 反转装饰器执行器
|
|
483
543
|
*
|
|
484
|
-
*
|
|
544
|
+
* 反转子节点的执行结果
|
|
485
545
|
*/
|
|
486
|
-
declare class
|
|
487
|
-
|
|
488
|
-
|
|
546
|
+
declare class InverterExecutor implements INodeExecutor {
|
|
547
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
548
|
+
reset(context: NodeExecutionContext): void;
|
|
489
549
|
}
|
|
490
550
|
|
|
491
551
|
/**
|
|
492
|
-
*
|
|
552
|
+
* 重复装饰器执行器
|
|
493
553
|
*
|
|
494
|
-
*
|
|
554
|
+
* 重复执行子节点指定次数
|
|
495
555
|
*/
|
|
496
|
-
declare class
|
|
497
|
-
|
|
498
|
-
|
|
556
|
+
declare class RepeaterExecutor implements INodeExecutor {
|
|
557
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
558
|
+
reset(context: NodeExecutionContext): void;
|
|
499
559
|
}
|
|
500
560
|
|
|
501
561
|
/**
|
|
502
|
-
*
|
|
562
|
+
* 总是成功装饰器执行器
|
|
503
563
|
*
|
|
504
|
-
*
|
|
564
|
+
* 无论子节点结果如何都返回成功
|
|
505
565
|
*/
|
|
506
|
-
declare class
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
constructor();
|
|
566
|
+
declare class AlwaysSucceedExecutor implements INodeExecutor {
|
|
567
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
568
|
+
reset(context: NodeExecutionContext): void;
|
|
510
569
|
}
|
|
511
570
|
|
|
512
571
|
/**
|
|
513
|
-
*
|
|
572
|
+
* 总是失败装饰器执行器
|
|
514
573
|
*
|
|
515
|
-
*
|
|
574
|
+
* 无论子节点结果如何都返回失败
|
|
516
575
|
*/
|
|
517
|
-
declare class
|
|
518
|
-
|
|
519
|
-
|
|
576
|
+
declare class AlwaysFailExecutor implements INodeExecutor {
|
|
577
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
578
|
+
reset(context: NodeExecutionContext): void;
|
|
520
579
|
}
|
|
521
580
|
|
|
522
581
|
/**
|
|
523
|
-
*
|
|
582
|
+
* 直到成功装饰器执行器
|
|
524
583
|
*
|
|
525
|
-
*
|
|
584
|
+
* 重复执行子节点直到成功
|
|
526
585
|
*/
|
|
527
|
-
declare class
|
|
528
|
-
|
|
529
|
-
|
|
586
|
+
declare class UntilSuccessExecutor implements INodeExecutor {
|
|
587
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
588
|
+
reset(context: NodeExecutionContext): void;
|
|
530
589
|
}
|
|
531
590
|
|
|
532
591
|
/**
|
|
533
|
-
*
|
|
592
|
+
* 直到失败装饰器执行器
|
|
534
593
|
*
|
|
535
|
-
*
|
|
594
|
+
* 重复执行子节点直到失败
|
|
536
595
|
*/
|
|
537
|
-
declare class
|
|
538
|
-
|
|
539
|
-
|
|
596
|
+
declare class UntilFailExecutor implements INodeExecutor {
|
|
597
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
598
|
+
reset(context: NodeExecutionContext): void;
|
|
540
599
|
}
|
|
541
600
|
|
|
542
601
|
/**
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
* 允许将其他行为树嵌入到当前树中,实现行为树的复用和模块化。
|
|
602
|
+
* 条件装饰器执行器
|
|
546
603
|
*
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
* @example
|
|
551
|
-
* ```typescript
|
|
552
|
-
* const subTree = entity.addComponent(SubTreeNode);
|
|
553
|
-
* subTree.assetId = 'patrol';
|
|
554
|
-
* subTree.inheritParentBlackboard = true;
|
|
555
|
-
* ```
|
|
604
|
+
* 根据条件决定是否执行子节点
|
|
605
|
+
* 支持动态优先级和中止机制
|
|
556
606
|
*/
|
|
557
|
-
declare class
|
|
558
|
-
|
|
559
|
-
|
|
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;
|
|
607
|
+
declare class ConditionalExecutor implements INodeExecutor {
|
|
608
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
609
|
+
private evaluateCondition;
|
|
614
610
|
/**
|
|
615
|
-
*
|
|
611
|
+
* 设置黑板观察者
|
|
616
612
|
*/
|
|
617
|
-
|
|
613
|
+
private setupObserver;
|
|
618
614
|
/**
|
|
619
|
-
*
|
|
615
|
+
* 处理条件变为true
|
|
620
616
|
*/
|
|
621
|
-
|
|
617
|
+
private handleConditionBecameTrue;
|
|
622
618
|
/**
|
|
623
|
-
*
|
|
624
|
-
* 保留子树根引用,只重置完成标记
|
|
619
|
+
* 处理条件变为false
|
|
625
620
|
*/
|
|
626
|
-
|
|
621
|
+
private handleConditionBecameFalse;
|
|
627
622
|
/**
|
|
628
|
-
*
|
|
623
|
+
* 请求中止低优先级节点
|
|
629
624
|
*/
|
|
630
|
-
|
|
625
|
+
private requestAbortLowerPriority;
|
|
626
|
+
reset(context: NodeExecutionContext): void;
|
|
631
627
|
}
|
|
632
628
|
|
|
633
629
|
/**
|
|
634
|
-
*
|
|
630
|
+
* 冷却装饰器执行器
|
|
635
631
|
*
|
|
636
|
-
*
|
|
637
|
-
* 具体的属性由各个子类自己定义
|
|
632
|
+
* 子节点执行成功后进入冷却时间
|
|
638
633
|
*/
|
|
639
|
-
declare class
|
|
640
|
-
|
|
641
|
-
|
|
634
|
+
declare class CooldownExecutor implements INodeExecutor {
|
|
635
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
636
|
+
reset(context: NodeExecutionContext): void;
|
|
642
637
|
}
|
|
643
638
|
|
|
644
639
|
/**
|
|
645
|
-
*
|
|
640
|
+
* 超时装饰器执行器
|
|
646
641
|
*
|
|
647
|
-
*
|
|
642
|
+
* 限制子节点的执行时间
|
|
648
643
|
*/
|
|
649
|
-
declare class
|
|
650
|
-
|
|
644
|
+
declare class TimeoutExecutor implements INodeExecutor {
|
|
645
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
646
|
+
reset(context: NodeExecutionContext): void;
|
|
651
647
|
}
|
|
652
648
|
|
|
653
649
|
/**
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
* 重复执行子节点指定次数
|
|
650
|
+
* Service执行接口
|
|
657
651
|
*/
|
|
658
|
-
|
|
659
|
-
constructor();
|
|
660
|
-
repeatCount: number;
|
|
661
|
-
endOnFailure: boolean;
|
|
662
|
-
/** 当前已重复次数 */
|
|
663
|
-
currentRepeatCount: number;
|
|
652
|
+
interface IServiceExecutor {
|
|
664
653
|
/**
|
|
665
|
-
*
|
|
654
|
+
* Service开始执行
|
|
666
655
|
*/
|
|
667
|
-
|
|
656
|
+
onServiceStart?(context: NodeExecutionContext): void;
|
|
668
657
|
/**
|
|
669
|
-
*
|
|
658
|
+
* Service每帧更新
|
|
670
659
|
*/
|
|
671
|
-
|
|
660
|
+
onServiceTick(context: NodeExecutionContext): void;
|
|
672
661
|
/**
|
|
673
|
-
*
|
|
662
|
+
* Service结束执行
|
|
674
663
|
*/
|
|
675
|
-
|
|
664
|
+
onServiceEnd?(context: NodeExecutionContext): void;
|
|
676
665
|
}
|
|
677
|
-
|
|
678
666
|
/**
|
|
679
|
-
*
|
|
667
|
+
* Service注册表
|
|
668
|
+
*/
|
|
669
|
+
declare class ServiceRegistry {
|
|
670
|
+
private static services;
|
|
671
|
+
static register(name: string, service: IServiceExecutor): void;
|
|
672
|
+
static get(name: string): IServiceExecutor | undefined;
|
|
673
|
+
static has(name: string): boolean;
|
|
674
|
+
static unregister(name: string): boolean;
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Service装饰器执行器
|
|
680
678
|
*
|
|
681
|
-
*
|
|
679
|
+
* 在子节点执行期间持续运行后台逻辑
|
|
682
680
|
*/
|
|
683
|
-
declare class
|
|
684
|
-
|
|
681
|
+
declare class ServiceDecorator implements INodeExecutor {
|
|
682
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
683
|
+
reset(context: NodeExecutionContext): void;
|
|
685
684
|
}
|
|
686
685
|
|
|
687
686
|
/**
|
|
688
|
-
*
|
|
687
|
+
* 等待动作执行器
|
|
689
688
|
*
|
|
690
|
-
*
|
|
689
|
+
* 等待指定时间后返回成功
|
|
691
690
|
*/
|
|
692
|
-
declare class
|
|
693
|
-
|
|
691
|
+
declare class WaitAction implements INodeExecutor {
|
|
692
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
693
|
+
reset(context: NodeExecutionContext): void;
|
|
694
694
|
}
|
|
695
695
|
|
|
696
696
|
/**
|
|
697
|
-
*
|
|
697
|
+
* 日志动作执行器
|
|
698
698
|
*
|
|
699
|
-
*
|
|
699
|
+
* 输出日志信息
|
|
700
700
|
*/
|
|
701
|
-
declare class
|
|
702
|
-
|
|
701
|
+
declare class LogAction implements INodeExecutor {
|
|
702
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
703
|
+
private replaceBlackboardVariables;
|
|
704
|
+
private log;
|
|
703
705
|
}
|
|
704
706
|
|
|
705
707
|
/**
|
|
706
|
-
*
|
|
708
|
+
* 设置黑板值动作执行器
|
|
707
709
|
*
|
|
708
|
-
*
|
|
710
|
+
* 设置黑板中的变量值
|
|
709
711
|
*/
|
|
710
|
-
declare class
|
|
711
|
-
|
|
712
|
+
declare class SetBlackboardValue implements INodeExecutor {
|
|
713
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
712
714
|
}
|
|
713
715
|
|
|
714
716
|
/**
|
|
715
|
-
*
|
|
717
|
+
* 修改黑板值动作执行器
|
|
716
718
|
*
|
|
717
|
-
*
|
|
719
|
+
* 对黑板中的数值进行运算
|
|
718
720
|
*/
|
|
719
|
-
declare class
|
|
720
|
-
|
|
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;
|
|
721
|
+
declare class ModifyBlackboardValue implements INodeExecutor {
|
|
722
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
733
723
|
}
|
|
734
724
|
|
|
735
725
|
/**
|
|
736
|
-
*
|
|
726
|
+
* 执行动作执行器
|
|
737
727
|
*
|
|
738
|
-
*
|
|
728
|
+
* 执行自定义动作逻辑
|
|
739
729
|
*/
|
|
740
|
-
declare class
|
|
741
|
-
|
|
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;
|
|
730
|
+
declare class ExecuteAction implements INodeExecutor {
|
|
731
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
757
732
|
}
|
|
758
733
|
|
|
759
734
|
/**
|
|
760
|
-
*
|
|
735
|
+
* SubTree执行器
|
|
761
736
|
*
|
|
762
|
-
*
|
|
737
|
+
* 引用并执行其他行为树,实现模块化和复用
|
|
763
738
|
*/
|
|
764
|
-
declare class
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
* 记录开始时间
|
|
771
|
-
*/
|
|
772
|
-
recordStartTime(currentTime: number): void;
|
|
773
|
-
/**
|
|
774
|
-
* 检查是否超时
|
|
775
|
-
*/
|
|
776
|
-
isTimeout(currentTime: number): boolean;
|
|
777
|
-
/**
|
|
778
|
-
* 重置状态
|
|
779
|
-
*/
|
|
780
|
-
reset(): void;
|
|
739
|
+
declare class SubTreeExecutor implements INodeExecutor {
|
|
740
|
+
private assetManager;
|
|
741
|
+
private getAssetManager;
|
|
742
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
743
|
+
private executeSubTreeNode;
|
|
744
|
+
reset(context: NodeExecutionContext): void;
|
|
781
745
|
}
|
|
782
746
|
|
|
783
747
|
/**
|
|
784
|
-
*
|
|
748
|
+
* 黑板比较条件执行器
|
|
785
749
|
*
|
|
786
|
-
*
|
|
750
|
+
* 比较黑板中的值
|
|
787
751
|
*/
|
|
788
|
-
declare class
|
|
789
|
-
|
|
790
|
-
|
|
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;
|
|
752
|
+
declare class BlackboardCompare implements INodeExecutor {
|
|
753
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
754
|
+
private compare;
|
|
806
755
|
}
|
|
807
756
|
|
|
808
757
|
/**
|
|
809
|
-
*
|
|
810
|
-
*
|
|
811
|
-
* 标记当前应该被执行的节点。
|
|
812
|
-
* 只有带有此组件的节点才会被各个执行系统处理。
|
|
758
|
+
* 黑板存在检查条件执行器
|
|
813
759
|
*
|
|
814
|
-
*
|
|
815
|
-
*
|
|
816
|
-
* 执行流程:
|
|
817
|
-
* 1. 初始时只有根节点带有 ActiveNode
|
|
818
|
-
* 2. 父节点决定激活哪个子节点时,为子节点添加 ActiveNode
|
|
819
|
-
* 3. 节点执行完成后移除 ActiveNode
|
|
820
|
-
* 4. 通过这种方式实现按需执行,避免每帧遍历整棵树
|
|
760
|
+
* 检查黑板中是否存在指定的键
|
|
821
761
|
*/
|
|
822
|
-
declare class
|
|
762
|
+
declare class BlackboardExists implements INodeExecutor {
|
|
763
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
823
764
|
}
|
|
824
765
|
|
|
825
766
|
/**
|
|
826
|
-
*
|
|
827
|
-
*
|
|
767
|
+
* 随机概率条件执行器
|
|
768
|
+
*
|
|
769
|
+
* 根据概率返回成功或失败
|
|
828
770
|
*/
|
|
829
|
-
declare class
|
|
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;
|
|
771
|
+
declare class RandomProbability implements INodeExecutor {
|
|
772
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
852
773
|
}
|
|
853
774
|
|
|
854
775
|
/**
|
|
855
|
-
*
|
|
776
|
+
* 执行条件执行器
|
|
856
777
|
*
|
|
857
|
-
*
|
|
778
|
+
* 执行自定义条件逻辑
|
|
858
779
|
*/
|
|
859
|
-
declare class
|
|
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;
|
|
780
|
+
declare class ExecuteCondition implements INodeExecutor {
|
|
781
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
876
782
|
}
|
|
877
783
|
|
|
878
784
|
/**
|
|
879
|
-
*
|
|
880
|
-
*
|
|
881
|
-
* 附加到从资产实例化的行为树根节点上,
|
|
882
|
-
* 用于标记资产ID和版本信息,便于循环引用检测和调试。
|
|
883
|
-
*
|
|
884
|
-
* @example
|
|
885
|
-
* ```typescript
|
|
886
|
-
* const rootEntity = BehaviorTreeAssetLoader.instantiate(asset, scene);
|
|
785
|
+
* 行为树执行系统
|
|
887
786
|
*
|
|
888
|
-
*
|
|
889
|
-
* const metadata = rootEntity.addComponent(new BehaviorTreeAssetMetadata());
|
|
890
|
-
* metadata.assetId = 'patrol';
|
|
891
|
-
* metadata.assetVersion = '1.0.0';
|
|
892
|
-
* ```
|
|
787
|
+
* 统一处理所有行为树的执行
|
|
893
788
|
*/
|
|
894
|
-
declare class
|
|
789
|
+
declare class BehaviorTreeExecutionSystem extends EntitySystem {
|
|
790
|
+
private assetManager;
|
|
791
|
+
private executorRegistry;
|
|
792
|
+
constructor();
|
|
895
793
|
/**
|
|
896
|
-
*
|
|
794
|
+
* 注册所有执行器(包括内置和插件提供的)
|
|
897
795
|
*/
|
|
898
|
-
|
|
796
|
+
private registerBuiltInExecutors;
|
|
899
797
|
/**
|
|
900
|
-
*
|
|
798
|
+
* 获取执行器注册表
|
|
901
799
|
*/
|
|
902
|
-
|
|
800
|
+
getExecutorRegistry(): NodeExecutorRegistry;
|
|
801
|
+
protected process(entities: readonly Entity[]): void;
|
|
903
802
|
/**
|
|
904
|
-
*
|
|
803
|
+
* 执行整个行为树
|
|
905
804
|
*/
|
|
906
|
-
|
|
805
|
+
private executeTree;
|
|
907
806
|
/**
|
|
908
|
-
*
|
|
807
|
+
* 执行单个节点
|
|
909
808
|
*/
|
|
910
|
-
|
|
809
|
+
private executeNode;
|
|
911
810
|
/**
|
|
912
|
-
*
|
|
811
|
+
* 创建执行上下文
|
|
913
812
|
*/
|
|
914
|
-
|
|
813
|
+
private createContext;
|
|
915
814
|
/**
|
|
916
|
-
*
|
|
815
|
+
* 执行子节点列表
|
|
917
816
|
*/
|
|
918
|
-
|
|
817
|
+
executeChildren(context: NodeExecutionContext, childIndices?: number[]): TaskStatus[];
|
|
919
818
|
}
|
|
920
819
|
|
|
921
820
|
/**
|
|
922
|
-
*
|
|
923
|
-
*
|
|
924
|
-
* 行为树的根节点,简单地激活第一个子节点
|
|
821
|
+
* 配置参数定义
|
|
925
822
|
*/
|
|
926
|
-
|
|
927
|
-
|
|
823
|
+
interface ConfigFieldDefinition {
|
|
824
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
825
|
+
default?: any;
|
|
826
|
+
description?: string;
|
|
827
|
+
min?: number;
|
|
828
|
+
max?: number;
|
|
829
|
+
options?: string[];
|
|
830
|
+
supportBinding?: boolean;
|
|
831
|
+
allowMultipleConnections?: boolean;
|
|
928
832
|
}
|
|
929
|
-
|
|
930
833
|
/**
|
|
931
|
-
*
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
private
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
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;
|
|
834
|
+
* 节点元数据
|
|
835
|
+
*/
|
|
836
|
+
interface NodeMetadata {
|
|
837
|
+
implementationType: string;
|
|
838
|
+
nodeType: NodeType;
|
|
839
|
+
displayName: string;
|
|
840
|
+
description?: string;
|
|
841
|
+
category?: string;
|
|
842
|
+
configSchema?: Record<string, ConfigFieldDefinition>;
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* 节点元数据注册表
|
|
846
|
+
*/
|
|
847
|
+
declare class NodeMetadataRegistry {
|
|
848
|
+
private static metadataMap;
|
|
849
|
+
private static executorClassMap;
|
|
850
|
+
private static executorConstructors;
|
|
851
|
+
static register(target: Function, metadata: NodeMetadata): void;
|
|
852
|
+
static getMetadata(implementationType: string): NodeMetadata | undefined;
|
|
853
|
+
static getAllMetadata(): NodeMetadata[];
|
|
854
|
+
static getByCategory(category: string): NodeMetadata[];
|
|
855
|
+
static getByNodeType(nodeType: NodeType): NodeMetadata[];
|
|
856
|
+
static getImplementationType(executorClass: Function): string | undefined;
|
|
857
|
+
static getExecutorConstructor(implementationType: string): (new () => any) | undefined;
|
|
858
|
+
static getAllExecutorConstructors(): Map<string, new () => any>;
|
|
994
859
|
}
|
|
860
|
+
/**
|
|
861
|
+
* 节点执行器元数据装饰器
|
|
862
|
+
*/
|
|
863
|
+
declare function NodeExecutorMetadata(metadata: NodeMetadata): (target: Function) => void;
|
|
995
864
|
|
|
996
865
|
/**
|
|
997
|
-
*
|
|
866
|
+
* 行为树启动辅助类
|
|
998
867
|
*
|
|
999
|
-
*
|
|
1000
|
-
* 只处理带有 ActiveNode 标记的节点
|
|
1001
|
-
*
|
|
1002
|
-
* updateOrder: 100 (最先执行)
|
|
868
|
+
* 提供便捷方法来启动、停止行为树
|
|
1003
869
|
*/
|
|
1004
|
-
declare class
|
|
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;
|
|
870
|
+
declare class BehaviorTreeStarter {
|
|
1060
871
|
/**
|
|
1061
|
-
*
|
|
872
|
+
* 启动行为树
|
|
873
|
+
*
|
|
874
|
+
* @param entity 游戏实体
|
|
875
|
+
* @param treeData 行为树数据
|
|
876
|
+
* @param autoStart 是否自动开始执行
|
|
1062
877
|
*/
|
|
1063
|
-
|
|
878
|
+
static start(entity: Entity, treeData: BehaviorTreeData, autoStart?: boolean): void;
|
|
1064
879
|
/**
|
|
1065
|
-
*
|
|
880
|
+
* 停止行为树
|
|
881
|
+
*
|
|
882
|
+
* @param entity 游戏实体
|
|
1066
883
|
*/
|
|
1067
|
-
|
|
884
|
+
static stop(entity: Entity): void;
|
|
1068
885
|
/**
|
|
1069
|
-
*
|
|
886
|
+
* 暂停行为树
|
|
887
|
+
*
|
|
888
|
+
* @param entity 游戏实体
|
|
1070
889
|
*/
|
|
1071
|
-
|
|
890
|
+
static pause(entity: Entity): void;
|
|
1072
891
|
/**
|
|
1073
|
-
*
|
|
892
|
+
* 恢复行为树
|
|
893
|
+
*
|
|
894
|
+
* @param entity 游戏实体
|
|
1074
895
|
*/
|
|
1075
|
-
|
|
896
|
+
static resume(entity: Entity): void;
|
|
1076
897
|
/**
|
|
1077
|
-
*
|
|
1078
|
-
*
|
|
898
|
+
* 重启行为树
|
|
899
|
+
*
|
|
900
|
+
* @param entity 游戏实体
|
|
1079
901
|
*/
|
|
1080
|
-
|
|
1081
|
-
protected getLoggerName(): string;
|
|
902
|
+
static restart(entity: Entity): void;
|
|
1082
903
|
}
|
|
1083
904
|
|
|
1084
905
|
/**
|
|
1085
|
-
*
|
|
1086
|
-
*
|
|
1087
|
-
* 负责处理所有活跃的装饰器节点
|
|
1088
|
-
* 读取子节点状态,根据装饰器规则决定自己的状态
|
|
906
|
+
* 行为树构建器
|
|
1089
907
|
*
|
|
1090
|
-
*
|
|
908
|
+
* 提供流式API构建行为树数据结构
|
|
1091
909
|
*/
|
|
1092
|
-
declare class
|
|
1093
|
-
|
|
1094
|
-
|
|
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;
|
|
910
|
+
declare class BehaviorTreeBuilder {
|
|
911
|
+
private treeData;
|
|
912
|
+
private nodeStack;
|
|
913
|
+
private nodeIdCounter;
|
|
914
|
+
private constructor();
|
|
1119
915
|
/**
|
|
1120
|
-
*
|
|
916
|
+
* 创建构建器
|
|
1121
917
|
*/
|
|
1122
|
-
|
|
918
|
+
static create(treeName?: string): BehaviorTreeBuilder;
|
|
1123
919
|
/**
|
|
1124
|
-
*
|
|
920
|
+
* 定义黑板变量
|
|
1125
921
|
*/
|
|
1126
|
-
|
|
922
|
+
defineBlackboardVariable(key: string, initialValue: any): BehaviorTreeBuilder;
|
|
1127
923
|
/**
|
|
1128
|
-
*
|
|
924
|
+
* 添加序列节点
|
|
1129
925
|
*/
|
|
1130
|
-
|
|
926
|
+
sequence(name?: string): BehaviorTreeBuilder;
|
|
1131
927
|
/**
|
|
1132
|
-
*
|
|
928
|
+
* 添加选择器节点
|
|
1133
929
|
*/
|
|
1134
|
-
|
|
930
|
+
selector(name?: string): BehaviorTreeBuilder;
|
|
1135
931
|
/**
|
|
1136
|
-
*
|
|
932
|
+
* 添加并行节点
|
|
1137
933
|
*/
|
|
1138
|
-
|
|
934
|
+
parallel(name?: string, config?: {
|
|
935
|
+
successPolicy?: string;
|
|
936
|
+
failurePolicy?: string;
|
|
937
|
+
}): BehaviorTreeBuilder;
|
|
1139
938
|
/**
|
|
1140
|
-
*
|
|
939
|
+
* 添加并行选择器节点
|
|
1141
940
|
*/
|
|
1142
|
-
|
|
941
|
+
parallelSelector(name?: string, config?: {
|
|
942
|
+
failurePolicy?: string;
|
|
943
|
+
}): BehaviorTreeBuilder;
|
|
1143
944
|
/**
|
|
1144
|
-
*
|
|
1145
|
-
* 如果属性绑定到黑板变量,从黑板读取最新值
|
|
945
|
+
* 添加随机序列节点
|
|
1146
946
|
*/
|
|
1147
|
-
|
|
947
|
+
randomSequence(name?: string): BehaviorTreeBuilder;
|
|
1148
948
|
/**
|
|
1149
|
-
*
|
|
949
|
+
* 添加随机选择器节点
|
|
1150
950
|
*/
|
|
1151
|
-
|
|
951
|
+
randomSelector(name?: string): BehaviorTreeBuilder;
|
|
1152
952
|
/**
|
|
1153
|
-
*
|
|
1154
|
-
* 同时输出到控制台和LogOutput组件,确保用户在UI中能看到
|
|
953
|
+
* 添加反转装饰器
|
|
1155
954
|
*/
|
|
1156
|
-
|
|
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;
|
|
955
|
+
inverter(name?: string): BehaviorTreeBuilder;
|
|
1171
956
|
/**
|
|
1172
|
-
*
|
|
957
|
+
* 添加重复装饰器
|
|
1173
958
|
*/
|
|
1174
|
-
|
|
959
|
+
repeater(repeatCount: number, name?: string): BehaviorTreeBuilder;
|
|
1175
960
|
/**
|
|
1176
|
-
*
|
|
961
|
+
* 添加总是成功装饰器
|
|
1177
962
|
*/
|
|
1178
|
-
|
|
963
|
+
alwaysSucceed(name?: string): BehaviorTreeBuilder;
|
|
1179
964
|
/**
|
|
1180
|
-
*
|
|
965
|
+
* 添加总是失败装饰器
|
|
1181
966
|
*/
|
|
1182
|
-
|
|
967
|
+
alwaysFail(name?: string): BehaviorTreeBuilder;
|
|
1183
968
|
/**
|
|
1184
|
-
*
|
|
969
|
+
* 添加直到成功装饰器
|
|
1185
970
|
*/
|
|
1186
|
-
|
|
971
|
+
untilSuccess(name?: string): BehaviorTreeBuilder;
|
|
1187
972
|
/**
|
|
1188
|
-
*
|
|
973
|
+
* 添加直到失败装饰器
|
|
1189
974
|
*/
|
|
1190
|
-
|
|
975
|
+
untilFail(name?: string): BehaviorTreeBuilder;
|
|
1191
976
|
/**
|
|
1192
|
-
*
|
|
977
|
+
* 添加条件装饰器
|
|
1193
978
|
*/
|
|
1194
|
-
|
|
979
|
+
conditional(blackboardKey: string, expectedValue: any, operator?: string, name?: string): BehaviorTreeBuilder;
|
|
1195
980
|
/**
|
|
1196
|
-
*
|
|
981
|
+
* 添加冷却装饰器
|
|
1197
982
|
*/
|
|
1198
|
-
|
|
983
|
+
cooldown(cooldownTime: number, name?: string): BehaviorTreeBuilder;
|
|
1199
984
|
/**
|
|
1200
|
-
*
|
|
985
|
+
* 添加超时装饰器
|
|
1201
986
|
*/
|
|
1202
|
-
|
|
987
|
+
timeout(timeout: number, name?: string): BehaviorTreeBuilder;
|
|
1203
988
|
/**
|
|
1204
|
-
*
|
|
989
|
+
* 添加等待动作
|
|
1205
990
|
*/
|
|
1206
|
-
|
|
991
|
+
wait(duration: number, name?: string): BehaviorTreeBuilder;
|
|
1207
992
|
/**
|
|
1208
|
-
*
|
|
993
|
+
* 添加日志动作
|
|
1209
994
|
*/
|
|
1210
|
-
|
|
995
|
+
log(message: string, name?: string): BehaviorTreeBuilder;
|
|
1211
996
|
/**
|
|
1212
|
-
*
|
|
997
|
+
* 添加设置黑板值动作
|
|
1213
998
|
*/
|
|
1214
|
-
|
|
999
|
+
setBlackboardValue(key: string, value: any, name?: string): BehaviorTreeBuilder;
|
|
1215
1000
|
/**
|
|
1216
|
-
*
|
|
1001
|
+
* 添加修改黑板值动作
|
|
1217
1002
|
*/
|
|
1218
|
-
|
|
1003
|
+
modifyBlackboardValue(key: string, operation: string, value: number, name?: string): BehaviorTreeBuilder;
|
|
1219
1004
|
/**
|
|
1220
|
-
*
|
|
1005
|
+
* 添加执行动作
|
|
1221
1006
|
*/
|
|
1222
|
-
|
|
1007
|
+
executeAction(actionName: string, name?: string): BehaviorTreeBuilder;
|
|
1223
1008
|
/**
|
|
1224
|
-
*
|
|
1009
|
+
* 添加黑板比较条件
|
|
1225
1010
|
*/
|
|
1226
|
-
|
|
1011
|
+
blackboardCompare(key: string, compareValue: any, operator?: string, name?: string): BehaviorTreeBuilder;
|
|
1227
1012
|
/**
|
|
1228
|
-
*
|
|
1013
|
+
* 添加黑板存在检查条件
|
|
1229
1014
|
*/
|
|
1230
|
-
|
|
1015
|
+
blackboardExists(key: string, name?: string): BehaviorTreeBuilder;
|
|
1231
1016
|
/**
|
|
1232
|
-
*
|
|
1017
|
+
* 添加随机概率条件
|
|
1233
1018
|
*/
|
|
1234
|
-
|
|
1019
|
+
randomProbability(probability: number, name?: string): BehaviorTreeBuilder;
|
|
1235
1020
|
/**
|
|
1236
|
-
*
|
|
1021
|
+
* 添加执行条件
|
|
1237
1022
|
*/
|
|
1238
|
-
|
|
1023
|
+
executeCondition(conditionName: string, name?: string): BehaviorTreeBuilder;
|
|
1239
1024
|
/**
|
|
1240
|
-
*
|
|
1025
|
+
* 结束当前节点,返回父节点
|
|
1241
1026
|
*/
|
|
1242
|
-
|
|
1027
|
+
end(): BehaviorTreeBuilder;
|
|
1243
1028
|
/**
|
|
1244
|
-
*
|
|
1029
|
+
* 构建行为树数据
|
|
1245
1030
|
*/
|
|
1246
|
-
|
|
1247
|
-
|
|
1031
|
+
build(): BehaviorTreeData;
|
|
1032
|
+
private addCompositeNode;
|
|
1033
|
+
private addDecoratorNode;
|
|
1034
|
+
private addActionNode;
|
|
1035
|
+
private addConditionNode;
|
|
1036
|
+
private generateNodeId;
|
|
1248
1037
|
}
|
|
1249
1038
|
|
|
1250
1039
|
/**
|
|
1251
|
-
*
|
|
1252
|
-
*/
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
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);
|
|
1040
|
+
* 节点数据JSON格式
|
|
1041
|
+
*/
|
|
1042
|
+
interface NodeDataJSON {
|
|
1043
|
+
nodeType: string;
|
|
1044
|
+
compositeType?: string;
|
|
1045
|
+
decoratorType?: string;
|
|
1046
|
+
actionType?: string;
|
|
1047
|
+
conditionType?: string;
|
|
1048
|
+
[key: string]: any;
|
|
1364
1049
|
}
|
|
1365
|
-
|
|
1366
1050
|
/**
|
|
1367
|
-
*
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1051
|
+
* 内置属性类型常量
|
|
1052
|
+
*/
|
|
1053
|
+
declare const PropertyType: {
|
|
1054
|
+
/** 字符串 */
|
|
1055
|
+
readonly String: "string";
|
|
1056
|
+
/** 数值 */
|
|
1057
|
+
readonly Number: "number";
|
|
1058
|
+
/** 布尔值 */
|
|
1059
|
+
readonly Boolean: "boolean";
|
|
1060
|
+
/** 选择框 */
|
|
1061
|
+
readonly Select: "select";
|
|
1062
|
+
/** 黑板变量引用 */
|
|
1063
|
+
readonly Blackboard: "blackboard";
|
|
1064
|
+
/** 代码编辑器 */
|
|
1065
|
+
readonly Code: "code";
|
|
1066
|
+
/** 变量引用 */
|
|
1067
|
+
readonly Variable: "variable";
|
|
1068
|
+
/** 资产引用 */
|
|
1069
|
+
readonly Asset: "asset";
|
|
1070
|
+
};
|
|
1071
|
+
/**
|
|
1072
|
+
* 属性类型(支持自定义扩展)
|
|
1374
1073
|
*
|
|
1375
1074
|
* @example
|
|
1376
1075
|
* ```typescript
|
|
1377
|
-
*
|
|
1378
|
-
*
|
|
1379
|
-
* const handle = manager.startLoading(
|
|
1380
|
-
* 'patrol',
|
|
1381
|
-
* parentEntity,
|
|
1382
|
-
* () => assetLoader.loadBehaviorTree('patrol'),
|
|
1383
|
-
* { timeoutMs: 5000, maxRetries: 3 }
|
|
1384
|
-
* );
|
|
1076
|
+
* // 使用内置类型
|
|
1077
|
+
* type: PropertyType.String
|
|
1385
1078
|
*
|
|
1386
|
-
* //
|
|
1387
|
-
*
|
|
1388
|
-
*
|
|
1389
|
-
* const entity = await handle.promise;
|
|
1390
|
-
* // 使用加载的实体
|
|
1391
|
-
* }
|
|
1079
|
+
* // 使用自定义类型
|
|
1080
|
+
* type: 'color-picker'
|
|
1081
|
+
* type: 'curve-editor'
|
|
1392
1082
|
* ```
|
|
1393
1083
|
*/
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1084
|
+
type PropertyType = typeof PropertyType[keyof typeof PropertyType] | string;
|
|
1085
|
+
/**
|
|
1086
|
+
* 属性定义(用于编辑器)
|
|
1087
|
+
*/
|
|
1088
|
+
interface PropertyDefinition {
|
|
1089
|
+
name: string;
|
|
1090
|
+
type: PropertyType;
|
|
1091
|
+
label: string;
|
|
1092
|
+
description?: string;
|
|
1093
|
+
defaultValue?: any;
|
|
1094
|
+
options?: Array<{
|
|
1095
|
+
label: string;
|
|
1096
|
+
value: any;
|
|
1097
|
+
}>;
|
|
1098
|
+
min?: number;
|
|
1099
|
+
max?: number;
|
|
1100
|
+
step?: number;
|
|
1101
|
+
required?: boolean;
|
|
1401
1102
|
/**
|
|
1402
|
-
*
|
|
1103
|
+
* 自定义渲染配置
|
|
1403
1104
|
*
|
|
1404
|
-
*
|
|
1405
|
-
*
|
|
1406
|
-
* @
|
|
1407
|
-
*
|
|
1408
|
-
*
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
*
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
* Promise 超时包装
|
|
1417
|
-
*/
|
|
1418
|
-
private withTimeout;
|
|
1419
|
-
/**
|
|
1420
|
-
* 循环依赖检测
|
|
1105
|
+
* 用于指定编辑器如何渲染此属性
|
|
1106
|
+
*
|
|
1107
|
+
* @example
|
|
1108
|
+
* ```typescript
|
|
1109
|
+
* renderConfig: {
|
|
1110
|
+
* component: 'ColorPicker', // 渲染器组件名称
|
|
1111
|
+
* props: { // 传递给组件的属性
|
|
1112
|
+
* showAlpha: true,
|
|
1113
|
+
* presets: ['#FF0000', '#00FF00']
|
|
1114
|
+
* }
|
|
1115
|
+
* }
|
|
1116
|
+
* ```
|
|
1421
1117
|
*/
|
|
1422
|
-
|
|
1118
|
+
renderConfig?: {
|
|
1119
|
+
/** 渲染器组件名称或路径 */
|
|
1120
|
+
component?: string;
|
|
1121
|
+
/** 传递给渲染器的属性配置 */
|
|
1122
|
+
props?: Record<string, any>;
|
|
1123
|
+
/** 渲染器的样式类名 */
|
|
1124
|
+
className?: string;
|
|
1125
|
+
/** 渲染器的内联样式 */
|
|
1126
|
+
style?: Record<string, any>;
|
|
1127
|
+
/** 其他自定义配置 */
|
|
1128
|
+
[key: string]: any;
|
|
1129
|
+
};
|
|
1423
1130
|
/**
|
|
1424
|
-
*
|
|
1131
|
+
* 验证规则
|
|
1132
|
+
*
|
|
1133
|
+
* 用于在编辑器中验证输入
|
|
1134
|
+
*
|
|
1135
|
+
* @example
|
|
1136
|
+
* ```typescript
|
|
1137
|
+
* validation: {
|
|
1138
|
+
* pattern: /^\d+$/,
|
|
1139
|
+
* message: '只能输入数字',
|
|
1140
|
+
* validator: (value) => value > 0
|
|
1141
|
+
* }
|
|
1142
|
+
* ```
|
|
1425
1143
|
*/
|
|
1426
|
-
|
|
1144
|
+
validation?: {
|
|
1145
|
+
/** 正则表达式验证 */
|
|
1146
|
+
pattern?: RegExp | string;
|
|
1147
|
+
/** 验证失败的提示信息 */
|
|
1148
|
+
message?: string;
|
|
1149
|
+
/** 自定义验证函数 */
|
|
1150
|
+
validator?: string;
|
|
1151
|
+
/** 最小长度(字符串) */
|
|
1152
|
+
minLength?: number;
|
|
1153
|
+
/** 最大长度(字符串) */
|
|
1154
|
+
maxLength?: number;
|
|
1155
|
+
};
|
|
1427
1156
|
/**
|
|
1428
|
-
*
|
|
1157
|
+
* 是否允许多个连接
|
|
1158
|
+
* 默认 false,只允许一个黑板变量连接
|
|
1429
1159
|
*/
|
|
1430
|
-
|
|
1160
|
+
allowMultipleConnections?: boolean;
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* 节点模板(用于编辑器)
|
|
1164
|
+
*/
|
|
1165
|
+
interface NodeTemplate {
|
|
1166
|
+
type: NodeType;
|
|
1167
|
+
displayName: string;
|
|
1168
|
+
category: string;
|
|
1169
|
+
icon?: string;
|
|
1170
|
+
description: string;
|
|
1171
|
+
color?: string;
|
|
1172
|
+
className?: string;
|
|
1173
|
+
componentClass?: Function;
|
|
1174
|
+
requiresChildren?: boolean;
|
|
1175
|
+
defaultConfig: Partial<NodeDataJSON>;
|
|
1176
|
+
properties: PropertyDefinition[];
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* 节点模板库
|
|
1180
|
+
*/
|
|
1181
|
+
declare class NodeTemplates {
|
|
1431
1182
|
/**
|
|
1432
|
-
*
|
|
1183
|
+
* 获取所有节点模板
|
|
1433
1184
|
*/
|
|
1434
|
-
|
|
1185
|
+
static getAllTemplates(): NodeTemplate[];
|
|
1435
1186
|
/**
|
|
1436
|
-
*
|
|
1187
|
+
* 根据类型和子类型获取模板
|
|
1437
1188
|
*/
|
|
1438
|
-
|
|
1189
|
+
static getTemplate(type: NodeType, subType: string): NodeTemplate | undefined;
|
|
1439
1190
|
/**
|
|
1440
|
-
*
|
|
1191
|
+
* 将NodeMetadata转换为NodeTemplate
|
|
1441
1192
|
*/
|
|
1442
|
-
private
|
|
1193
|
+
private static convertMetadataToTemplate;
|
|
1443
1194
|
/**
|
|
1444
|
-
*
|
|
1195
|
+
* 将ConfigSchema转换为PropertyDefinition数组
|
|
1445
1196
|
*/
|
|
1446
|
-
private
|
|
1197
|
+
private static convertConfigSchemaToProperties;
|
|
1447
1198
|
/**
|
|
1448
|
-
*
|
|
1199
|
+
* 映射字段类型到属性类型
|
|
1449
1200
|
*/
|
|
1450
|
-
|
|
1201
|
+
private static mapFieldTypeToPropertyType;
|
|
1451
1202
|
/**
|
|
1452
|
-
*
|
|
1203
|
+
* NodeType转字符串
|
|
1453
1204
|
*/
|
|
1454
|
-
|
|
1455
|
-
totalTasks: number;
|
|
1456
|
-
loadingTasks: number;
|
|
1457
|
-
failedTasks: number;
|
|
1458
|
-
timeoutTasks: number;
|
|
1459
|
-
};
|
|
1205
|
+
private static nodeTypeToString;
|
|
1460
1206
|
/**
|
|
1461
|
-
*
|
|
1207
|
+
* 根据NodeType获取默认分类
|
|
1462
1208
|
*/
|
|
1463
|
-
|
|
1209
|
+
private static getCategoryByNodeType;
|
|
1464
1210
|
/**
|
|
1465
|
-
*
|
|
1211
|
+
* 根据节点类型获取默认图标和颜色
|
|
1466
1212
|
*/
|
|
1467
|
-
|
|
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;
|
|
1213
|
+
private static getIconAndColorByType;
|
|
1717
1214
|
}
|
|
1718
1215
|
|
|
1719
1216
|
/**
|
|
@@ -1736,6 +1233,13 @@ interface BlackboardVariableDefinition {
|
|
|
1736
1233
|
readonly?: boolean;
|
|
1737
1234
|
description?: string;
|
|
1738
1235
|
}
|
|
1236
|
+
/**
|
|
1237
|
+
* 行为树节点配置数据
|
|
1238
|
+
*/
|
|
1239
|
+
interface BehaviorNodeConfigData {
|
|
1240
|
+
className?: string;
|
|
1241
|
+
[key: string]: any;
|
|
1242
|
+
}
|
|
1739
1243
|
/**
|
|
1740
1244
|
* 行为树节点数据(运行时格式)
|
|
1741
1245
|
*/
|
|
@@ -1743,7 +1247,7 @@ interface BehaviorTreeNodeData {
|
|
|
1743
1247
|
id: string;
|
|
1744
1248
|
name: string;
|
|
1745
1249
|
nodeType: NodeType;
|
|
1746
|
-
data:
|
|
1250
|
+
data: BehaviorNodeConfigData;
|
|
1747
1251
|
children: string[];
|
|
1748
1252
|
}
|
|
1749
1253
|
/**
|
|
@@ -1817,626 +1321,125 @@ declare class BehaviorTreeAssetValidator {
|
|
|
1817
1321
|
}
|
|
1818
1322
|
|
|
1819
1323
|
/**
|
|
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
|
-
* 文件系统资产加载器配置
|
|
1324
|
+
* 编辑器节点格式
|
|
1885
1325
|
*/
|
|
1886
|
-
interface
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
extension?: string;
|
|
1893
|
-
/** 是否启用缓存 */
|
|
1894
|
-
enableCache?: boolean;
|
|
1895
|
-
/** 自定义文件读取函数(可选) */
|
|
1896
|
-
readFile?: (path: string) => Promise<string | Uint8Array>;
|
|
1326
|
+
interface EditorNodeTemplate {
|
|
1327
|
+
displayName: string;
|
|
1328
|
+
category: string;
|
|
1329
|
+
type: NodeType;
|
|
1330
|
+
className?: string;
|
|
1331
|
+
[key: string]: any;
|
|
1897
1332
|
}
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
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;
|
|
1333
|
+
interface EditorNodeData {
|
|
1334
|
+
nodeType?: string;
|
|
1335
|
+
className?: string;
|
|
1336
|
+
variableName?: string;
|
|
1337
|
+
name?: string;
|
|
1338
|
+
[key: string]: any;
|
|
1964
1339
|
}
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
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;
|
|
1340
|
+
interface EditorNode {
|
|
1341
|
+
id: string;
|
|
1342
|
+
template: EditorNodeTemplate;
|
|
1343
|
+
data: EditorNodeData;
|
|
1344
|
+
position: {
|
|
1345
|
+
x: number;
|
|
1346
|
+
y: number;
|
|
1347
|
+
};
|
|
1348
|
+
children: string[];
|
|
2017
1349
|
}
|
|
2018
|
-
|
|
2019
1350
|
/**
|
|
2020
|
-
*
|
|
2021
|
-
*
|
|
2022
|
-
* 提供便捷方法来启动、停止和暂停行为树
|
|
1351
|
+
* 编辑器连接格式
|
|
2023
1352
|
*/
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
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;
|
|
1353
|
+
interface EditorConnection {
|
|
1354
|
+
from: string;
|
|
1355
|
+
to: string;
|
|
1356
|
+
fromProperty?: string;
|
|
1357
|
+
toProperty?: string;
|
|
1358
|
+
connectionType: 'node' | 'property';
|
|
2122
1359
|
}
|
|
2123
|
-
|
|
2124
1360
|
/**
|
|
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
|
-
* ```
|
|
1361
|
+
* 编辑器格式
|
|
2147
1362
|
*/
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
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;
|
|
1363
|
+
interface EditorFormat {
|
|
1364
|
+
version?: string;
|
|
1365
|
+
metadata?: {
|
|
1366
|
+
name: string;
|
|
2171
1367
|
description?: string;
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
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;
|
|
1368
|
+
createdAt?: string;
|
|
1369
|
+
modifiedAt?: string;
|
|
1370
|
+
};
|
|
1371
|
+
nodes: EditorNode[];
|
|
1372
|
+
connections: EditorConnection[];
|
|
1373
|
+
blackboard: Record<string, any>;
|
|
1374
|
+
canvasState?: {
|
|
1375
|
+
offset: {
|
|
1376
|
+
x: number;
|
|
1377
|
+
y: number;
|
|
1378
|
+
};
|
|
1379
|
+
scale: number;
|
|
1380
|
+
};
|
|
2285
1381
|
}
|
|
2286
|
-
|
|
2287
1382
|
/**
|
|
2288
|
-
*
|
|
1383
|
+
* 编辑器格式转换器
|
|
2289
1384
|
*
|
|
2290
|
-
*
|
|
1385
|
+
* 将编辑器格式转换为运行时资产格式
|
|
2291
1386
|
*/
|
|
2292
|
-
declare class
|
|
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;
|
|
1387
|
+
declare class EditorFormatConverter {
|
|
2322
1388
|
/**
|
|
2323
|
-
*
|
|
1389
|
+
* 转换编辑器格式为资产格式
|
|
2324
1390
|
*
|
|
2325
|
-
* @param
|
|
2326
|
-
* @param
|
|
2327
|
-
* @returns
|
|
1391
|
+
* @param editorData 编辑器数据
|
|
1392
|
+
* @param metadata 可选的元数据覆盖
|
|
1393
|
+
* @returns 行为树资产
|
|
2328
1394
|
*/
|
|
2329
|
-
static
|
|
1395
|
+
static toAsset(editorData: EditorFormat, metadata?: Partial<AssetMetadata>): BehaviorTreeAsset;
|
|
2330
1396
|
/**
|
|
2331
|
-
*
|
|
2332
|
-
*
|
|
2333
|
-
* @param scene 场景实例
|
|
2334
|
-
* @param json JSON 字符串
|
|
1397
|
+
* 查找根节点
|
|
2335
1398
|
*/
|
|
2336
|
-
static
|
|
1399
|
+
private static findRootNode;
|
|
2337
1400
|
/**
|
|
2338
|
-
*
|
|
2339
|
-
*
|
|
2340
|
-
* @param rootEntity 行为树根实体
|
|
2341
|
-
* @param filePath 文件路径
|
|
2342
|
-
*
|
|
2343
|
-
* @example
|
|
2344
|
-
* ```typescript
|
|
2345
|
-
* await BehaviorTreePersistence.saveToFile(aiRoot, 'ai-behavior.json');
|
|
2346
|
-
* ```
|
|
1401
|
+
* 转换节点列表
|
|
2347
1402
|
*/
|
|
2348
|
-
static
|
|
1403
|
+
private static convertNodes;
|
|
2349
1404
|
/**
|
|
2350
|
-
*
|
|
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
|
-
* ```
|
|
1405
|
+
* 转换单个节点
|
|
2360
1406
|
*/
|
|
2361
|
-
static
|
|
1407
|
+
private static convertNode;
|
|
2362
1408
|
/**
|
|
2363
|
-
*
|
|
2364
|
-
*
|
|
2365
|
-
* @param data 序列化数据(字符串格式)
|
|
2366
|
-
* @returns 是否有效
|
|
1409
|
+
* 转换黑板变量
|
|
2367
1410
|
*/
|
|
2368
|
-
static
|
|
1411
|
+
private static convertBlackboard;
|
|
2369
1412
|
/**
|
|
2370
|
-
*
|
|
2371
|
-
*
|
|
2372
|
-
* @param scene 场景实例
|
|
2373
|
-
* @param rootEntity 要克隆的行为树根实体
|
|
2374
|
-
* @returns 克隆的新实体
|
|
2375
|
-
*
|
|
2376
|
-
* @example
|
|
2377
|
-
* ```typescript
|
|
2378
|
-
* const clonedAI = BehaviorTreePersistence.clone(scene, originalAI);
|
|
2379
|
-
* ```
|
|
1413
|
+
* 推断黑板变量类型
|
|
2380
1414
|
*/
|
|
2381
|
-
static
|
|
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 {
|
|
1415
|
+
private static inferBlackboardType;
|
|
2432
1416
|
/**
|
|
2433
|
-
*
|
|
1417
|
+
* 转换属性绑定
|
|
2434
1418
|
*/
|
|
2435
|
-
static
|
|
1419
|
+
private static convertPropertyBindings;
|
|
2436
1420
|
/**
|
|
2437
|
-
*
|
|
1421
|
+
* 从资产格式转换回编辑器格式(用于加载)
|
|
1422
|
+
*
|
|
1423
|
+
* @param asset 行为树资产
|
|
1424
|
+
* @returns 编辑器格式数据
|
|
2438
1425
|
*/
|
|
2439
|
-
static
|
|
1426
|
+
static fromAsset(asset: BehaviorTreeAsset): EditorFormat;
|
|
1427
|
+
/**
|
|
1428
|
+
* 从资产格式转换节点
|
|
1429
|
+
*/
|
|
1430
|
+
private static convertNodesFromAsset;
|
|
1431
|
+
/**
|
|
1432
|
+
* 推断节点分类
|
|
1433
|
+
*/
|
|
1434
|
+
private static inferCategory;
|
|
1435
|
+
/**
|
|
1436
|
+
* 将属性绑定转换为连接
|
|
1437
|
+
*/
|
|
1438
|
+
private static convertPropertyBindingsToConnections;
|
|
1439
|
+
/**
|
|
1440
|
+
* 根据children关系构建节点连接
|
|
1441
|
+
*/
|
|
1442
|
+
private static buildNodeConnections;
|
|
2440
1443
|
}
|
|
2441
1444
|
|
|
2442
1445
|
/**
|
|
@@ -2476,7 +1479,7 @@ interface DeserializationOptions {
|
|
|
2476
1479
|
/**
|
|
2477
1480
|
* 行为树资产序列化器
|
|
2478
1481
|
*
|
|
2479
|
-
* 支持JSON
|
|
1482
|
+
* 支持JSON和二进制两种格式
|
|
2480
1483
|
*/
|
|
2481
1484
|
declare class BehaviorTreeAssetSerializer {
|
|
2482
1485
|
/**
|
|
@@ -2501,7 +1504,7 @@ declare class BehaviorTreeAssetSerializer {
|
|
|
2501
1504
|
*/
|
|
2502
1505
|
private static serializeToJSON;
|
|
2503
1506
|
/**
|
|
2504
|
-
*
|
|
1507
|
+
* 序列化为二进制格式
|
|
2505
1508
|
*/
|
|
2506
1509
|
private static serializeToBinary;
|
|
2507
1510
|
/**
|
|
@@ -2584,292 +1587,138 @@ declare class BehaviorTreeAssetSerializer {
|
|
|
2584
1587
|
}
|
|
2585
1588
|
|
|
2586
1589
|
/**
|
|
2587
|
-
*
|
|
1590
|
+
* 全局黑板配置
|
|
2588
1591
|
*/
|
|
2589
|
-
interface
|
|
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;
|
|
1592
|
+
interface GlobalBlackboardConfig {
|
|
1593
|
+
version: string;
|
|
1594
|
+
variables: BlackboardVariable[];
|
|
2607
1595
|
}
|
|
2608
1596
|
/**
|
|
2609
|
-
*
|
|
1597
|
+
* 全局黑板服务
|
|
2610
1598
|
*
|
|
2611
|
-
*
|
|
1599
|
+
* 提供所有行为树共享的全局变量存储
|
|
1600
|
+
*
|
|
1601
|
+
* 使用方式:
|
|
1602
|
+
* ```typescript
|
|
1603
|
+
* // 注册服务(在 BehaviorTreePlugin.install 中自动完成)
|
|
1604
|
+
* core.services.registerSingleton(GlobalBlackboardService);
|
|
1605
|
+
*
|
|
1606
|
+
* // 获取服务
|
|
1607
|
+
* const blackboard = core.services.resolve(GlobalBlackboardService);
|
|
1608
|
+
* ```
|
|
2612
1609
|
*/
|
|
2613
|
-
declare class
|
|
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;
|
|
1610
|
+
declare class GlobalBlackboardService implements IService {
|
|
1611
|
+
private variables;
|
|
1612
|
+
dispose(): void;
|
|
2659
1613
|
/**
|
|
2660
|
-
*
|
|
1614
|
+
* 定义全局变量
|
|
2661
1615
|
*/
|
|
2662
|
-
|
|
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;
|
|
1616
|
+
defineVariable(name: string, type: BlackboardValueType, initialValue: any, options?: {
|
|
1617
|
+
readonly?: boolean;
|
|
2700
1618
|
description?: string;
|
|
2701
|
-
|
|
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 {
|
|
1619
|
+
}): void;
|
|
2721
1620
|
/**
|
|
2722
|
-
*
|
|
2723
|
-
*
|
|
2724
|
-
* @param editorData 编辑器数据
|
|
2725
|
-
* @param metadata 可选的元数据覆盖
|
|
2726
|
-
* @returns 行为树资产
|
|
1621
|
+
* 获取全局变量值
|
|
2727
1622
|
*/
|
|
2728
|
-
|
|
1623
|
+
getValue<T = any>(name: string): T | undefined;
|
|
2729
1624
|
/**
|
|
2730
|
-
*
|
|
1625
|
+
* 设置全局变量值
|
|
2731
1626
|
*/
|
|
2732
|
-
|
|
1627
|
+
setValue(name: string, value: any, force?: boolean): boolean;
|
|
2733
1628
|
/**
|
|
2734
|
-
*
|
|
1629
|
+
* 检查全局变量是否存在
|
|
2735
1630
|
*/
|
|
2736
|
-
|
|
1631
|
+
hasVariable(name: string): boolean;
|
|
2737
1632
|
/**
|
|
2738
|
-
*
|
|
1633
|
+
* 删除全局变量
|
|
2739
1634
|
*/
|
|
2740
|
-
|
|
1635
|
+
removeVariable(name: string): boolean;
|
|
2741
1636
|
/**
|
|
2742
|
-
*
|
|
1637
|
+
* 获取所有变量名
|
|
2743
1638
|
*/
|
|
2744
|
-
|
|
1639
|
+
getVariableNames(): string[];
|
|
2745
1640
|
/**
|
|
2746
|
-
*
|
|
1641
|
+
* 获取所有变量
|
|
2747
1642
|
*/
|
|
2748
|
-
|
|
1643
|
+
getAllVariables(): BlackboardVariable[];
|
|
2749
1644
|
/**
|
|
2750
|
-
*
|
|
1645
|
+
* 清空所有全局变量
|
|
2751
1646
|
*/
|
|
2752
|
-
|
|
1647
|
+
clear(): void;
|
|
2753
1648
|
/**
|
|
2754
|
-
*
|
|
2755
|
-
*
|
|
2756
|
-
* @param asset 行为树资产
|
|
2757
|
-
* @returns 编辑器格式数据
|
|
1649
|
+
* 批量设置变量
|
|
2758
1650
|
*/
|
|
2759
|
-
|
|
1651
|
+
setVariables(values: Record<string, any>): void;
|
|
2760
1652
|
/**
|
|
2761
|
-
*
|
|
1653
|
+
* 批量获取变量
|
|
2762
1654
|
*/
|
|
2763
|
-
|
|
1655
|
+
getVariables(names: string[]): Record<string, any>;
|
|
2764
1656
|
/**
|
|
2765
|
-
*
|
|
1657
|
+
* 导出配置
|
|
2766
1658
|
*/
|
|
2767
|
-
|
|
1659
|
+
exportConfig(): GlobalBlackboardConfig;
|
|
2768
1660
|
/**
|
|
2769
|
-
*
|
|
1661
|
+
* 导入配置
|
|
2770
1662
|
*/
|
|
2771
|
-
|
|
1663
|
+
importConfig(config: GlobalBlackboardConfig): void;
|
|
2772
1664
|
/**
|
|
2773
|
-
*
|
|
1665
|
+
* 序列化为 JSON
|
|
2774
1666
|
*/
|
|
2775
|
-
|
|
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;
|
|
1667
|
+
toJSON(): string;
|
|
2789
1668
|
/**
|
|
2790
|
-
*
|
|
2791
|
-
* - true: 节点需要子节点(如 SequenceNode、DecoratorNode)
|
|
2792
|
-
* - false: 节点不需要子节点(如 ActionNode、SubTreeNode)
|
|
2793
|
-
* - undefined: 根据节点类型自动判断
|
|
1669
|
+
* 从 JSON 反序列化
|
|
2794
1670
|
*/
|
|
2795
|
-
|
|
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;
|
|
1671
|
+
static fromJSON(json: string): GlobalBlackboardConfig;
|
|
2809
1672
|
}
|
|
1673
|
+
|
|
2810
1674
|
/**
|
|
2811
|
-
*
|
|
1675
|
+
* 行为树插件
|
|
2812
1676
|
*
|
|
2813
|
-
*
|
|
1677
|
+
* 提供便捷方法向场景添加行为树系统
|
|
2814
1678
|
*
|
|
2815
1679
|
* @example
|
|
2816
1680
|
* ```typescript
|
|
2817
|
-
*
|
|
2818
|
-
*
|
|
2819
|
-
*
|
|
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
|
-
* 用于标注节点的可配置属性,这些属性会在编辑器中显示
|
|
1681
|
+
* const core = Core.create();
|
|
1682
|
+
* const plugin = new BehaviorTreePlugin();
|
|
1683
|
+
* await core.pluginManager.install(plugin);
|
|
2844
1684
|
*
|
|
2845
|
-
*
|
|
2846
|
-
*
|
|
2847
|
-
*
|
|
2848
|
-
* class MyNode {
|
|
2849
|
-
* @BehaviorProperty({
|
|
2850
|
-
* label: '速度',
|
|
2851
|
-
* type: 'number',
|
|
2852
|
-
* min: 0,
|
|
2853
|
-
* max: 100,
|
|
2854
|
-
* description: '移动速度'
|
|
2855
|
-
* })
|
|
2856
|
-
* speed: number = 10;
|
|
2857
|
-
* }
|
|
1685
|
+
* // 为场景添加行为树系统
|
|
1686
|
+
* const scene = new Scene();
|
|
1687
|
+
* plugin.setupScene(scene);
|
|
2858
1688
|
* ```
|
|
2859
1689
|
*/
|
|
2860
|
-
declare
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
/**
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
/**
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
1690
|
+
declare class BehaviorTreePlugin implements IPlugin {
|
|
1691
|
+
readonly name = "@esengine/behavior-tree";
|
|
1692
|
+
readonly version = "1.0.0";
|
|
1693
|
+
private worldManager;
|
|
1694
|
+
private services;
|
|
1695
|
+
/**
|
|
1696
|
+
* 安装插件
|
|
1697
|
+
*/
|
|
1698
|
+
install(_core: Core, services: ServiceContainer): Promise<void>;
|
|
1699
|
+
/**
|
|
1700
|
+
* 卸载插件
|
|
1701
|
+
*/
|
|
1702
|
+
uninstall(): Promise<void>;
|
|
1703
|
+
/**
|
|
1704
|
+
* 为场景设置行为树系统
|
|
1705
|
+
*
|
|
1706
|
+
* 向场景添加行为树执行系统
|
|
1707
|
+
*
|
|
1708
|
+
* @param scene 目标场景
|
|
1709
|
+
*
|
|
1710
|
+
* @example
|
|
1711
|
+
* ```typescript
|
|
1712
|
+
* const scene = new Scene();
|
|
1713
|
+
* behaviorTreePlugin.setupScene(scene);
|
|
1714
|
+
* ```
|
|
1715
|
+
*/
|
|
1716
|
+
setupScene(scene: IScene): void;
|
|
1717
|
+
/**
|
|
1718
|
+
* 为所有现有场景设置行为树系统
|
|
1719
|
+
*/
|
|
1720
|
+
setupAllScenes(): void;
|
|
1721
|
+
}
|
|
2873
1722
|
|
|
2874
|
-
export { AbortType,
|
|
2875
|
-
export type { AssetMetadata,
|
|
1723
|
+
export { AbortType, AlwaysFailExecutor, AlwaysSucceedExecutor, BehaviorTreeAssetManager, BehaviorTreeAssetSerializer, BehaviorTreeAssetValidator, BehaviorTreeBuilder, BehaviorTreeExecutionSystem, BehaviorTreePlugin, BehaviorTreeRuntimeComponent, BehaviorTreeStarter, BindingHelper, BlackboardCompare, BlackboardExists, BlackboardValueType, CompositeType, ConditionalExecutor, CooldownExecutor, DecoratorType, EditorFormatConverter, ExecuteAction, ExecuteCondition, GlobalBlackboardService, InverterExecutor, LogAction, ModifyBlackboardValue, NodeExecutorMetadata, NodeExecutorRegistry, NodeMetadataRegistry, NodeTemplates, NodeType, ParallelExecutor, ParallelSelectorExecutor, PropertyType, RandomProbability, RandomSelectorExecutor, RandomSequenceExecutor, RepeaterExecutor, SelectorExecutor, SequenceExecutor, ServiceDecorator, ServiceRegistry, SetBlackboardValue, SubTreeExecutor, TaskStatus, TimeoutExecutor, UntilFailExecutor, UntilSuccessExecutor, WaitAction, createDefaultRuntimeState };
|
|
1724
|
+
export type { AssetMetadata, AssetValidationResult, BehaviorNodeConfigData, BehaviorNodeData, BehaviorTreeAsset, BehaviorTreeData, BehaviorTreeNodeData, BlackboardVariable, BlackboardVariableDefinition, ConfigFieldDefinition, DeserializationOptions, EditorConnection, EditorFormat, EditorNode, EditorNodeData, EditorNodeTemplate, GlobalBlackboardConfig, INodeExecutor, IServiceExecutor, NodeDataJSON, NodeExecutionContext, NodeMetadata, NodeRuntimeState, NodeTemplate, PropertyBinding, PropertyDefinition, SerializationFormat, SerializationOptions };
|