@esengine/behavior-tree 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/{index.d.ts → dist/index.d.ts} +361 -73
- package/dist/index.js +4692 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -29
- package/index.cjs +0 -2
- package/index.cjs.map +0 -1
- package/index.es5.js +0 -4
- package/index.es5.js.map +0 -1
- package/index.mjs +0 -2
- package/index.mjs.map +0 -1
- package/index.umd.js +0 -2
- package/index.umd.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ESEngine Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import * as _esengine_ecs_framework from '@esengine/ecs-framework';
|
|
2
|
+
import { Component, IService, Entity, EntitySystem, ServiceContainer } from '@esengine/ecs-framework';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
5
|
+
* Behavior Tree Constants
|
|
6
|
+
* 行为树常量
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
declare const BehaviorTreeAssetType: "behavior-tree";
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* 任务执行状态
|
|
@@ -21,6 +24,8 @@ declare enum TaskStatus {
|
|
|
21
24
|
* 内置节点类型常量
|
|
22
25
|
*/
|
|
23
26
|
declare const NodeType: {
|
|
27
|
+
/** 根节点 - 行为树的起始节点 */
|
|
28
|
+
readonly Root: "root";
|
|
24
29
|
/** 复合节点 - 有多个子节点 */
|
|
25
30
|
readonly Composite: "composite";
|
|
26
31
|
/** 装饰器节点 - 有一个子节点 */
|
|
@@ -103,7 +108,7 @@ declare enum AbortType {
|
|
|
103
108
|
/**
|
|
104
109
|
* 黑板变量类型
|
|
105
110
|
*/
|
|
106
|
-
declare enum BlackboardValueType {
|
|
111
|
+
declare enum BlackboardValueType$1 {
|
|
107
112
|
String = "string",
|
|
108
113
|
Number = "number",
|
|
109
114
|
Boolean = "boolean",
|
|
@@ -117,7 +122,7 @@ declare enum BlackboardValueType {
|
|
|
117
122
|
*/
|
|
118
123
|
interface BlackboardVariable {
|
|
119
124
|
name: string;
|
|
120
|
-
type: BlackboardValueType;
|
|
125
|
+
type: BlackboardValueType$1;
|
|
121
126
|
value: any;
|
|
122
127
|
readonly?: boolean;
|
|
123
128
|
description?: string;
|
|
@@ -171,6 +176,8 @@ interface NodeRuntimeState {
|
|
|
171
176
|
status: TaskStatus;
|
|
172
177
|
/** 当前执行的子节点索引(复合节点使用) */
|
|
173
178
|
currentChildIndex: number;
|
|
179
|
+
/** 执行顺序号(用于调试和可视化) */
|
|
180
|
+
executionOrder?: number;
|
|
174
181
|
/** 开始执行时间(某些节点需要) */
|
|
175
182
|
startTime?: number;
|
|
176
183
|
/** 上次执行时间(冷却节点使用) */
|
|
@@ -193,6 +200,56 @@ interface NodeRuntimeState {
|
|
|
193
200
|
*/
|
|
194
201
|
declare function createDefaultRuntimeState(): NodeRuntimeState;
|
|
195
202
|
|
|
203
|
+
/**
|
|
204
|
+
* @zh 资产管理器接口(可选依赖)
|
|
205
|
+
* @en Asset manager interface (optional dependency)
|
|
206
|
+
*
|
|
207
|
+
* @zh 行为树系统的可选资产管理器接口。
|
|
208
|
+
* 当与 ESEngine 的 asset-system 集成时,传入 IAssetManager 实例。
|
|
209
|
+
* 不使用 ESEngine 时,可以直接使用 BehaviorTreeAssetManager.loadFromEditorJSON()。
|
|
210
|
+
*
|
|
211
|
+
* @en Optional asset manager interface for behavior tree system.
|
|
212
|
+
* When integrating with ESEngine's asset-system, pass an IAssetManager instance.
|
|
213
|
+
* When not using ESEngine, use BehaviorTreeAssetManager.loadFromEditorJSON() directly.
|
|
214
|
+
*/
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @zh 行为树资产内容
|
|
218
|
+
* @en Behavior tree asset content
|
|
219
|
+
*/
|
|
220
|
+
interface IBehaviorTreeAssetContent {
|
|
221
|
+
/** @zh 行为树数据 @en Behavior tree data */
|
|
222
|
+
data: BehaviorTreeData;
|
|
223
|
+
/** @zh 文件路径 @en File path */
|
|
224
|
+
path: string;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* @zh 简化的资产管理器接口
|
|
228
|
+
* @en Simplified asset manager interface
|
|
229
|
+
*
|
|
230
|
+
* @zh 这是行为树系统需要的最小资产管理器接口。
|
|
231
|
+
* ESEngine 的 IAssetManager 实现此接口。
|
|
232
|
+
* 其他引擎可以提供自己的实现。
|
|
233
|
+
*
|
|
234
|
+
* @en This is the minimal asset manager interface required by the behavior tree system.
|
|
235
|
+
* ESEngine's IAssetManager implements this interface.
|
|
236
|
+
* Other engines can provide their own implementation.
|
|
237
|
+
*/
|
|
238
|
+
interface IBTAssetManager {
|
|
239
|
+
/**
|
|
240
|
+
* @zh 通过 GUID 加载资产
|
|
241
|
+
* @en Load asset by GUID
|
|
242
|
+
*/
|
|
243
|
+
loadAsset(guid: string): Promise<{
|
|
244
|
+
asset: IBehaviorTreeAssetContent | null;
|
|
245
|
+
} | null>;
|
|
246
|
+
/**
|
|
247
|
+
* @zh 通过 GUID 获取已加载的资产
|
|
248
|
+
* @en Get loaded asset by GUID
|
|
249
|
+
*/
|
|
250
|
+
getAsset<T = IBehaviorTreeAssetContent>(guid: string): T | null;
|
|
251
|
+
}
|
|
252
|
+
|
|
196
253
|
/**
|
|
197
254
|
* 黑板变化监听器
|
|
198
255
|
*/
|
|
@@ -242,6 +299,10 @@ declare class BehaviorTreeRuntimeComponent extends Component {
|
|
|
242
299
|
* 需要中止的节点ID列表
|
|
243
300
|
*/
|
|
244
301
|
nodesToAbort: Set<string>;
|
|
302
|
+
/**
|
|
303
|
+
* 执行顺序计数器(用于调试和可视化)
|
|
304
|
+
*/
|
|
305
|
+
executionOrderCounter: number;
|
|
245
306
|
/**
|
|
246
307
|
* 获取节点运行时状态
|
|
247
308
|
*/
|
|
@@ -344,6 +405,27 @@ declare class BehaviorTreeAssetManager implements IService {
|
|
|
344
405
|
* 加载行为树资产
|
|
345
406
|
*/
|
|
346
407
|
loadAsset(asset: BehaviorTreeData): void;
|
|
408
|
+
/**
|
|
409
|
+
* 从编辑器 JSON 格式加载行为树资产
|
|
410
|
+
*
|
|
411
|
+
* @param json 编辑器导出的 JSON 字符串
|
|
412
|
+
* @returns 加载的行为树数据
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```typescript
|
|
416
|
+
* const assetManager = Core.services.resolve(BehaviorTreeAssetManager);
|
|
417
|
+
* const jsonContent = await readFile('path/to/tree.btree');
|
|
418
|
+
* const treeData = assetManager.loadFromEditorJSON(jsonContent);
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
loadFromEditorJSON(json: string): BehaviorTreeData;
|
|
422
|
+
/**
|
|
423
|
+
* 批量加载多个行为树资产(从编辑器JSON)
|
|
424
|
+
*
|
|
425
|
+
* @param jsonDataList JSON字符串列表
|
|
426
|
+
* @returns 成功加载的资产数量
|
|
427
|
+
*/
|
|
428
|
+
loadMultipleFromEditorJSON(jsonDataList: string[]): number;
|
|
347
429
|
/**
|
|
348
430
|
* 获取行为树资产
|
|
349
431
|
*/
|
|
@@ -474,6 +556,16 @@ declare class NodeExecutorRegistry {
|
|
|
474
556
|
clear(): void;
|
|
475
557
|
}
|
|
476
558
|
|
|
559
|
+
/**
|
|
560
|
+
* 根节点执行器
|
|
561
|
+
*
|
|
562
|
+
* 行为树的入口节点,执行其唯一的子节点
|
|
563
|
+
*/
|
|
564
|
+
declare class RootExecutor implements INodeExecutor {
|
|
565
|
+
execute(context: NodeExecutionContext): TaskStatus;
|
|
566
|
+
reset(_context: NodeExecutionContext): void;
|
|
567
|
+
}
|
|
568
|
+
|
|
477
569
|
/**
|
|
478
570
|
* 序列节点执行器
|
|
479
571
|
*
|
|
@@ -787,9 +879,53 @@ declare class ExecuteCondition implements INodeExecutor {
|
|
|
787
879
|
* 统一处理所有行为树的执行
|
|
788
880
|
*/
|
|
789
881
|
declare class BehaviorTreeExecutionSystem extends EntitySystem {
|
|
790
|
-
private
|
|
882
|
+
private btAssetManager;
|
|
791
883
|
private executorRegistry;
|
|
792
|
-
|
|
884
|
+
private _services;
|
|
885
|
+
/** 引用外部资产管理器(可选,由外部模块设置) */
|
|
886
|
+
private _assetManager;
|
|
887
|
+
/** 已警告过的缺失资产,避免重复警告 */
|
|
888
|
+
private _warnedMissingAssets;
|
|
889
|
+
constructor(services?: ServiceContainer);
|
|
890
|
+
/**
|
|
891
|
+
* @zh 设置外部资产管理器引用(可选)
|
|
892
|
+
* @en Set external asset manager reference (optional)
|
|
893
|
+
*
|
|
894
|
+
* @zh 当与 ESEngine 集成时,由 BehaviorTreeRuntimeModule 调用。
|
|
895
|
+
* 不使用 ESEngine 时,可以不调用此方法,
|
|
896
|
+
* 直接使用 BehaviorTreeAssetManager.loadFromEditorJSON() 加载资产。
|
|
897
|
+
*
|
|
898
|
+
* @en Called by BehaviorTreeRuntimeModule when integrating with ESEngine.
|
|
899
|
+
* When not using ESEngine, you can skip this and use
|
|
900
|
+
* BehaviorTreeAssetManager.loadFromEditorJSON() to load assets directly.
|
|
901
|
+
*/
|
|
902
|
+
setAssetManager(assetManager: IBTAssetManager | null): void;
|
|
903
|
+
/**
|
|
904
|
+
* 启动所有 autoStart 的行为树(用于预览模式)
|
|
905
|
+
* Start all autoStart behavior trees (for preview mode)
|
|
906
|
+
*
|
|
907
|
+
* 由于编辑器模式下系统默认禁用,实体添加时 onAdded 不会处理自动启动。
|
|
908
|
+
* 预览开始时需要手动调用此方法来启动所有需要自动启动的行为树。
|
|
909
|
+
*/
|
|
910
|
+
startAllAutoStartTrees(): void;
|
|
911
|
+
/**
|
|
912
|
+
* 当实体添加到系统时,处理自动启动
|
|
913
|
+
* Handle auto-start when entity is added to system
|
|
914
|
+
*/
|
|
915
|
+
protected onAdded(entity: Entity): void;
|
|
916
|
+
/**
|
|
917
|
+
* 确保行为树资产已加载
|
|
918
|
+
* Ensure behavior tree asset is loaded
|
|
919
|
+
*/
|
|
920
|
+
private ensureAssetLoaded;
|
|
921
|
+
private getBTAssetManager;
|
|
922
|
+
/**
|
|
923
|
+
* 获取行为树数据
|
|
924
|
+
* Get behavior tree data from AssetManager or BehaviorTreeAssetManager
|
|
925
|
+
*
|
|
926
|
+
* 优先从 AssetManager 获取(新方式),如果没有再从 BehaviorTreeAssetManager 获取(兼容旧方式)
|
|
927
|
+
*/
|
|
928
|
+
private getTreeData;
|
|
793
929
|
/**
|
|
794
930
|
* 注册所有执行器(包括内置和插件提供的)
|
|
795
931
|
*/
|
|
@@ -830,6 +966,14 @@ interface ConfigFieldDefinition {
|
|
|
830
966
|
supportBinding?: boolean;
|
|
831
967
|
allowMultipleConnections?: boolean;
|
|
832
968
|
}
|
|
969
|
+
/**
|
|
970
|
+
* 子节点约束配置
|
|
971
|
+
*/
|
|
972
|
+
interface ChildrenConstraints {
|
|
973
|
+
min?: number;
|
|
974
|
+
max?: number;
|
|
975
|
+
required?: boolean;
|
|
976
|
+
}
|
|
833
977
|
/**
|
|
834
978
|
* 节点元数据
|
|
835
979
|
*/
|
|
@@ -840,6 +984,7 @@ interface NodeMetadata {
|
|
|
840
984
|
description?: string;
|
|
841
985
|
category?: string;
|
|
842
986
|
configSchema?: Record<string, ConfigFieldDefinition>;
|
|
987
|
+
childrenConstraints?: ChildrenConstraints;
|
|
843
988
|
}
|
|
844
989
|
/**
|
|
845
990
|
* 节点元数据注册表
|
|
@@ -1048,9 +1193,10 @@ interface NodeDataJSON {
|
|
|
1048
1193
|
[key: string]: any;
|
|
1049
1194
|
}
|
|
1050
1195
|
/**
|
|
1051
|
-
*
|
|
1196
|
+
* 行为树节点属性类型常量
|
|
1197
|
+
* Behavior tree node property type constants
|
|
1052
1198
|
*/
|
|
1053
|
-
declare const
|
|
1199
|
+
declare const NodePropertyType: {
|
|
1054
1200
|
/** 字符串 */
|
|
1055
1201
|
readonly String: "string";
|
|
1056
1202
|
/** 数值 */
|
|
@@ -1069,25 +1215,26 @@ declare const PropertyType: {
|
|
|
1069
1215
|
readonly Asset: "asset";
|
|
1070
1216
|
};
|
|
1071
1217
|
/**
|
|
1072
|
-
*
|
|
1218
|
+
* 节点属性类型(支持自定义扩展)
|
|
1219
|
+
* Node property type (supports custom extensions)
|
|
1073
1220
|
*
|
|
1074
1221
|
* @example
|
|
1075
1222
|
* ```typescript
|
|
1076
1223
|
* // 使用内置类型
|
|
1077
|
-
* type:
|
|
1224
|
+
* type: NodePropertyType.String
|
|
1078
1225
|
*
|
|
1079
1226
|
* // 使用自定义类型
|
|
1080
1227
|
* type: 'color-picker'
|
|
1081
1228
|
* type: 'curve-editor'
|
|
1082
1229
|
* ```
|
|
1083
1230
|
*/
|
|
1084
|
-
type
|
|
1231
|
+
type NodePropertyType = (typeof NodePropertyType)[keyof typeof NodePropertyType] | string;
|
|
1085
1232
|
/**
|
|
1086
1233
|
* 属性定义(用于编辑器)
|
|
1087
1234
|
*/
|
|
1088
1235
|
interface PropertyDefinition {
|
|
1089
1236
|
name: string;
|
|
1090
|
-
type:
|
|
1237
|
+
type: NodePropertyType;
|
|
1091
1238
|
label: string;
|
|
1092
1239
|
description?: string;
|
|
1093
1240
|
defaultValue?: any;
|
|
@@ -1099,6 +1246,23 @@ interface PropertyDefinition {
|
|
|
1099
1246
|
max?: number;
|
|
1100
1247
|
step?: number;
|
|
1101
1248
|
required?: boolean;
|
|
1249
|
+
/**
|
|
1250
|
+
* 字段编辑器配置
|
|
1251
|
+
*
|
|
1252
|
+
* 指定使用哪个字段编辑器以及相关选项
|
|
1253
|
+
*
|
|
1254
|
+
* @example
|
|
1255
|
+
* ```typescript
|
|
1256
|
+
* fieldEditor: {
|
|
1257
|
+
* type: 'asset',
|
|
1258
|
+
* options: { fileExtension: '.btree' }
|
|
1259
|
+
* }
|
|
1260
|
+
* ```
|
|
1261
|
+
*/
|
|
1262
|
+
fieldEditor?: {
|
|
1263
|
+
type: string;
|
|
1264
|
+
options?: Record<string, any>;
|
|
1265
|
+
};
|
|
1102
1266
|
/**
|
|
1103
1267
|
* 自定义渲染配置
|
|
1104
1268
|
*
|
|
@@ -1172,6 +1336,8 @@ interface NodeTemplate {
|
|
|
1172
1336
|
className?: string;
|
|
1173
1337
|
componentClass?: Function;
|
|
1174
1338
|
requiresChildren?: boolean;
|
|
1339
|
+
minChildren?: number;
|
|
1340
|
+
maxChildren?: number;
|
|
1175
1341
|
defaultConfig: Partial<NodeDataJSON>;
|
|
1176
1342
|
properties: PropertyDefinition[];
|
|
1177
1343
|
}
|
|
@@ -1191,6 +1357,10 @@ declare class NodeTemplates {
|
|
|
1191
1357
|
* 将NodeMetadata转换为NodeTemplate
|
|
1192
1358
|
*/
|
|
1193
1359
|
private static convertMetadataToTemplate;
|
|
1360
|
+
/**
|
|
1361
|
+
* 获取节点类型的默认约束
|
|
1362
|
+
*/
|
|
1363
|
+
private static getDefaultConstraintsByNodeType;
|
|
1194
1364
|
/**
|
|
1195
1365
|
* 将ConfigSchema转换为PropertyDefinition数组
|
|
1196
1366
|
*/
|
|
@@ -1228,7 +1398,7 @@ interface AssetMetadata {
|
|
|
1228
1398
|
*/
|
|
1229
1399
|
interface BlackboardVariableDefinition {
|
|
1230
1400
|
name: string;
|
|
1231
|
-
type: BlackboardValueType;
|
|
1401
|
+
type: BlackboardValueType$1;
|
|
1232
1402
|
defaultValue: any;
|
|
1233
1403
|
readonly?: boolean;
|
|
1234
1404
|
description?: string;
|
|
@@ -1337,7 +1507,7 @@ interface EditorNodeData {
|
|
|
1337
1507
|
name?: string;
|
|
1338
1508
|
[key: string]: any;
|
|
1339
1509
|
}
|
|
1340
|
-
interface EditorNode {
|
|
1510
|
+
interface EditorNode$1 {
|
|
1341
1511
|
id: string;
|
|
1342
1512
|
template: EditorNodeTemplate;
|
|
1343
1513
|
data: EditorNodeData;
|
|
@@ -1350,7 +1520,7 @@ interface EditorNode {
|
|
|
1350
1520
|
/**
|
|
1351
1521
|
* 编辑器连接格式
|
|
1352
1522
|
*/
|
|
1353
|
-
interface EditorConnection {
|
|
1523
|
+
interface EditorConnection$1 {
|
|
1354
1524
|
from: string;
|
|
1355
1525
|
to: string;
|
|
1356
1526
|
fromProperty?: string;
|
|
@@ -1368,8 +1538,8 @@ interface EditorFormat {
|
|
|
1368
1538
|
createdAt?: string;
|
|
1369
1539
|
modifiedAt?: string;
|
|
1370
1540
|
};
|
|
1371
|
-
nodes: EditorNode[];
|
|
1372
|
-
connections: EditorConnection[];
|
|
1541
|
+
nodes: EditorNode$1[];
|
|
1542
|
+
connections: EditorConnection$1[];
|
|
1373
1543
|
blackboard: Record<string, any>;
|
|
1374
1544
|
canvasState?: {
|
|
1375
1545
|
offset: {
|
|
@@ -1443,9 +1613,10 @@ declare class EditorFormatConverter {
|
|
|
1443
1613
|
}
|
|
1444
1614
|
|
|
1445
1615
|
/**
|
|
1446
|
-
*
|
|
1616
|
+
* 行为树序列化格式
|
|
1617
|
+
* Behavior tree serialization format
|
|
1447
1618
|
*/
|
|
1448
|
-
type
|
|
1619
|
+
type BehaviorTreeSerializationFormat = 'json' | 'binary';
|
|
1449
1620
|
/**
|
|
1450
1621
|
* 序列化选项
|
|
1451
1622
|
*/
|
|
@@ -1453,7 +1624,7 @@ interface SerializationOptions {
|
|
|
1453
1624
|
/**
|
|
1454
1625
|
* 序列化格式
|
|
1455
1626
|
*/
|
|
1456
|
-
format:
|
|
1627
|
+
format: BehaviorTreeSerializationFormat;
|
|
1457
1628
|
/**
|
|
1458
1629
|
* 是否美化JSON输出(仅format='json'时有效)
|
|
1459
1630
|
*/
|
|
@@ -1538,7 +1709,7 @@ declare class BehaviorTreeAssetSerializer {
|
|
|
1538
1709
|
* @param data 序列化的数据
|
|
1539
1710
|
* @returns 格式类型
|
|
1540
1711
|
*/
|
|
1541
|
-
static detectFormat(data: string | Uint8Array):
|
|
1712
|
+
static detectFormat(data: string | Uint8Array): BehaviorTreeSerializationFormat;
|
|
1542
1713
|
/**
|
|
1543
1714
|
* 获取序列化数据的信息(不完全反序列化)
|
|
1544
1715
|
*
|
|
@@ -1546,7 +1717,7 @@ declare class BehaviorTreeAssetSerializer {
|
|
|
1546
1717
|
* @returns 资产元信息
|
|
1547
1718
|
*/
|
|
1548
1719
|
static getInfo(data: string | Uint8Array): {
|
|
1549
|
-
format:
|
|
1720
|
+
format: BehaviorTreeSerializationFormat;
|
|
1550
1721
|
name: string;
|
|
1551
1722
|
version: string;
|
|
1552
1723
|
nodeCount: number;
|
|
@@ -1570,7 +1741,7 @@ declare class BehaviorTreeAssetSerializer {
|
|
|
1570
1741
|
* const json = BehaviorTreeAssetSerializer.convert(binaryData, 'json', true);
|
|
1571
1742
|
* ```
|
|
1572
1743
|
*/
|
|
1573
|
-
static convert(data: string | Uint8Array, targetFormat:
|
|
1744
|
+
static convert(data: string | Uint8Array, targetFormat: BehaviorTreeSerializationFormat, pretty?: boolean): string | Uint8Array;
|
|
1574
1745
|
/**
|
|
1575
1746
|
* 比较两个资产数据的大小
|
|
1576
1747
|
*
|
|
@@ -1586,6 +1757,130 @@ declare class BehaviorTreeAssetSerializer {
|
|
|
1586
1757
|
};
|
|
1587
1758
|
}
|
|
1588
1759
|
|
|
1760
|
+
/**
|
|
1761
|
+
* 编辑器节点数据接口
|
|
1762
|
+
*/
|
|
1763
|
+
interface EditorNode {
|
|
1764
|
+
id: string;
|
|
1765
|
+
template: {
|
|
1766
|
+
type: string;
|
|
1767
|
+
className: string;
|
|
1768
|
+
displayName?: string;
|
|
1769
|
+
};
|
|
1770
|
+
data: Record<string, any>;
|
|
1771
|
+
children?: string[];
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* 编辑器连接数据接口
|
|
1775
|
+
*/
|
|
1776
|
+
interface EditorConnection {
|
|
1777
|
+
from: string;
|
|
1778
|
+
to: string;
|
|
1779
|
+
connectionType: 'node' | 'property';
|
|
1780
|
+
fromProperty?: string;
|
|
1781
|
+
toProperty?: string;
|
|
1782
|
+
}
|
|
1783
|
+
/**
|
|
1784
|
+
* 编辑器行为树数据接口
|
|
1785
|
+
*/
|
|
1786
|
+
interface EditorBehaviorTreeData {
|
|
1787
|
+
version?: string;
|
|
1788
|
+
metadata?: {
|
|
1789
|
+
name: string;
|
|
1790
|
+
description?: string;
|
|
1791
|
+
createdAt?: string;
|
|
1792
|
+
modifiedAt?: string;
|
|
1793
|
+
};
|
|
1794
|
+
nodes: EditorNode[];
|
|
1795
|
+
connections?: EditorConnection[];
|
|
1796
|
+
blackboard?: Record<string, any>;
|
|
1797
|
+
}
|
|
1798
|
+
/**
|
|
1799
|
+
* 编辑器格式到运行时格式的转换器
|
|
1800
|
+
*
|
|
1801
|
+
* 负责将编辑器的 JSON 格式(包含UI信息)转换为运行时的 BehaviorTreeData 格式
|
|
1802
|
+
*/
|
|
1803
|
+
declare class EditorToBehaviorTreeDataConverter {
|
|
1804
|
+
/**
|
|
1805
|
+
* 将编辑器 JSON 字符串转换为运行时 BehaviorTreeData
|
|
1806
|
+
*/
|
|
1807
|
+
static fromEditorJSON(json: string): BehaviorTreeData;
|
|
1808
|
+
/**
|
|
1809
|
+
* 将编辑器数据对象转换为运行时 BehaviorTreeData
|
|
1810
|
+
*/
|
|
1811
|
+
static convert(editorData: EditorBehaviorTreeData): BehaviorTreeData;
|
|
1812
|
+
/**
|
|
1813
|
+
* 从连接数据构建属性绑定映射
|
|
1814
|
+
* 处理 connectionType === 'property' 的连接,将黑板变量节点连接到目标节点的属性
|
|
1815
|
+
*/
|
|
1816
|
+
private static buildPropertyBindingsMap;
|
|
1817
|
+
/**
|
|
1818
|
+
* 转换单个节点
|
|
1819
|
+
* @param editorNode 编辑器节点数据
|
|
1820
|
+
* @param propertyBindings 从连接中提取的属性绑定(可选)
|
|
1821
|
+
*/
|
|
1822
|
+
private static convertNode;
|
|
1823
|
+
/**
|
|
1824
|
+
* 检查是否为不可执行的节点(如黑板变量节点)
|
|
1825
|
+
* 这些节点只在编辑器中使用,不参与运行时执行
|
|
1826
|
+
*/
|
|
1827
|
+
private static isNonExecutableNode;
|
|
1828
|
+
/**
|
|
1829
|
+
* 从节点数据中提取实现类型
|
|
1830
|
+
*
|
|
1831
|
+
* 优先级:
|
|
1832
|
+
* 1. template.className(标准方式)
|
|
1833
|
+
* 2. data 中的类型字段(compositeType, actionType 等)
|
|
1834
|
+
* 3. 特殊节点类型的默认值(如 Root)
|
|
1835
|
+
*/
|
|
1836
|
+
private static extractImplementationType;
|
|
1837
|
+
/**
|
|
1838
|
+
* 获取节点类型的默认实现
|
|
1839
|
+
* 当无法确定具体实现类型时使用
|
|
1840
|
+
*/
|
|
1841
|
+
private static getDefaultImplementationType;
|
|
1842
|
+
/**
|
|
1843
|
+
* 映射节点类型
|
|
1844
|
+
*/
|
|
1845
|
+
private static mapNodeType;
|
|
1846
|
+
/**
|
|
1847
|
+
* 提取节点配置(过滤掉内部字段和绑定字段)
|
|
1848
|
+
*/
|
|
1849
|
+
private static extractConfig;
|
|
1850
|
+
/**
|
|
1851
|
+
* 提取黑板变量绑定
|
|
1852
|
+
*/
|
|
1853
|
+
private static extractBindings;
|
|
1854
|
+
/**
|
|
1855
|
+
* 判断是否为黑板绑定
|
|
1856
|
+
*/
|
|
1857
|
+
private static isBinding;
|
|
1858
|
+
/**
|
|
1859
|
+
* 提取黑板绑定的键名
|
|
1860
|
+
*/
|
|
1861
|
+
private static extractBindingKey;
|
|
1862
|
+
/**
|
|
1863
|
+
* 提取中止类型(条件装饰器使用)
|
|
1864
|
+
*/
|
|
1865
|
+
private static extractAbortType;
|
|
1866
|
+
/**
|
|
1867
|
+
* 生成行为树ID
|
|
1868
|
+
*/
|
|
1869
|
+
private static generateTreeId;
|
|
1870
|
+
/**
|
|
1871
|
+
* 将运行时格式转换回编辑器格式(用于双向转换)
|
|
1872
|
+
*/
|
|
1873
|
+
static toEditorJSON(treeData: BehaviorTreeData): string;
|
|
1874
|
+
/**
|
|
1875
|
+
* 将运行时 BehaviorTreeData 转换为编辑器格式
|
|
1876
|
+
*/
|
|
1877
|
+
static convertToEditor(treeData: BehaviorTreeData): EditorBehaviorTreeData;
|
|
1878
|
+
/**
|
|
1879
|
+
* 将运行时节点转换为编辑器节点
|
|
1880
|
+
*/
|
|
1881
|
+
private static convertNodeToEditor;
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1589
1884
|
/**
|
|
1590
1885
|
* 全局黑板配置
|
|
1591
1886
|
*/
|
|
@@ -1613,7 +1908,7 @@ declare class GlobalBlackboardService implements IService {
|
|
|
1613
1908
|
/**
|
|
1614
1909
|
* 定义全局变量
|
|
1615
1910
|
*/
|
|
1616
|
-
defineVariable(name: string, type: BlackboardValueType, initialValue: any, options?: {
|
|
1911
|
+
defineVariable(name: string, type: BlackboardValueType$1, initialValue: any, options?: {
|
|
1617
1912
|
readonly?: boolean;
|
|
1618
1913
|
description?: string;
|
|
1619
1914
|
}): void;
|
|
@@ -1671,54 +1966,47 @@ declare class GlobalBlackboardService implements IService {
|
|
|
1671
1966
|
static fromJSON(json: string): GlobalBlackboardConfig;
|
|
1672
1967
|
}
|
|
1673
1968
|
|
|
1969
|
+
declare enum BlackboardValueType {
|
|
1970
|
+
String = "string",
|
|
1971
|
+
Number = "number",
|
|
1972
|
+
Boolean = "boolean",
|
|
1973
|
+
Vector2 = "vector2",
|
|
1974
|
+
Vector3 = "vector3",
|
|
1975
|
+
Vector4 = "vector4",
|
|
1976
|
+
Quaternion = "quaternion",
|
|
1977
|
+
Color = "color",
|
|
1978
|
+
GameObject = "gameObject",
|
|
1979
|
+
Transform = "transform",
|
|
1980
|
+
Component = "component",
|
|
1981
|
+
AssetReference = "assetReference",
|
|
1982
|
+
Array = "array",
|
|
1983
|
+
Map = "map",
|
|
1984
|
+
Enum = "enum",
|
|
1985
|
+
Struct = "struct",
|
|
1986
|
+
Function = "function",
|
|
1987
|
+
EntityId = "entityId",
|
|
1988
|
+
NodePath = "nodePath",
|
|
1989
|
+
ResourcePath = "resourcePath",
|
|
1990
|
+
AnimationState = "animationState",
|
|
1991
|
+
AudioClip = "audioClip",
|
|
1992
|
+
Material = "material",
|
|
1993
|
+
Texture = "texture"
|
|
1994
|
+
}
|
|
1995
|
+
interface BlackboardTypeDefinition {
|
|
1996
|
+
type: BlackboardValueType;
|
|
1997
|
+
displayName: string;
|
|
1998
|
+
category: 'basic' | 'math' | 'reference' | 'collection' | 'advanced' | 'game';
|
|
1999
|
+
defaultValue: any;
|
|
2000
|
+
editorComponent?: string;
|
|
2001
|
+
validator?: (value: any) => boolean;
|
|
2002
|
+
converter?: (value: any) => any;
|
|
2003
|
+
}
|
|
2004
|
+
declare const BlackboardTypes: Record<BlackboardValueType, BlackboardTypeDefinition>;
|
|
2005
|
+
|
|
1674
2006
|
/**
|
|
1675
|
-
*
|
|
1676
|
-
*
|
|
1677
|
-
* 提供便捷方法向场景添加行为树系统
|
|
1678
|
-
*
|
|
1679
|
-
* @example
|
|
1680
|
-
* ```typescript
|
|
1681
|
-
* const core = Core.create();
|
|
1682
|
-
* const plugin = new BehaviorTreePlugin();
|
|
1683
|
-
* await core.pluginManager.install(plugin);
|
|
1684
|
-
*
|
|
1685
|
-
* // 为场景添加行为树系统
|
|
1686
|
-
* const scene = new Scene();
|
|
1687
|
-
* plugin.setupScene(scene);
|
|
1688
|
-
* ```
|
|
2007
|
+
* 行为树执行系统令牌
|
|
2008
|
+
* Behavior tree execution system token
|
|
1689
2009
|
*/
|
|
1690
|
-
declare
|
|
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
|
-
}
|
|
2010
|
+
declare const BehaviorTreeSystemToken: _esengine_ecs_framework.ServiceToken<BehaviorTreeExecutionSystem>;
|
|
1722
2011
|
|
|
1723
|
-
export { AbortType, AlwaysFailExecutor, AlwaysSucceedExecutor, BehaviorTreeAssetManager, BehaviorTreeAssetSerializer, BehaviorTreeAssetValidator, BehaviorTreeBuilder, BehaviorTreeExecutionSystem,
|
|
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 };
|
|
2012
|
+
export { AbortType, AlwaysFailExecutor, AlwaysSucceedExecutor, type AssetMetadata, type AssetValidationResult, type BehaviorNodeConfigData, type BehaviorNodeData, type BehaviorTreeAsset, BehaviorTreeAssetManager, BehaviorTreeAssetSerializer, BehaviorTreeAssetType, BehaviorTreeAssetValidator, BehaviorTreeBuilder, type BehaviorTreeData, BehaviorTreeExecutionSystem, type BehaviorTreeNodeData, BehaviorTreeRuntimeComponent, type BehaviorTreeSerializationFormat, BehaviorTreeStarter, BehaviorTreeSystemToken, BindingHelper, BlackboardCompare, BlackboardExists, type BlackboardTypeDefinition, BlackboardTypes, BlackboardValueType$1 as BlackboardValueType, type BlackboardVariable, type BlackboardVariableDefinition, CompositeType, ConditionalExecutor, type ConfigFieldDefinition, CooldownExecutor, DecoratorType, type DeserializationOptions, type EditorConnection$1 as EditorConnection, type EditorFormat, EditorFormatConverter, type EditorNode$1 as EditorNode, type EditorNodeData, type EditorNodeTemplate, EditorToBehaviorTreeDataConverter, ExecuteAction, ExecuteCondition, type GlobalBlackboardConfig, GlobalBlackboardService, type IBTAssetManager, type IBehaviorTreeAssetContent, type INodeExecutor, type IServiceExecutor, InverterExecutor, LogAction, ModifyBlackboardValue, type NodeDataJSON, type NodeExecutionContext, NodeExecutorMetadata, NodeExecutorRegistry, type NodeMetadata, NodeMetadataRegistry, NodePropertyType, type NodeRuntimeState, type NodeTemplate, NodeTemplates, NodeType, ParallelExecutor, ParallelSelectorExecutor, type PropertyBinding, type PropertyDefinition, RandomProbability, RandomSelectorExecutor, RandomSequenceExecutor, RepeaterExecutor, RootExecutor, SelectorExecutor, SequenceExecutor, type SerializationOptions, ServiceDecorator, ServiceRegistry, SetBlackboardValue, SubTreeExecutor, TaskStatus, TimeoutExecutor, UntilFailExecutor, UntilSuccessExecutor, WaitAction, createDefaultRuntimeState };
|