mirror of
https://github.com/gongxh0901/kunpocc-behaviortree.git
synced 2025-12-27 00:58:18 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e50bb3ba34 | ||
|
|
6b9e7dbdda | ||
|
|
b20cf3fd41 | ||
|
|
249022a300 | ||
|
|
9a3e7028d2 | ||
|
|
63d9855658 | ||
|
|
b1107805d0 | ||
|
|
b582a5d1da | ||
|
|
d7fc1e49ae | ||
|
|
1c5f9de608 | ||
|
|
3071611cd0 | ||
|
|
6ae0b4200a | ||
|
|
6d6162031a |
521
README.md
521
README.md
@@ -10,64 +10,24 @@
|
|||||||
- 🎯 **简洁设计**: 零废话,直接解决问题
|
- 🎯 **简洁设计**: 零废话,直接解决问题
|
||||||
- 🔧 **类型安全**: 完整 TypeScript 支持
|
- 🔧 **类型安全**: 完整 TypeScript 支持
|
||||||
- 🚀 **高性能**: 优化的执行机制,最小开销
|
- 🚀 **高性能**: 优化的执行机制,最小开销
|
||||||
- 🧠 **记忆节点**: 智能状态记忆,避免重复计算
|
|
||||||
- 📦 **零依赖**: 纯净实现,无第三方依赖
|
- 📦 **零依赖**: 纯净实现,无第三方依赖
|
||||||
- 🔄 **状态管理**: 分层黑板系统,数据隔离清晰
|
- 🔄 **状态管理**: 分层黑板系统,数据隔离清晰
|
||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
|
|
||||||
### 安装
|
#### 安装
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install kunpocc-behaviortree
|
npm install kunpocc-behaviortree
|
||||||
```
|
```
|
||||||
|
|
||||||
### 基础示例
|
#### 内置demo
|
||||||
|
|
||||||
```typescript
|
项目根目录下的 `bt-demo`文件夹
|
||||||
import {
|
|
||||||
BehaviorTree, Status, Action, Condition,
|
|
||||||
Sequence, Selector
|
|
||||||
} from 'kunpocc-behaviortree';
|
|
||||||
|
|
||||||
// 定义实体
|
demo是基于`cocos creator3.8.6`制作的
|
||||||
interface Enemy {
|
|
||||||
health: number;
|
|
||||||
hasWeapon: boolean;
|
|
||||||
position: { x: number, y: number };
|
|
||||||
}
|
|
||||||
|
|
||||||
const enemy: Enemy = {
|
|
||||||
health: 30,
|
|
||||||
hasWeapon: true,
|
|
||||||
position: { x: 100, y: 200 }
|
|
||||||
};
|
|
||||||
|
|
||||||
// 创建行为树
|
|
||||||
const tree = new BehaviorTree(enemy,
|
|
||||||
new Selector(
|
|
||||||
// 生命值低时逃跑
|
|
||||||
new Sequence(
|
|
||||||
new Condition((node) => {
|
|
||||||
const entity = node.getEntity<Enemy>();
|
|
||||||
return entity.health < 50;
|
|
||||||
}),
|
|
||||||
new Action((node) => {
|
|
||||||
console.log("血量低,逃跑!");
|
|
||||||
return Status.SUCCESS;
|
|
||||||
})
|
|
||||||
),
|
|
||||||
// 否则攻击
|
|
||||||
new Action((node) => {
|
|
||||||
console.log("发起攻击!");
|
|
||||||
return Status.SUCCESS;
|
|
||||||
})
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// 执行
|
|
||||||
tree.tick(); // 输出: "血量低,逃跑!"
|
|
||||||
```
|
|
||||||
|
|
||||||
## 核心概念
|
## 核心概念
|
||||||
|
|
||||||
@@ -81,196 +41,116 @@ enum Status {
|
|||||||
```
|
```
|
||||||
|
|
||||||
### 节点类型
|
### 节点类型
|
||||||
- **组合节点**: 控制子节点执行逻辑(Sequence、Selector、Parallel等)
|
- **组合节点**: 包含多个子节点 (Composite)
|
||||||
- **装饰节点**: 修饰单个子节点(Inverter、Repeat、Limit等)
|
- **装饰节点**: 有且只有一个子节点(Decorator)
|
||||||
- **叶子节点**: 执行具体逻辑(Action、Condition、Wait等)
|
- **叶子节点**: 不能包含子节点 (LeafNode)
|
||||||
|
- **条件节点**: 特殊的叶子节点 (Condition)
|
||||||
|
|
||||||
## 节点详解
|
|
||||||
|
|
||||||
|
## 装饰器
|
||||||
|
|
||||||
|
> **自行实现的节点,通过装饰器把数据暴露给行为树编辑器**
|
||||||
|
|
||||||
|
##### ClassAction - 行为节点装饰器
|
||||||
|
|
||||||
|
##### ClassCondition - 条件节点装饰器
|
||||||
|
|
||||||
|
##### ClassComposite - 组合节点装饰器
|
||||||
|
|
||||||
|
##### ClassDecorator - 装饰节点装饰器
|
||||||
|
|
||||||
|
##### prop - 属性装饰器
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## 内置节点
|
||||||
|
|
||||||
### 组合节点 (Composite)
|
### 组合节点 (Composite)
|
||||||
|
|
||||||
#### Sequence - 顺序节点
|
##### Selector - 选择节点
|
||||||
按顺序执行子节点,全部成功才成功:
|
* 选择第一个成功的子节点
|
||||||
```typescript
|
|
||||||
new Sequence(
|
|
||||||
checkAmmo, // 检查弹药
|
|
||||||
aim, // 瞄准
|
|
||||||
shoot // 射击
|
|
||||||
)
|
|
||||||
// 只有全部成功才返回SUCCESS
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Selector - 选择节点
|
##### Sequence - 顺序节点
|
||||||
选择第一个成功的子节点:
|
* 按顺序执行子节点,执行过程中子节点返回非SUCCESS,则返回子节点状态,全部成功返回SUCCESS
|
||||||
```typescript
|
|
||||||
new Selector(
|
|
||||||
tryMeleeAttack, // 尝试近战
|
|
||||||
tryRangedAttack, // 尝试远程
|
|
||||||
retreat // 撤退
|
|
||||||
)
|
|
||||||
// 任一成功就返回SUCCESS
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Parallel - 并行节点
|
##### Parallel - 并行节点
|
||||||
同时执行所有子节点,全部成功才成功:
|
* 执行所有子节点,全部成功才成功
|
||||||
```typescript
|
* 并不是真正的并行,也有执行顺序
|
||||||
new Parallel(
|
|
||||||
moveToTarget, // 移动到目标
|
|
||||||
playAnimation, // 播放动画
|
|
||||||
updateUI // 更新UI
|
|
||||||
)
|
|
||||||
// 任一失败返回FAILURE,有RUNNING返回RUNNING,全部SUCCESS才返回SUCCESS
|
|
||||||
```
|
|
||||||
|
|
||||||
#### ParallelAnySuccess - 并行任一成功
|
##### RandomSelector - 随机选择节点
|
||||||
同时执行所有子节点,任一成功就成功:
|
* 随机选择一个子节点执行
|
||||||
```typescript
|
|
||||||
new ParallelAnySuccess(
|
|
||||||
findCover, // 寻找掩体
|
|
||||||
callForHelp, // 呼叫支援
|
|
||||||
counterAttack // 反击
|
|
||||||
)
|
|
||||||
// 任一SUCCESS就返回SUCCESS
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Memory节点 - 状态记忆
|
##### ParallelAnySuccess - 并行任一成功
|
||||||
记忆节点会记住上次执行位置,避免重复执行:
|
* 同时执行所有子节点,任一成功就成功
|
||||||
|
|
||||||
```typescript
|
|
||||||
// MemSequence - 记忆顺序节点
|
|
||||||
new MemSequence(
|
|
||||||
longTask1, // 第一次:SUCCESS,继续下一个
|
|
||||||
longTask2, // 第一次:RUNNING,记住这个位置; 第二次:从longTask2开始继续执行
|
|
||||||
longTask3
|
|
||||||
)
|
|
||||||
|
|
||||||
// MemSelector - 记忆选择节点
|
|
||||||
new MemSelector(
|
|
||||||
expensiveCheck1, // 第一次:FAILURE,继续下一个
|
|
||||||
expensiveCheck2, // 第一次:RUNNING,记住这个位置; 第二次:从expensiveCheck2开始执行
|
|
||||||
fallback // 如果前面都是FAILURE才会执行到这里
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### RandomSelector - 随机选择
|
|
||||||
随机选择一个子节点执行:
|
|
||||||
```typescript
|
|
||||||
new RandomSelector(
|
|
||||||
idleBehavior1,
|
|
||||||
idleBehavior2,
|
|
||||||
idleBehavior3
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 装饰节点 (Decorator)
|
### 装饰节点 (Decorator)
|
||||||
|
|
||||||
#### Inverter - 反转节点
|
##### ConditionDecorator - 条件装饰节点
|
||||||
反转子节点的成功/失败状态:
|
|
||||||
```typescript
|
|
||||||
new Inverter(
|
|
||||||
new Condition((node) => {
|
|
||||||
const enemy = node.getEntity<Enemy>();
|
|
||||||
return enemy.isAlive;
|
|
||||||
})
|
|
||||||
) // 敌人死亡时返回SUCCESS
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Repeat - 重复节点
|
* 子类需实现
|
||||||
重复执行子节点指定次数:
|
|
||||||
```typescript
|
|
||||||
new Repeat(
|
|
||||||
new Action((node) => {
|
|
||||||
console.log("射击");
|
|
||||||
return Status.SUCCESS;
|
|
||||||
}),
|
|
||||||
3 // 射击3次
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### RepeatUntilSuccess - 重复直到成功
|
```typescript
|
||||||
```typescript
|
/**
|
||||||
new RepeatUntilSuccess(
|
* 判断是否满足条件
|
||||||
new Action((node) => {
|
* @returns 是否满足条件
|
||||||
console.log("尝试开门");
|
*/
|
||||||
return Math.random() > 0.5 ? Status.SUCCESS : Status.FAILURE;
|
protected abstract isEligible(): boolean;
|
||||||
}),
|
```
|
||||||
5 // 最多尝试5次
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### RepeatUntilFailure - 重复直到失败
|
##### Inverter - 反转节点
|
||||||
```typescript
|
* 反转子节点的成功/失败状态
|
||||||
new RepeatUntilFailure(
|
|
||||||
new Action((node) => {
|
|
||||||
console.log("收集资源");
|
|
||||||
return Status.SUCCESS; // 持续收集直到失败
|
|
||||||
}),
|
|
||||||
10 // 最多收集10次
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### LimitTime - 时间限制
|
##### LimitTime - 时间限制
|
||||||
```typescript
|
|
||||||
new LimitTime(
|
|
||||||
new Action((node) => {
|
|
||||||
console.log("执行复杂计算");
|
|
||||||
return Status.SUCCESS;
|
|
||||||
}),
|
|
||||||
2.0 // 最多执行2秒
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### LimitTicks - 次数限制
|
* 规定时间内, 向父节点返回子节点的结果,超时后返回失败
|
||||||
```typescript
|
|
||||||
new LimitTicks(
|
|
||||||
new Action((node) => {
|
|
||||||
console.log("尝试操作");
|
|
||||||
return Status.SUCCESS;
|
|
||||||
}),
|
|
||||||
5 // 最多执行5次
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 叶子节点 (Leaf)
|
##### LimitTicks - 次数限制
|
||||||
|
|
||||||
#### Action - 动作节点
|
* 执行次数(子节点非RUNNNG状态)内,向父节点返回子节点的结果,超过次数后返回失败
|
||||||
执行自定义逻辑:
|
|
||||||
```typescript
|
|
||||||
new Action((node) => {
|
|
||||||
// 直接获取实体
|
|
||||||
const target = node.getEntity<Character>();
|
|
||||||
|
|
||||||
// 访问黑板数据
|
##### Repeat - 重复节点
|
||||||
const ammo = node.get<number>('ammo');
|
* 重复执行指定次数
|
||||||
|
|
||||||
if (target && ammo > 0) {
|
##### RepeatUntilSuccess - 重复直到成功
|
||||||
console.log("攻击目标");
|
|
||||||
node.set('ammo', ammo - 1);
|
|
||||||
return Status.SUCCESS;
|
|
||||||
}
|
|
||||||
return Status.FAILURE;
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Condition - 条件节点
|
* 设置最大重试次数
|
||||||
检查条件:
|
|
||||||
```typescript
|
##### RepeatUntilFailure - 重复直到失败
|
||||||
new Condition((node) => {
|
|
||||||
const player = node.getEntity<Player>();
|
* 设置最大重试次数
|
||||||
const health = player.health;
|
|
||||||
return health > 50; // true->SUCCESS, false->FAILURE
|
##### WeightDecorator - 权重装饰节点
|
||||||
})
|
|
||||||
```
|
* 用于随机选择节点的子节点的按权重随机
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### 叶子节点 (LeafNode)
|
||||||
|
|
||||||
|
##### LeafNode - 叶子节点基类
|
||||||
|
|
||||||
|
##### WaitTicks - 次数等待节点
|
||||||
|
|
||||||
|
##### WaitTime - 时间等待节点
|
||||||
|
|
||||||
|
### 条件节点 (Condition)
|
||||||
|
|
||||||
|
##### Condition - 条件节点基类
|
||||||
|
|
||||||
|
* 特殊的叶子节点,子类需实现
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
/**
|
||||||
|
* 判断是否满足条件
|
||||||
|
* @returns 是否满足条件
|
||||||
|
*/
|
||||||
|
protected abstract isEligible(): boolean;
|
||||||
|
```
|
||||||
|
|
||||||
#### WaitTime - 时间等待
|
|
||||||
```typescript
|
|
||||||
new WaitTime(2.5) // 等待2.5秒
|
|
||||||
```
|
|
||||||
|
|
||||||
#### WaitTicks - 帧数等待
|
|
||||||
```typescript
|
|
||||||
new WaitTicks(60) // 等待60帧
|
|
||||||
```
|
|
||||||
|
|
||||||
## 黑板系统
|
## 黑板系统
|
||||||
|
|
||||||
@@ -298,230 +178,7 @@ new Action((node) => {
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### 数据查找链
|
|
||||||
黑板数据按以下顺序查找:
|
|
||||||
1. 当前节点的本地黑板
|
|
||||||
2. 父节点的黑板
|
|
||||||
3. 递归向上查找到根节点
|
|
||||||
|
|
||||||
### Memory节点的数据隔离
|
|
||||||
Memory节点会创建独立的子黑板,确保状态隔离:
|
|
||||||
```typescript
|
|
||||||
const mem1 = new MemSequence(/* ... */);
|
|
||||||
const mem2 = new MemSequence(/* ... */);
|
|
||||||
// mem1 和 mem2 的记忆状态完全独立
|
|
||||||
```
|
|
||||||
|
|
||||||
## 完整示例
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import {
|
|
||||||
BehaviorTree, Status, Action, Condition,
|
|
||||||
Sequence, Selector, MemSelector, Parallel,
|
|
||||||
Inverter, RepeatUntilSuccess, LimitTime
|
|
||||||
} from 'kunpocc-behaviortree';
|
|
||||||
|
|
||||||
interface Character {
|
|
||||||
health: number;
|
|
||||||
mana: number;
|
|
||||||
hasWeapon: boolean;
|
|
||||||
isInCombat: boolean;
|
|
||||||
position: { x: number, y: number };
|
|
||||||
}
|
|
||||||
|
|
||||||
const character: Character = {
|
|
||||||
health: 80,
|
|
||||||
mana: 50,
|
|
||||||
hasWeapon: true,
|
|
||||||
isInCombat: false,
|
|
||||||
position: { x: 0, y: 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
// 构建复杂行为树
|
|
||||||
const behaviorTree = new BehaviorTree(character,
|
|
||||||
new Selector(
|
|
||||||
// 战斗行为
|
|
||||||
new Sequence(
|
|
||||||
new Condition((node) => {
|
|
||||||
const char = node.getEntity<Character>();
|
|
||||||
return char.isInCombat;
|
|
||||||
}),
|
|
||||||
new Selector(
|
|
||||||
// 生命值低时治疗
|
|
||||||
new Sequence(
|
|
||||||
new Condition((node) => {
|
|
||||||
const char = node.getEntity<Character>();
|
|
||||||
return char.health < 30;
|
|
||||||
}),
|
|
||||||
new RepeatUntilSuccess(
|
|
||||||
new Action((node) => {
|
|
||||||
const char = node.getEntity<Character>();
|
|
||||||
if (char.mana >= 10) {
|
|
||||||
char.health += 20;
|
|
||||||
char.mana -= 10;
|
|
||||||
console.log("治疗完成");
|
|
||||||
return Status.SUCCESS;
|
|
||||||
}
|
|
||||||
return Status.FAILURE;
|
|
||||||
}),
|
|
||||||
3 // 最多尝试3次
|
|
||||||
)
|
|
||||||
),
|
|
||||||
// 正常攻击
|
|
||||||
new Sequence(
|
|
||||||
new Condition((node) => {
|
|
||||||
const char = node.getEntity<Character>();
|
|
||||||
return char.hasWeapon;
|
|
||||||
}),
|
|
||||||
new LimitTime(
|
|
||||||
new Action((node) => {
|
|
||||||
console.log("发起攻击");
|
|
||||||
return Status.SUCCESS;
|
|
||||||
}),
|
|
||||||
1.0 // 攻击最多1秒
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
// 非战斗行为 - 巡逻
|
|
||||||
new MemSelector(
|
|
||||||
new Action((node) => {
|
|
||||||
console.log("巡逻点A");
|
|
||||||
return Status.SUCCESS;
|
|
||||||
}),
|
|
||||||
new Action((node) => {
|
|
||||||
console.log("巡逻点B");
|
|
||||||
return Status.SUCCESS;
|
|
||||||
}),
|
|
||||||
new Action((node) => {
|
|
||||||
console.log("巡逻点C");
|
|
||||||
return Status.SUCCESS;
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// 执行行为树
|
|
||||||
console.log("=== 执行行为树 ===");
|
|
||||||
behaviorTree.tick(); // 输出: "巡逻点A"
|
|
||||||
|
|
||||||
// 进入战斗状态
|
|
||||||
character.isInCombat = true;
|
|
||||||
character.health = 20; // 低血量
|
|
||||||
|
|
||||||
behaviorTree.tick(); // 输出: "治疗完成"
|
|
||||||
```
|
|
||||||
|
|
||||||
## 最佳实践
|
|
||||||
|
|
||||||
### 1. 节点设计原则
|
|
||||||
- **单一职责**: 每个节点只做一件事
|
|
||||||
- **状态明确**: 明确定义SUCCESS/FAILURE/RUNNING的含义
|
|
||||||
- **避免副作用**: 尽量避免节点间的隐式依赖
|
|
||||||
|
|
||||||
### 2. 性能优化
|
|
||||||
```typescript
|
|
||||||
// ✅ 好的做法 - 使用记忆节点避免重复计算
|
|
||||||
new MemSelector(
|
|
||||||
expensivePathfinding, // 复杂寻路只计算一次
|
|
||||||
fallbackBehavior
|
|
||||||
)
|
|
||||||
|
|
||||||
// ❌ 避免 - 每次都重新计算
|
|
||||||
new Selector(
|
|
||||||
expensivePathfinding, // 每次tick都会重新计算
|
|
||||||
fallbackBehavior
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 黑板使用
|
|
||||||
```typescript
|
|
||||||
// ✅ 好的做法 - 合理使用数据层级
|
|
||||||
new Action((node) => {
|
|
||||||
// 获取实体
|
|
||||||
const player = node.getEntity<Player>();
|
|
||||||
|
|
||||||
// 临时数据用本地黑板
|
|
||||||
node.set('temp_result', calculation());
|
|
||||||
|
|
||||||
// 共享数据用树级黑板
|
|
||||||
node.setRoot('current_target', target);
|
|
||||||
|
|
||||||
// 配置数据用全局黑板
|
|
||||||
node.setGlobal('game_config', config);
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. 错误处理
|
|
||||||
```typescript
|
|
||||||
// ✅ 明确的错误处理
|
|
||||||
new Action((node) => {
|
|
||||||
try {
|
|
||||||
const result = riskyOperation();
|
|
||||||
return result ? Status.SUCCESS : Status.FAILURE;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Operation failed:', error);
|
|
||||||
return Status.FAILURE;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
## 测试覆盖
|
|
||||||
|
|
||||||
本库包含全面的测试用例,覆盖:
|
|
||||||
- ✅ 17种节点类型 (100%覆盖)
|
|
||||||
- ✅ Memory节点状态管理
|
|
||||||
- ✅ 黑板数据隔离
|
|
||||||
- ✅ 边界条件处理
|
|
||||||
- ✅ 复杂嵌套场景
|
|
||||||
|
|
||||||
运行测试:
|
|
||||||
```bash
|
|
||||||
npm test
|
|
||||||
```
|
|
||||||
|
|
||||||
## API 参考
|
|
||||||
|
|
||||||
### 核心类
|
|
||||||
|
|
||||||
#### `BehaviorTree<T>`
|
|
||||||
```typescript
|
|
||||||
constructor(entity: T, root: IBTNode)
|
|
||||||
tick(): Status // 执行一次行为树
|
|
||||||
reset(): void // 重置所有状态
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `Status`
|
|
||||||
```typescript
|
|
||||||
enum Status {
|
|
||||||
SUCCESS = 0,
|
|
||||||
FAILURE = 1,
|
|
||||||
RUNNING = 2
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 节点接口
|
|
||||||
```typescript
|
|
||||||
interface IBTNode {
|
|
||||||
readonly children: IBTNode[];
|
|
||||||
// 节点黑板
|
|
||||||
local: IBlackboard;
|
|
||||||
tick(): Status;
|
|
||||||
|
|
||||||
// 优先写入自己的黑板数据, 如果没有则写入父节点的黑板数据
|
|
||||||
set<T>(key: string, value: T): void;
|
|
||||||
get<T>(key: string): T;
|
|
||||||
// 写入树根节点的黑板数据
|
|
||||||
setRoot<T>(key: string, value: T): void;
|
|
||||||
getRoot<T>(key: string): T;
|
|
||||||
// 写入全局黑板数据
|
|
||||||
setGlobal<T>(key: string, value: T): void;
|
|
||||||
getGlobal<T>(key: string): T;
|
|
||||||
|
|
||||||
// 实体访问
|
|
||||||
getEntity<T>(): T;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 许可证
|
## 许可证
|
||||||
|
|
||||||
|
|||||||
30
bt-demo/.gitignore
vendored
Normal file
30
bt-demo/.gitignore
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
#///////////////////////////
|
||||||
|
# Cocos Creator 3D Project
|
||||||
|
#///////////////////////////
|
||||||
|
library/
|
||||||
|
temp/
|
||||||
|
local/
|
||||||
|
build/
|
||||||
|
profiles/
|
||||||
|
extensions/
|
||||||
|
publish/
|
||||||
|
#//////////////////////////
|
||||||
|
# NPM
|
||||||
|
#//////////////////////////
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
#//////////////////////////
|
||||||
|
# VSCode
|
||||||
|
#//////////////////////////
|
||||||
|
.vscode/
|
||||||
|
.creator/
|
||||||
|
|
||||||
|
#//////////////////////////
|
||||||
|
# WebStorm
|
||||||
|
#//////////////////////////
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
package-lock.json
|
||||||
|
|
||||||
|
**/.DS_Store
|
||||||
10
bt-demo/README.md
Normal file
10
bt-demo/README.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# 项目说明
|
||||||
|
|
||||||
|
clone项目后,到项目根目录,执行以下命令,安装项目依赖库
|
||||||
|
```bash
|
||||||
|
npm i
|
||||||
|
```
|
||||||
|
|
||||||
|
重新用creator打开项目
|
||||||
|
|
||||||
|
本项目使用的creator版本为3.8.6
|
||||||
9
bt-demo/assets/res.meta
Normal file
9
bt-demo/assets/res.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.2.0",
|
||||||
|
"importer": "directory",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "de9afb2e-952c-4e0b-96df-cc676989bed9",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
9
bt-demo/assets/res/spine.meta
Normal file
9
bt-demo/assets/res/spine.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.2.0",
|
||||||
|
"importer": "directory",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "d5a536b5-db1b-42ac-8654-5f6a81341c3a",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
286
bt-demo/assets/res/spine/spineboy-pro.atlas
Normal file
286
bt-demo/assets/res/spine/spineboy-pro.atlas
Normal file
@@ -0,0 +1,286 @@
|
|||||||
|
|
||||||
|
spineboy-pro.png
|
||||||
|
size: 1534,529
|
||||||
|
format: RGBA8888
|
||||||
|
filter: Linear,Linear
|
||||||
|
repeat: none
|
||||||
|
crosshair
|
||||||
|
rotate: false
|
||||||
|
xy: 449, 18
|
||||||
|
size: 89, 89
|
||||||
|
orig: 89, 89
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
eye-indifferent
|
||||||
|
rotate: false
|
||||||
|
xy: 695, 10
|
||||||
|
size: 93, 89
|
||||||
|
orig: 93, 89
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
eye-surprised
|
||||||
|
rotate: true
|
||||||
|
xy: 985, 178
|
||||||
|
size: 93, 89
|
||||||
|
orig: 93, 89
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
front-bracer
|
||||||
|
rotate: true
|
||||||
|
xy: 1407, 103
|
||||||
|
size: 58, 80
|
||||||
|
orig: 58, 80
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
front-fist-closed
|
||||||
|
rotate: true
|
||||||
|
xy: 1208, 203
|
||||||
|
size: 75, 82
|
||||||
|
orig: 75, 82
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
front-fist-open
|
||||||
|
rotate: false
|
||||||
|
xy: 989, 89
|
||||||
|
size: 86, 87
|
||||||
|
orig: 86, 87
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
front-foot
|
||||||
|
rotate: false
|
||||||
|
xy: 1077, 58
|
||||||
|
size: 126, 69
|
||||||
|
orig: 126, 69
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
front-shin
|
||||||
|
rotate: true
|
||||||
|
xy: 803, 89
|
||||||
|
size: 82, 184
|
||||||
|
orig: 82, 184
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
front-thigh
|
||||||
|
rotate: true
|
||||||
|
xy: 1062, 11
|
||||||
|
size: 45, 112
|
||||||
|
orig: 45, 112
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
front-upper-arm
|
||||||
|
rotate: true
|
||||||
|
xy: 1205, 33
|
||||||
|
size: 46, 97
|
||||||
|
orig: 46, 97
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
goggles
|
||||||
|
rotate: false
|
||||||
|
xy: 540, 101
|
||||||
|
size: 261, 166
|
||||||
|
orig: 261, 166
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
gun
|
||||||
|
rotate: false
|
||||||
|
xy: 1301, 324
|
||||||
|
size: 209, 203
|
||||||
|
orig: 210, 203
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
head
|
||||||
|
rotate: false
|
||||||
|
xy: 2, 75
|
||||||
|
size: 271, 298
|
||||||
|
orig: 271, 298
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
hoverboard-board
|
||||||
|
rotate: false
|
||||||
|
xy: 2, 375
|
||||||
|
size: 492, 152
|
||||||
|
orig: 492, 152
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
hoverboard-thruster
|
||||||
|
rotate: false
|
||||||
|
xy: 1472, 38
|
||||||
|
size: 60, 63
|
||||||
|
orig: 60, 64
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
hoverglow-small
|
||||||
|
rotate: false
|
||||||
|
xy: 2, 2
|
||||||
|
size: 258, 71
|
||||||
|
orig: 274, 75
|
||||||
|
offset: 7, 2
|
||||||
|
index: -1
|
||||||
|
mouth-grind
|
||||||
|
rotate: false
|
||||||
|
xy: 1203, 142
|
||||||
|
size: 93, 59
|
||||||
|
orig: 93, 59
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
mouth-oooo
|
||||||
|
rotate: false
|
||||||
|
xy: 1205, 81
|
||||||
|
size: 93, 59
|
||||||
|
orig: 93, 59
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
mouth-smile
|
||||||
|
rotate: false
|
||||||
|
xy: 1300, 98
|
||||||
|
size: 93, 59
|
||||||
|
orig: 93, 59
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
muzzle-glow
|
||||||
|
rotate: false
|
||||||
|
xy: 496, 485
|
||||||
|
size: 42, 42
|
||||||
|
orig: 50, 50
|
||||||
|
offset: 4, 4
|
||||||
|
index: -1
|
||||||
|
muzzle-ring
|
||||||
|
rotate: true
|
||||||
|
xy: 1301, 276
|
||||||
|
size: 46, 206
|
||||||
|
orig: 49, 209
|
||||||
|
offset: 1, 2
|
||||||
|
index: -1
|
||||||
|
muzzle01
|
||||||
|
rotate: false
|
||||||
|
xy: 1077, 129
|
||||||
|
size: 124, 74
|
||||||
|
orig: 133, 79
|
||||||
|
offset: 3, 2
|
||||||
|
index: -1
|
||||||
|
muzzle02
|
||||||
|
rotate: false
|
||||||
|
xy: 934, 12
|
||||||
|
size: 126, 75
|
||||||
|
orig: 135, 84
|
||||||
|
offset: 4, 5
|
||||||
|
index: -1
|
||||||
|
muzzle03
|
||||||
|
rotate: false
|
||||||
|
xy: 540, 6
|
||||||
|
size: 153, 93
|
||||||
|
orig: 166, 106
|
||||||
|
offset: 7, 7
|
||||||
|
index: -1
|
||||||
|
muzzle04
|
||||||
|
rotate: false
|
||||||
|
xy: 790, 5
|
||||||
|
size: 142, 82
|
||||||
|
orig: 149, 90
|
||||||
|
offset: 4, 4
|
||||||
|
index: -1
|
||||||
|
muzzle05
|
||||||
|
rotate: false
|
||||||
|
xy: 1076, 205
|
||||||
|
size: 130, 73
|
||||||
|
orig: 135, 75
|
||||||
|
offset: 2, 1
|
||||||
|
index: -1
|
||||||
|
neck
|
||||||
|
rotate: false
|
||||||
|
xy: 1489, 120
|
||||||
|
size: 35, 41
|
||||||
|
orig: 36, 41
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
portal-bg
|
||||||
|
rotate: false
|
||||||
|
xy: 275, 109
|
||||||
|
size: 263, 264
|
||||||
|
orig: 266, 266
|
||||||
|
offset: 2, 1
|
||||||
|
index: -1
|
||||||
|
portal-flare1
|
||||||
|
rotate: false
|
||||||
|
xy: 1407, 163
|
||||||
|
size: 103, 54
|
||||||
|
orig: 111, 60
|
||||||
|
offset: 4, 3
|
||||||
|
index: -1
|
||||||
|
portal-flare2
|
||||||
|
rotate: false
|
||||||
|
xy: 1407, 219
|
||||||
|
size: 107, 55
|
||||||
|
orig: 114, 61
|
||||||
|
offset: 4, 3
|
||||||
|
index: -1
|
||||||
|
portal-flare3
|
||||||
|
rotate: false
|
||||||
|
xy: 1298, 159
|
||||||
|
size: 107, 53
|
||||||
|
orig: 115, 59
|
||||||
|
offset: 5, 3
|
||||||
|
index: -1
|
||||||
|
portal-shade
|
||||||
|
rotate: false
|
||||||
|
xy: 540, 269
|
||||||
|
size: 258, 258
|
||||||
|
orig: 266, 266
|
||||||
|
offset: 4, 4
|
||||||
|
index: -1
|
||||||
|
portal-streaks1
|
||||||
|
rotate: false
|
||||||
|
xy: 800, 273
|
||||||
|
size: 249, 254
|
||||||
|
orig: 252, 256
|
||||||
|
offset: 1, 1
|
||||||
|
index: -1
|
||||||
|
portal-streaks2
|
||||||
|
rotate: false
|
||||||
|
xy: 1051, 280
|
||||||
|
size: 248, 247
|
||||||
|
orig: 250, 249
|
||||||
|
offset: 1, 1
|
||||||
|
index: -1
|
||||||
|
rear-bracer
|
||||||
|
rotate: true
|
||||||
|
xy: 1400, 46
|
||||||
|
size: 55, 70
|
||||||
|
orig: 56, 72
|
||||||
|
offset: 0, 2
|
||||||
|
index: -1
|
||||||
|
rear-foot
|
||||||
|
rotate: false
|
||||||
|
xy: 1292, 214
|
||||||
|
size: 113, 60
|
||||||
|
orig: 113, 60
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
rear-shin
|
||||||
|
rotate: true
|
||||||
|
xy: 275, 33
|
||||||
|
size: 74, 172
|
||||||
|
orig: 75, 178
|
||||||
|
offset: 1, 4
|
||||||
|
index: -1
|
||||||
|
rear-thigh
|
||||||
|
rotate: true
|
||||||
|
xy: 1304, 41
|
||||||
|
size: 55, 94
|
||||||
|
orig: 55, 94
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
rear-upper-arm
|
||||||
|
rotate: false
|
||||||
|
xy: 496, 396
|
||||||
|
size: 40, 87
|
||||||
|
orig: 40, 87
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
torso
|
||||||
|
rotate: true
|
||||||
|
xy: 803, 173
|
||||||
|
size: 98, 180
|
||||||
|
orig: 98, 180
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
12
bt-demo/assets/res/spine/spineboy-pro.atlas.meta
Normal file
12
bt-demo/assets/res/spine/spineboy-pro.atlas.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.0.0",
|
||||||
|
"importer": "*",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "e6a17488-4c37-468e-bf09-a613cf272d3e",
|
||||||
|
"files": [
|
||||||
|
".atlas",
|
||||||
|
".json"
|
||||||
|
],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
4304
bt-demo/assets/res/spine/spineboy-pro.json
Normal file
4304
bt-demo/assets/res/spine/spineboy-pro.json
Normal file
File diff suppressed because it is too large
Load Diff
13
bt-demo/assets/res/spine/spineboy-pro.json.meta
Normal file
13
bt-demo/assets/res/spine/spineboy-pro.json.meta
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.2.7",
|
||||||
|
"importer": "spine-data",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "39a7d8cd-533a-479a-b909-9575bf720338",
|
||||||
|
"files": [
|
||||||
|
".json"
|
||||||
|
],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {
|
||||||
|
"atlasUuid": "e6a17488-4c37-468e-bf09-a613cf272d3e"
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
bt-demo/assets/res/spine/spineboy-pro.png
Normal file
BIN
bt-demo/assets/res/spine/spineboy-pro.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 824 KiB |
42
bt-demo/assets/res/spine/spineboy-pro.png.meta
Normal file
42
bt-demo/assets/res/spine/spineboy-pro.png.meta
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.0.27",
|
||||||
|
"importer": "image",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "74f9105a-c38b-4f5b-b7f2-f59cc6374074",
|
||||||
|
"files": [
|
||||||
|
".json",
|
||||||
|
".png"
|
||||||
|
],
|
||||||
|
"subMetas": {
|
||||||
|
"6c48a": {
|
||||||
|
"importer": "texture",
|
||||||
|
"uuid": "74f9105a-c38b-4f5b-b7f2-f59cc6374074@6c48a",
|
||||||
|
"displayName": "spineboy-pro",
|
||||||
|
"id": "6c48a",
|
||||||
|
"name": "texture",
|
||||||
|
"userData": {
|
||||||
|
"wrapModeS": "repeat",
|
||||||
|
"wrapModeT": "repeat",
|
||||||
|
"minfilter": "linear",
|
||||||
|
"magfilter": "linear",
|
||||||
|
"mipfilter": "none",
|
||||||
|
"anisotropy": 0,
|
||||||
|
"isUuid": true,
|
||||||
|
"imageUuidOrDatabaseUri": "74f9105a-c38b-4f5b-b7f2-f59cc6374074",
|
||||||
|
"visible": false
|
||||||
|
},
|
||||||
|
"ver": "1.0.22",
|
||||||
|
"imported": true,
|
||||||
|
"files": [
|
||||||
|
".json"
|
||||||
|
],
|
||||||
|
"subMetas": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"userData": {
|
||||||
|
"type": "texture",
|
||||||
|
"hasAlpha": true,
|
||||||
|
"fixAlphaTransparencyArtifacts": false,
|
||||||
|
"redirect": "74f9105a-c38b-4f5b-b7f2-f59cc6374074@6c48a"
|
||||||
|
}
|
||||||
|
}
|
||||||
14
bt-demo/assets/resources.meta
Normal file
14
bt-demo/assets/resources.meta
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.2.0",
|
||||||
|
"importer": "directory",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "9d91ce52-ffe8-43c0-a118-9ace6bd9cf45",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {
|
||||||
|
"isBundle": true,
|
||||||
|
"bundleConfigID": "default",
|
||||||
|
"bundleName": "resources",
|
||||||
|
"priority": 8
|
||||||
|
}
|
||||||
|
}
|
||||||
9
bt-demo/assets/resources/config.meta
Normal file
9
bt-demo/assets/resources/config.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.2.0",
|
||||||
|
"importer": "directory",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "1ea023b5-0ab6-4613-b157-3098b11c379b",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
148
bt-demo/assets/resources/config/bt_config.json
Normal file
148
bt-demo/assets/resources/config/bt_config.json
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
{
|
||||||
|
"bt-tree1": [
|
||||||
|
{
|
||||||
|
"id": "1759488688188_qejfcso50",
|
||||||
|
"className": "Selector",
|
||||||
|
"parameters": {},
|
||||||
|
"children": [
|
||||||
|
"1759488707759_2bmdm1fqt",
|
||||||
|
"1759488725107_v8u160t95",
|
||||||
|
"1759488737637_axpz9aqaz",
|
||||||
|
"1759482034741_cf3mqaqdj"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759479318405_bptb8ltcp",
|
||||||
|
"className": "LimitTime",
|
||||||
|
"parameters": {
|
||||||
|
"_max": 2
|
||||||
|
},
|
||||||
|
"children": [
|
||||||
|
"1758089736854_t55n54hkh"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759479295671_jflit2ek8",
|
||||||
|
"className": "LimitTime",
|
||||||
|
"parameters": {
|
||||||
|
"_max": 2
|
||||||
|
},
|
||||||
|
"children": [
|
||||||
|
"1758089659917_vjumiu9hy"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1758089659917_vjumiu9hy",
|
||||||
|
"className": "BTAnimation",
|
||||||
|
"parameters": {
|
||||||
|
"_name": "walk",
|
||||||
|
"_loop": true
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1758089736854_t55n54hkh",
|
||||||
|
"className": "BTAnimation",
|
||||||
|
"parameters": {
|
||||||
|
"_name": "run",
|
||||||
|
"_loop": true
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1758089757615_dp9tw9ka1",
|
||||||
|
"className": "BTAnimation",
|
||||||
|
"parameters": {
|
||||||
|
"_name": "jump",
|
||||||
|
"_loop": false
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759478407706_w30m4btux",
|
||||||
|
"className": "BTAnimation",
|
||||||
|
"parameters": {
|
||||||
|
"_name": "idle",
|
||||||
|
"_loop": true
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759481172259_xou25wj2n",
|
||||||
|
"className": "BTConditionRandom",
|
||||||
|
"parameters": {
|
||||||
|
"_value": 0.3
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759481282875_5orqavi5y",
|
||||||
|
"className": "BTConditionRandom",
|
||||||
|
"parameters": {
|
||||||
|
"_value": 0.4
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759481307863_ja6q4q9bz",
|
||||||
|
"className": "BTConditionRandom",
|
||||||
|
"parameters": {
|
||||||
|
"_value": 0.3
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759482034741_cf3mqaqdj",
|
||||||
|
"className": "LimitTime",
|
||||||
|
"parameters": {
|
||||||
|
"_max": 3
|
||||||
|
},
|
||||||
|
"children": [
|
||||||
|
"1759478407706_w30m4btux"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759488707759_2bmdm1fqt",
|
||||||
|
"className": "Sequence",
|
||||||
|
"parameters": {},
|
||||||
|
"children": [
|
||||||
|
"1759481172259_xou25wj2n",
|
||||||
|
"1759479295671_jflit2ek8"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759488725107_v8u160t95",
|
||||||
|
"className": "Sequence",
|
||||||
|
"parameters": {},
|
||||||
|
"children": [
|
||||||
|
"1759481282875_5orqavi5y",
|
||||||
|
"1759479318405_bptb8ltcp"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759488737637_axpz9aqaz",
|
||||||
|
"className": "Sequence",
|
||||||
|
"parameters": {},
|
||||||
|
"children": [
|
||||||
|
"1759481307863_ja6q4q9bz",
|
||||||
|
"1758089757615_dp9tw9ka1"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"bt-tree2": [
|
||||||
|
{
|
||||||
|
"id": "1757930589538_qisfksbwz",
|
||||||
|
"className": "MemSequence",
|
||||||
|
"parameters": {},
|
||||||
|
"children": [
|
||||||
|
"1758090634327_mf36nwkdt"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1758090634327_mf36nwkdt",
|
||||||
|
"className": "Selector",
|
||||||
|
"parameters": {},
|
||||||
|
"children": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
11
bt-demo/assets/resources/config/bt_config.json.meta
Normal file
11
bt-demo/assets/resources/config/bt_config.json.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"ver": "2.0.1",
|
||||||
|
"importer": "json",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "c8aeef5d-6d0e-4093-848e-7d8f1ca30261",
|
||||||
|
"files": [
|
||||||
|
".json"
|
||||||
|
],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
9
bt-demo/assets/resources/prefab.meta
Normal file
9
bt-demo/assets/resources/prefab.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.2.0",
|
||||||
|
"importer": "directory",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "6b9b2da1-08c2-4c40-ab35-e7cb5bb30872",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
147
bt-demo/assets/resources/prefab/spineboy.prefab
Normal file
147
bt-demo/assets/resources/prefab/spineboy.prefab
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"__type__": "cc.Prefab",
|
||||||
|
"_name": "spineboy",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"_native": "",
|
||||||
|
"data": {
|
||||||
|
"__id__": 1
|
||||||
|
},
|
||||||
|
"optimizationPolicy": 0,
|
||||||
|
"persistent": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.Node",
|
||||||
|
"_name": "spineboy",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"_parent": null,
|
||||||
|
"_children": [],
|
||||||
|
"_active": true,
|
||||||
|
"_components": [
|
||||||
|
{
|
||||||
|
"__id__": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 4
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"_prefab": {
|
||||||
|
"__id__": 6
|
||||||
|
},
|
||||||
|
"_lpos": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": -1000
|
||||||
|
},
|
||||||
|
"_lrot": {
|
||||||
|
"__type__": "cc.Quat",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0,
|
||||||
|
"w": 1
|
||||||
|
},
|
||||||
|
"_lscale": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 0.3,
|
||||||
|
"y": 0.3,
|
||||||
|
"z": 1
|
||||||
|
},
|
||||||
|
"_mobility": 0,
|
||||||
|
"_layer": 1073741824,
|
||||||
|
"_euler": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"_id": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.UITransform",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"node": {
|
||||||
|
"__id__": 1
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": {
|
||||||
|
"__id__": 3
|
||||||
|
},
|
||||||
|
"_contentSize": {
|
||||||
|
"__type__": "cc.Size",
|
||||||
|
"width": 419.8399963378906,
|
||||||
|
"height": 686.0800170898438
|
||||||
|
},
|
||||||
|
"_anchorPoint": {
|
||||||
|
"__type__": "cc.Vec2",
|
||||||
|
"x": 0.45412539378136013,
|
||||||
|
"y": 0.011660447470739235
|
||||||
|
},
|
||||||
|
"_id": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.CompPrefabInfo",
|
||||||
|
"fileId": "dfVeZdqm9E15k7OBD615QP"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "sp.Skeleton",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"node": {
|
||||||
|
"__id__": 1
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": {
|
||||||
|
"__id__": 5
|
||||||
|
},
|
||||||
|
"_customMaterial": null,
|
||||||
|
"_srcBlendFactor": 2,
|
||||||
|
"_dstBlendFactor": 4,
|
||||||
|
"_color": {
|
||||||
|
"__type__": "cc.Color",
|
||||||
|
"r": 255,
|
||||||
|
"g": 255,
|
||||||
|
"b": 255,
|
||||||
|
"a": 255
|
||||||
|
},
|
||||||
|
"_skeletonData": {
|
||||||
|
"__uuid__": "39a7d8cd-533a-479a-b909-9575bf720338",
|
||||||
|
"__expectedType__": "sp.SkeletonData"
|
||||||
|
},
|
||||||
|
"defaultSkin": "default",
|
||||||
|
"defaultAnimation": "jump",
|
||||||
|
"_premultipliedAlpha": true,
|
||||||
|
"_timeScale": 1,
|
||||||
|
"_preCacheMode": 0,
|
||||||
|
"_cacheMode": 0,
|
||||||
|
"_sockets": [],
|
||||||
|
"_useTint": false,
|
||||||
|
"_debugMesh": false,
|
||||||
|
"_debugBones": false,
|
||||||
|
"_debugSlots": false,
|
||||||
|
"_enableBatch": false,
|
||||||
|
"loop": true,
|
||||||
|
"_id": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.CompPrefabInfo",
|
||||||
|
"fileId": "deHPJ9jpdJZq/2PP1E2haI"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.PrefabInfo",
|
||||||
|
"root": {
|
||||||
|
"__id__": 1
|
||||||
|
},
|
||||||
|
"asset": {
|
||||||
|
"__id__": 0
|
||||||
|
},
|
||||||
|
"fileId": "fcg4LyhU9MpITaQy7lW8Ru",
|
||||||
|
"instance": null,
|
||||||
|
"targetOverrides": null
|
||||||
|
}
|
||||||
|
]
|
||||||
13
bt-demo/assets/resources/prefab/spineboy.prefab.meta
Normal file
13
bt-demo/assets/resources/prefab/spineboy.prefab.meta
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.1.50",
|
||||||
|
"importer": "prefab",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "610db270-416d-42a9-a228-67b0fe1beee4",
|
||||||
|
"files": [
|
||||||
|
".json"
|
||||||
|
],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {
|
||||||
|
"syncNodeName": "spineboy"
|
||||||
|
}
|
||||||
|
}
|
||||||
9
bt-demo/assets/scene.meta
Normal file
9
bt-demo/assets/scene.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.2.0",
|
||||||
|
"importer": "directory",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "6f3166a3-36ba-4512-bae8-889c2a7d7d98",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
726
bt-demo/assets/scene/GameEntry.scene
Normal file
726
bt-demo/assets/scene/GameEntry.scene
Normal file
@@ -0,0 +1,726 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"__type__": "cc.SceneAsset",
|
||||||
|
"_name": "GameEntry",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"_native": "",
|
||||||
|
"scene": {
|
||||||
|
"__id__": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.Scene",
|
||||||
|
"_name": "GameEntry",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"_parent": null,
|
||||||
|
"_children": [
|
||||||
|
{
|
||||||
|
"__id__": 2
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"_active": true,
|
||||||
|
"_components": [],
|
||||||
|
"_prefab": {
|
||||||
|
"__id__": 22
|
||||||
|
},
|
||||||
|
"_lpos": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"_lrot": {
|
||||||
|
"__type__": "cc.Quat",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0,
|
||||||
|
"w": 1
|
||||||
|
},
|
||||||
|
"_lscale": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 1,
|
||||||
|
"y": 1,
|
||||||
|
"z": 1
|
||||||
|
},
|
||||||
|
"_mobility": 0,
|
||||||
|
"_layer": 1073741824,
|
||||||
|
"_euler": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"autoReleaseAssets": false,
|
||||||
|
"_globals": {
|
||||||
|
"__id__": 25
|
||||||
|
},
|
||||||
|
"_id": "bef93422-3e63-4c0f-a5cf-d926e7360673"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.Node",
|
||||||
|
"_name": "Canvas",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"_parent": {
|
||||||
|
"__id__": 1
|
||||||
|
},
|
||||||
|
"_children": [
|
||||||
|
{
|
||||||
|
"__id__": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 6
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 8
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"_active": true,
|
||||||
|
"_components": [
|
||||||
|
{
|
||||||
|
"__id__": 19
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 20
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 21
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"_prefab": null,
|
||||||
|
"_lpos": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 375,
|
||||||
|
"y": 667,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"_lrot": {
|
||||||
|
"__type__": "cc.Quat",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0,
|
||||||
|
"w": 1
|
||||||
|
},
|
||||||
|
"_lscale": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 1,
|
||||||
|
"y": 1,
|
||||||
|
"z": 1
|
||||||
|
},
|
||||||
|
"_mobility": 0,
|
||||||
|
"_layer": 1073741824,
|
||||||
|
"_euler": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"_id": "beI88Z2HpFELqR4T5EMHpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.Node",
|
||||||
|
"_name": "entry",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"_parent": {
|
||||||
|
"__id__": 2
|
||||||
|
},
|
||||||
|
"_children": [],
|
||||||
|
"_active": true,
|
||||||
|
"_components": [
|
||||||
|
{
|
||||||
|
"__id__": 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 5
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"_prefab": null,
|
||||||
|
"_lpos": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 1000
|
||||||
|
},
|
||||||
|
"_lrot": {
|
||||||
|
"__type__": "cc.Quat",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0,
|
||||||
|
"w": 1
|
||||||
|
},
|
||||||
|
"_lscale": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 1,
|
||||||
|
"y": 1,
|
||||||
|
"z": 1
|
||||||
|
},
|
||||||
|
"_mobility": 0,
|
||||||
|
"_layer": 1073741824,
|
||||||
|
"_euler": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"_id": "6eSMYbFu9DJL1bKl9DnMo6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.UITransform",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"node": {
|
||||||
|
"__id__": 3
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": null,
|
||||||
|
"_contentSize": {
|
||||||
|
"__type__": "cc.Size",
|
||||||
|
"width": 100,
|
||||||
|
"height": 100
|
||||||
|
},
|
||||||
|
"_anchorPoint": {
|
||||||
|
"__type__": "cc.Vec2",
|
||||||
|
"x": 0.5,
|
||||||
|
"y": 0.5
|
||||||
|
},
|
||||||
|
"_id": "8ekQXh8+BP/6BzVmjL7OPr"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "e5804qewX9N9op0d4aH4r7B",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"node": {
|
||||||
|
"__id__": 3
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": null,
|
||||||
|
"skeleton": null,
|
||||||
|
"btConfig": {
|
||||||
|
"__uuid__": "c8aeef5d-6d0e-4093-848e-7d8f1ca30261",
|
||||||
|
"__expectedType__": "cc.JsonAsset"
|
||||||
|
},
|
||||||
|
"_id": "69LhmWaZRIUpmYvdiN82Ha"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.Node",
|
||||||
|
"_name": "Camera",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"_parent": {
|
||||||
|
"__id__": 2
|
||||||
|
},
|
||||||
|
"_children": [],
|
||||||
|
"_active": true,
|
||||||
|
"_components": [
|
||||||
|
{
|
||||||
|
"__id__": 7
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"_prefab": null,
|
||||||
|
"_lpos": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 1000
|
||||||
|
},
|
||||||
|
"_lrot": {
|
||||||
|
"__type__": "cc.Quat",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0,
|
||||||
|
"w": 1
|
||||||
|
},
|
||||||
|
"_lscale": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 1,
|
||||||
|
"y": 1,
|
||||||
|
"z": 1
|
||||||
|
},
|
||||||
|
"_mobility": 0,
|
||||||
|
"_layer": 1073741824,
|
||||||
|
"_euler": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"_id": "ebFwiq8gBFaYpqYbdoDODe"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.Camera",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"node": {
|
||||||
|
"__id__": 6
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": null,
|
||||||
|
"_projection": 0,
|
||||||
|
"_priority": 1,
|
||||||
|
"_fov": 45,
|
||||||
|
"_fovAxis": 0,
|
||||||
|
"_orthoHeight": 667,
|
||||||
|
"_near": 0,
|
||||||
|
"_far": 2000,
|
||||||
|
"_color": {
|
||||||
|
"__type__": "cc.Color",
|
||||||
|
"r": 0,
|
||||||
|
"g": 0,
|
||||||
|
"b": 0,
|
||||||
|
"a": 255
|
||||||
|
},
|
||||||
|
"_depth": 1,
|
||||||
|
"_stencil": 0,
|
||||||
|
"_clearFlags": 0,
|
||||||
|
"_rect": {
|
||||||
|
"__type__": "cc.Rect",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"width": 1,
|
||||||
|
"height": 1
|
||||||
|
},
|
||||||
|
"_aperture": 19,
|
||||||
|
"_shutter": 7,
|
||||||
|
"_iso": 0,
|
||||||
|
"_screenScale": 1,
|
||||||
|
"_visibility": 1107296259,
|
||||||
|
"_targetTexture": null,
|
||||||
|
"_postProcess": null,
|
||||||
|
"_usePostProcess": false,
|
||||||
|
"_cameraType": -1,
|
||||||
|
"_trackingType": 0,
|
||||||
|
"_id": "63WIch3o5BEYRlXzTT0oWc"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.Node",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"_parent": {
|
||||||
|
"__id__": 2
|
||||||
|
},
|
||||||
|
"_prefab": {
|
||||||
|
"__id__": 9
|
||||||
|
},
|
||||||
|
"__editorExtras__": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.PrefabInfo",
|
||||||
|
"root": {
|
||||||
|
"__id__": 8
|
||||||
|
},
|
||||||
|
"asset": {
|
||||||
|
"__uuid__": "610db270-416d-42a9-a228-67b0fe1beee4",
|
||||||
|
"__expectedType__": "cc.Prefab"
|
||||||
|
},
|
||||||
|
"fileId": "fcg4LyhU9MpITaQy7lW8Ru",
|
||||||
|
"instance": {
|
||||||
|
"__id__": 10
|
||||||
|
},
|
||||||
|
"targetOverrides": null,
|
||||||
|
"nestedPrefabInstanceRoots": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.PrefabInstance",
|
||||||
|
"fileId": "2eYzhZYv5Mi5OETcYel3W3",
|
||||||
|
"prefabRootNode": null,
|
||||||
|
"mountedChildren": [],
|
||||||
|
"mountedComponents": [],
|
||||||
|
"propertyOverrides": [
|
||||||
|
{
|
||||||
|
"__id__": 11
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 13
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 14
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 16
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 18
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"removedComponents": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "CCPropertyOverrideInfo",
|
||||||
|
"targetInfo": {
|
||||||
|
"__id__": 12
|
||||||
|
},
|
||||||
|
"propertyPath": [
|
||||||
|
"_lpos"
|
||||||
|
],
|
||||||
|
"value": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.TargetInfo",
|
||||||
|
"localID": [
|
||||||
|
"fcg4LyhU9MpITaQy7lW8Ru"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "CCPropertyOverrideInfo",
|
||||||
|
"targetInfo": {
|
||||||
|
"__id__": 12
|
||||||
|
},
|
||||||
|
"propertyPath": [
|
||||||
|
"_name"
|
||||||
|
],
|
||||||
|
"value": "spineboy"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "CCPropertyOverrideInfo",
|
||||||
|
"targetInfo": {
|
||||||
|
"__id__": 12
|
||||||
|
},
|
||||||
|
"propertyPath": [
|
||||||
|
"_lrot"
|
||||||
|
],
|
||||||
|
"value": {
|
||||||
|
"__type__": "cc.Quat",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0,
|
||||||
|
"w": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "CCPropertyOverrideInfo",
|
||||||
|
"targetInfo": {
|
||||||
|
"__id__": 12
|
||||||
|
},
|
||||||
|
"propertyPath": [
|
||||||
|
"_euler"
|
||||||
|
],
|
||||||
|
"value": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "CCPropertyOverrideInfo",
|
||||||
|
"targetInfo": {
|
||||||
|
"__id__": 17
|
||||||
|
},
|
||||||
|
"propertyPath": [
|
||||||
|
"defaultAnimation"
|
||||||
|
],
|
||||||
|
"value": "idle"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.TargetInfo",
|
||||||
|
"localID": [
|
||||||
|
"deHPJ9jpdJZq/2PP1E2haI"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "CCPropertyOverrideInfo",
|
||||||
|
"targetInfo": {
|
||||||
|
"__id__": 17
|
||||||
|
},
|
||||||
|
"propertyPath": [
|
||||||
|
"_premultipliedAlpha"
|
||||||
|
],
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.UITransform",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"node": {
|
||||||
|
"__id__": 2
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": null,
|
||||||
|
"_contentSize": {
|
||||||
|
"__type__": "cc.Size",
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"_anchorPoint": {
|
||||||
|
"__type__": "cc.Vec2",
|
||||||
|
"x": 0.5,
|
||||||
|
"y": 0.5
|
||||||
|
},
|
||||||
|
"_id": "d6rUX5yfhMlKoWX2bSbawx"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.Canvas",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"node": {
|
||||||
|
"__id__": 2
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": null,
|
||||||
|
"_cameraComponent": {
|
||||||
|
"__id__": 7
|
||||||
|
},
|
||||||
|
"_alignCanvasWithScreen": true,
|
||||||
|
"_id": "12O/ljcVlEqLmVm3U2gEOQ"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.Widget",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"node": {
|
||||||
|
"__id__": 2
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": null,
|
||||||
|
"_alignFlags": 18,
|
||||||
|
"_target": null,
|
||||||
|
"_left": 375,
|
||||||
|
"_right": 375,
|
||||||
|
"_top": 667,
|
||||||
|
"_bottom": 667,
|
||||||
|
"_horizontalCenter": 0,
|
||||||
|
"_verticalCenter": 0,
|
||||||
|
"_isAbsLeft": true,
|
||||||
|
"_isAbsRight": true,
|
||||||
|
"_isAbsTop": true,
|
||||||
|
"_isAbsBottom": true,
|
||||||
|
"_isAbsHorizontalCenter": true,
|
||||||
|
"_isAbsVerticalCenter": true,
|
||||||
|
"_originalWidth": 0,
|
||||||
|
"_originalHeight": 0,
|
||||||
|
"_alignMode": 2,
|
||||||
|
"_lockFlags": 0,
|
||||||
|
"_id": "c5V1EV8IpMtrIvY1OE9t2u"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.PrefabInfo",
|
||||||
|
"root": null,
|
||||||
|
"asset": null,
|
||||||
|
"fileId": "bef93422-3e63-4c0f-a5cf-d926e7360673",
|
||||||
|
"instance": null,
|
||||||
|
"targetOverrides": [
|
||||||
|
{
|
||||||
|
"__id__": 23
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nestedPrefabInstanceRoots": [
|
||||||
|
{
|
||||||
|
"__id__": 8
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.TargetOverrideInfo",
|
||||||
|
"source": {
|
||||||
|
"__id__": 5
|
||||||
|
},
|
||||||
|
"sourceInfo": null,
|
||||||
|
"propertyPath": [
|
||||||
|
"skeleton"
|
||||||
|
],
|
||||||
|
"target": {
|
||||||
|
"__id__": 8
|
||||||
|
},
|
||||||
|
"targetInfo": {
|
||||||
|
"__id__": 24
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.TargetInfo",
|
||||||
|
"localID": [
|
||||||
|
"deHPJ9jpdJZq/2PP1E2haI"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.SceneGlobals",
|
||||||
|
"ambient": {
|
||||||
|
"__id__": 26
|
||||||
|
},
|
||||||
|
"shadows": {
|
||||||
|
"__id__": 27
|
||||||
|
},
|
||||||
|
"_skybox": {
|
||||||
|
"__id__": 28
|
||||||
|
},
|
||||||
|
"fog": {
|
||||||
|
"__id__": 29
|
||||||
|
},
|
||||||
|
"octree": {
|
||||||
|
"__id__": 30
|
||||||
|
},
|
||||||
|
"skin": {
|
||||||
|
"__id__": 31
|
||||||
|
},
|
||||||
|
"lightProbeInfo": {
|
||||||
|
"__id__": 32
|
||||||
|
},
|
||||||
|
"postSettings": {
|
||||||
|
"__id__": 33
|
||||||
|
},
|
||||||
|
"bakedWithStationaryMainLight": false,
|
||||||
|
"bakedWithHighpLightmap": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.AmbientInfo",
|
||||||
|
"_skyColorHDR": {
|
||||||
|
"__type__": "cc.Vec4",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0,
|
||||||
|
"w": 0.520833125
|
||||||
|
},
|
||||||
|
"_skyColor": {
|
||||||
|
"__type__": "cc.Vec4",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0,
|
||||||
|
"w": 0.520833125
|
||||||
|
},
|
||||||
|
"_skyIllumHDR": 20000,
|
||||||
|
"_skyIllum": 20000,
|
||||||
|
"_groundAlbedoHDR": {
|
||||||
|
"__type__": "cc.Vec4",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0,
|
||||||
|
"w": 0
|
||||||
|
},
|
||||||
|
"_groundAlbedo": {
|
||||||
|
"__type__": "cc.Vec4",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0,
|
||||||
|
"w": 0
|
||||||
|
},
|
||||||
|
"_skyColorLDR": {
|
||||||
|
"__type__": "cc.Vec4",
|
||||||
|
"x": 0.2,
|
||||||
|
"y": 0.5,
|
||||||
|
"z": 0.8,
|
||||||
|
"w": 1
|
||||||
|
},
|
||||||
|
"_skyIllumLDR": 20000,
|
||||||
|
"_groundAlbedoLDR": {
|
||||||
|
"__type__": "cc.Vec4",
|
||||||
|
"x": 0.2,
|
||||||
|
"y": 0.2,
|
||||||
|
"z": 0.2,
|
||||||
|
"w": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.ShadowsInfo",
|
||||||
|
"_enabled": false,
|
||||||
|
"_type": 0,
|
||||||
|
"_normal": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 0,
|
||||||
|
"y": 1,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"_distance": 0,
|
||||||
|
"_planeBias": 1,
|
||||||
|
"_shadowColor": {
|
||||||
|
"__type__": "cc.Color",
|
||||||
|
"r": 76,
|
||||||
|
"g": 76,
|
||||||
|
"b": 76,
|
||||||
|
"a": 255
|
||||||
|
},
|
||||||
|
"_maxReceived": 4,
|
||||||
|
"_size": {
|
||||||
|
"__type__": "cc.Vec2",
|
||||||
|
"x": 512,
|
||||||
|
"y": 512
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.SkyboxInfo",
|
||||||
|
"_envLightingType": 0,
|
||||||
|
"_envmapHDR": null,
|
||||||
|
"_envmap": null,
|
||||||
|
"_envmapLDR": null,
|
||||||
|
"_diffuseMapHDR": null,
|
||||||
|
"_diffuseMapLDR": null,
|
||||||
|
"_enabled": false,
|
||||||
|
"_useHDR": true,
|
||||||
|
"_editableMaterial": null,
|
||||||
|
"_reflectionHDR": null,
|
||||||
|
"_reflectionLDR": null,
|
||||||
|
"_rotationAngle": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.FogInfo",
|
||||||
|
"_type": 0,
|
||||||
|
"_fogColor": {
|
||||||
|
"__type__": "cc.Color",
|
||||||
|
"r": 200,
|
||||||
|
"g": 200,
|
||||||
|
"b": 200,
|
||||||
|
"a": 255
|
||||||
|
},
|
||||||
|
"_enabled": false,
|
||||||
|
"_fogDensity": 0.3,
|
||||||
|
"_fogStart": 0.5,
|
||||||
|
"_fogEnd": 300,
|
||||||
|
"_fogAtten": 5,
|
||||||
|
"_fogTop": 1.5,
|
||||||
|
"_fogRange": 1.2,
|
||||||
|
"_accurate": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.OctreeInfo",
|
||||||
|
"_enabled": false,
|
||||||
|
"_minPos": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": -1024,
|
||||||
|
"y": -1024,
|
||||||
|
"z": -1024
|
||||||
|
},
|
||||||
|
"_maxPos": {
|
||||||
|
"__type__": "cc.Vec3",
|
||||||
|
"x": 1024,
|
||||||
|
"y": 1024,
|
||||||
|
"z": 1024
|
||||||
|
},
|
||||||
|
"_depth": 8
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.SkinInfo",
|
||||||
|
"_enabled": false,
|
||||||
|
"_blurRadius": 0.01,
|
||||||
|
"_sssIntensity": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.LightProbeInfo",
|
||||||
|
"_giScale": 1,
|
||||||
|
"_giSamples": 1024,
|
||||||
|
"_bounces": 2,
|
||||||
|
"_reduceRinging": 0,
|
||||||
|
"_showProbe": true,
|
||||||
|
"_showWireframe": true,
|
||||||
|
"_showConvex": false,
|
||||||
|
"_data": null,
|
||||||
|
"_lightProbeSphereVolume": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.PostSettingsInfo",
|
||||||
|
"_toneMappingType": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
11
bt-demo/assets/scene/GameEntry.scene.meta
Normal file
11
bt-demo/assets/scene/GameEntry.scene.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.1.50",
|
||||||
|
"importer": "scene",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "bef93422-3e63-4c0f-a5cf-d926e7360673",
|
||||||
|
"files": [
|
||||||
|
".json"
|
||||||
|
],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
9
bt-demo/assets/script.meta
Normal file
9
bt-demo/assets/script.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.2.0",
|
||||||
|
"importer": "directory",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "448b0525-daf3-4ad4-be4a-04a7e181f028",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
72
bt-demo/assets/script/BTNode.ts
Normal file
72
bt-demo/assets/script/BTNode.ts
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/**
|
||||||
|
* @Author: Gongxh
|
||||||
|
* @Date: 2025-09-17
|
||||||
|
* @Description: 定义一些行为节点
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { sp } from "cc";
|
||||||
|
import { BT } from "./Header";
|
||||||
|
|
||||||
|
@BT.ClassAction("BTAnimation", { name: "播放动画", group: "动画", desc: "通过动画名播放动画,播放完成后返回成功" })
|
||||||
|
export class BTAnimation extends BT.LeafNode {
|
||||||
|
@BT.prop({ type: BT.ParamType.string, description: "动画名" })
|
||||||
|
private _name: string = "";
|
||||||
|
|
||||||
|
@BT.prop({ type: BT.ParamType.bool, description: "是否循环" })
|
||||||
|
private _loop: boolean = false;
|
||||||
|
|
||||||
|
private _complete: boolean = false;
|
||||||
|
|
||||||
|
protected open(): void {
|
||||||
|
super.open();
|
||||||
|
this._complete = false;
|
||||||
|
|
||||||
|
console.log("open", this._name, this._loop);
|
||||||
|
|
||||||
|
let skeleton = this.getEntity<sp.Skeleton>();
|
||||||
|
skeleton.setAnimation(0, this._name, this._loop);
|
||||||
|
|
||||||
|
if (!this._loop) {
|
||||||
|
skeleton.setCompleteListener(() => {
|
||||||
|
this._complete = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public tick(): BT.Status {
|
||||||
|
if (!this._loop && this._complete) {
|
||||||
|
return BT.Status.SUCCESS;
|
||||||
|
}
|
||||||
|
return BT.Status.RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected close(): void {
|
||||||
|
super.close();
|
||||||
|
console.log("close", this._name, this._loop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 条件节点 */
|
||||||
|
@BT.ClassCondition("BTConditionRandom", { name: "随机条件节点", group: "基础条件节点", desc: "随机0-1的值,大于设置值返回成功,否则返回失败" })
|
||||||
|
export class BTConditionRandom extends BT.Condition {
|
||||||
|
|
||||||
|
@BT.prop({ type: BT.ParamType.float, description: "值", defaultValue: 0.5 })
|
||||||
|
private _value: number = 0.5;
|
||||||
|
|
||||||
|
public isEligible(): boolean {
|
||||||
|
return Math.random() > this._value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** 条件装饰节点 */
|
||||||
|
@BT.ClassDecorator("BTCondition", { name: "条件装饰节点", group: "基础装饰节点", desc: "随机0-1的值,大于设置值返回成功,否则返回失败" })
|
||||||
|
export class BTCondition extends BT.ConditionDecorator {
|
||||||
|
|
||||||
|
@BT.prop({ type: BT.ParamType.float, description: "值" })
|
||||||
|
private _value: number = 0.5;
|
||||||
|
|
||||||
|
public isEligible(): boolean {
|
||||||
|
return Math.random() > this._value;
|
||||||
|
}
|
||||||
|
}
|
||||||
9
bt-demo/assets/script/BTNode.ts.meta
Normal file
9
bt-demo/assets/script/BTNode.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.24",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "6c8cc47c-1976-432a-aa59-932cb74f41a2",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
23
bt-demo/assets/script/GameEntry.ts
Normal file
23
bt-demo/assets/script/GameEntry.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { _decorator, Component, JsonAsset, sp } from 'cc';
|
||||||
|
import { BT } from './Header';
|
||||||
|
const { ccclass, property, menu } = _decorator;
|
||||||
|
@ccclass("GameEntry")
|
||||||
|
@menu("kunpo/GameEntry")
|
||||||
|
export class GameEntry extends Component {
|
||||||
|
@property(sp.Skeleton)
|
||||||
|
private skeleton: sp.Skeleton = null;
|
||||||
|
|
||||||
|
@property(JsonAsset)
|
||||||
|
private btConfig: JsonAsset = null;
|
||||||
|
|
||||||
|
private _tree: BT.BehaviorTree<sp.Skeleton> = null;
|
||||||
|
start(): void {
|
||||||
|
console.log("btConfig", this.btConfig);
|
||||||
|
let btTree1: BT.INodeConfig[] = this.btConfig.json["bt-tree1"]
|
||||||
|
this._tree = BT.createBehaviorTree(btTree1, this.skeleton);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected update(dt: number): void {
|
||||||
|
this._tree.tick(dt);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
bt-demo/assets/script/GameEntry.ts.meta
Normal file
9
bt-demo/assets/script/GameEntry.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.24",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "e5804a9e-c17f-4df6-8a74-778687e2bec1",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
9
bt-demo/assets/script/Header.ts
Normal file
9
bt-demo/assets/script/Header.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* @Author: Gongxh
|
||||||
|
* @Date: 2025-09-17
|
||||||
|
* @Description: 头文件
|
||||||
|
*/
|
||||||
|
|
||||||
|
import * as BT from "kunpocc-behaviortree";
|
||||||
|
export { BT };
|
||||||
|
|
||||||
9
bt-demo/assets/script/Header.ts.meta
Normal file
9
bt-demo/assets/script/Header.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.24",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "17dd8d23-3e47-454a-9e47-69e371273e3b",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
73
bt-demo/assets/script/Math.ts
Normal file
73
bt-demo/assets/script/Math.ts
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
interface Math {
|
||||||
|
/**
|
||||||
|
* 限制值
|
||||||
|
* @param value 当前值
|
||||||
|
* @param min 最小值
|
||||||
|
* @param max 最大值
|
||||||
|
*/
|
||||||
|
clampf(value: number, min: number, max: number): number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机从 min 到 max 的整数(包含min和max)
|
||||||
|
* @param min
|
||||||
|
* @param max
|
||||||
|
*/
|
||||||
|
rand(min: number, max: number): number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机从 min 到 max的数
|
||||||
|
* @param min
|
||||||
|
* @param max
|
||||||
|
*/
|
||||||
|
randRange(min: number, max: number): number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角度转弧度
|
||||||
|
* @param angle 角度
|
||||||
|
*/
|
||||||
|
rad(angle: number): number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 弧度转角度
|
||||||
|
* @param radian 弧度
|
||||||
|
*/
|
||||||
|
deg(radian: number): number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数值平滑渐变
|
||||||
|
* @param num1
|
||||||
|
* @param num2
|
||||||
|
* @param elapsedTime
|
||||||
|
* @param responseTime
|
||||||
|
*/
|
||||||
|
smooth(num1: number, num2: number, elapsedTime: number, responseTime: number): number;
|
||||||
|
}
|
||||||
|
|
||||||
|
Math.clampf = function (value: number, min: number, max: number): number {
|
||||||
|
return Math.min(Math.max(value, min), max);
|
||||||
|
};
|
||||||
|
|
||||||
|
Math.rand = function (min: number, max: number): number {
|
||||||
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
||||||
|
};
|
||||||
|
|
||||||
|
Math.randRange = function (min: number, max: number): number {
|
||||||
|
return Math.random() * (max - min) + min;
|
||||||
|
};
|
||||||
|
|
||||||
|
Math.rad = function (angle: number): number {
|
||||||
|
return (angle * Math.PI) / 180;
|
||||||
|
};
|
||||||
|
|
||||||
|
Math.deg = function (radian: number): number {
|
||||||
|
return (radian * 180) / Math.PI;
|
||||||
|
};
|
||||||
|
|
||||||
|
Math.smooth = function (num1: number, num2: number, elapsedTime: number, responseTime: number): number {
|
||||||
|
let out: number = num1;
|
||||||
|
if (elapsedTime > 0) {
|
||||||
|
out = out + (num2 - num1) * (elapsedTime / (elapsedTime + responseTime));
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
};
|
||||||
|
|
||||||
9
bt-demo/assets/script/Math.ts.meta
Normal file
9
bt-demo/assets/script/Math.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.24",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "a336ce23-5d73-4280-b2e9-084389a3877e",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
1
bt-demo/extensions-config/.gitignore
vendored
Normal file
1
bt-demo/extensions-config/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
local/
|
||||||
302
bt-demo/extensions-config/bt-editor/bt-tree1.json
Normal file
302
bt-demo/extensions-config/bt-editor/bt-tree1.json
Normal file
@@ -0,0 +1,302 @@
|
|||||||
|
{
|
||||||
|
"name": "bt-tree1",
|
||||||
|
"description": "",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"id": "1759488688188_qejfcso50",
|
||||||
|
"className": "Selector",
|
||||||
|
"name": "选择节点",
|
||||||
|
"position": {
|
||||||
|
"x": -60,
|
||||||
|
"y": -200
|
||||||
|
},
|
||||||
|
"parameters": {},
|
||||||
|
"children": [
|
||||||
|
"1759488707759_2bmdm1fqt",
|
||||||
|
"1759488725107_v8u160t95",
|
||||||
|
"1759488737637_axpz9aqaz",
|
||||||
|
"1759482034741_cf3mqaqdj"
|
||||||
|
],
|
||||||
|
"alias": "根节点"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759479318405_bptb8ltcp",
|
||||||
|
"className": "LimitTime",
|
||||||
|
"name": "时间限制器",
|
||||||
|
"position": {
|
||||||
|
"x": -40,
|
||||||
|
"y": 40
|
||||||
|
},
|
||||||
|
"parameters": {
|
||||||
|
"_max": 2
|
||||||
|
},
|
||||||
|
"children": [
|
||||||
|
"1758089736854_t55n54hkh"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759479295671_jflit2ek8",
|
||||||
|
"className": "LimitTime",
|
||||||
|
"name": "时间限制器",
|
||||||
|
"position": {
|
||||||
|
"x": -360,
|
||||||
|
"y": 40
|
||||||
|
},
|
||||||
|
"parameters": {
|
||||||
|
"_max": 2
|
||||||
|
},
|
||||||
|
"children": [
|
||||||
|
"1758089659917_vjumiu9hy"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1758089659917_vjumiu9hy",
|
||||||
|
"className": "BTAnimation",
|
||||||
|
"name": "播放动画",
|
||||||
|
"position": {
|
||||||
|
"x": -360,
|
||||||
|
"y": 160
|
||||||
|
},
|
||||||
|
"parameters": {
|
||||||
|
"_name": "walk",
|
||||||
|
"_loop": true
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1758089736854_t55n54hkh",
|
||||||
|
"className": "BTAnimation",
|
||||||
|
"name": "播放动画",
|
||||||
|
"position": {
|
||||||
|
"x": -40,
|
||||||
|
"y": 160
|
||||||
|
},
|
||||||
|
"parameters": {
|
||||||
|
"_name": "run",
|
||||||
|
"_loop": true
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1758089757615_dp9tw9ka1",
|
||||||
|
"className": "BTAnimation",
|
||||||
|
"name": "播放动画",
|
||||||
|
"position": {
|
||||||
|
"x": 260,
|
||||||
|
"y": 40
|
||||||
|
},
|
||||||
|
"parameters": {
|
||||||
|
"_name": "jump",
|
||||||
|
"_loop": false
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759478407706_w30m4btux",
|
||||||
|
"className": "BTAnimation",
|
||||||
|
"name": "播放动画",
|
||||||
|
"position": {
|
||||||
|
"x": 420,
|
||||||
|
"y": 40
|
||||||
|
},
|
||||||
|
"parameters": {
|
||||||
|
"_name": "idle",
|
||||||
|
"_loop": true
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759481172259_xou25wj2n",
|
||||||
|
"className": "BTConditionRandom",
|
||||||
|
"name": "随机条件节点",
|
||||||
|
"position": {
|
||||||
|
"x": -520,
|
||||||
|
"y": 40
|
||||||
|
},
|
||||||
|
"parameters": {
|
||||||
|
"_value": 0.3
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759481282875_5orqavi5y",
|
||||||
|
"className": "BTConditionRandom",
|
||||||
|
"name": "随机条件节点",
|
||||||
|
"position": {
|
||||||
|
"x": -200,
|
||||||
|
"y": 40
|
||||||
|
},
|
||||||
|
"parameters": {
|
||||||
|
"_value": 0.4
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759481307863_ja6q4q9bz",
|
||||||
|
"className": "BTConditionRandom",
|
||||||
|
"name": "随机条件节点",
|
||||||
|
"position": {
|
||||||
|
"x": 120,
|
||||||
|
"y": 40
|
||||||
|
},
|
||||||
|
"parameters": {
|
||||||
|
"_value": 0.3
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759482034741_cf3mqaqdj",
|
||||||
|
"className": "LimitTime",
|
||||||
|
"name": "时间限制器",
|
||||||
|
"position": {
|
||||||
|
"x": 420,
|
||||||
|
"y": -80
|
||||||
|
},
|
||||||
|
"parameters": {
|
||||||
|
"_max": 3
|
||||||
|
},
|
||||||
|
"children": [
|
||||||
|
"1759478407706_w30m4btux"
|
||||||
|
],
|
||||||
|
"alias": "待机动画"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759488707759_2bmdm1fqt",
|
||||||
|
"className": "Sequence",
|
||||||
|
"name": "顺序节点",
|
||||||
|
"position": {
|
||||||
|
"x": -440,
|
||||||
|
"y": -80
|
||||||
|
},
|
||||||
|
"parameters": {},
|
||||||
|
"children": [
|
||||||
|
"1759481172259_xou25wj2n",
|
||||||
|
"1759479295671_jflit2ek8"
|
||||||
|
],
|
||||||
|
"alias": "行走动画分支"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759488725107_v8u160t95",
|
||||||
|
"className": "Sequence",
|
||||||
|
"name": "顺序节点",
|
||||||
|
"position": {
|
||||||
|
"x": -120,
|
||||||
|
"y": -80
|
||||||
|
},
|
||||||
|
"parameters": {},
|
||||||
|
"children": [
|
||||||
|
"1759481282875_5orqavi5y",
|
||||||
|
"1759479318405_bptb8ltcp"
|
||||||
|
],
|
||||||
|
"alias": "奔跑动画分支"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1759488737637_axpz9aqaz",
|
||||||
|
"className": "Sequence",
|
||||||
|
"name": "顺序节点",
|
||||||
|
"position": {
|
||||||
|
"x": 180,
|
||||||
|
"y": -80
|
||||||
|
},
|
||||||
|
"parameters": {},
|
||||||
|
"children": [
|
||||||
|
"1759481307863_ja6q4q9bz",
|
||||||
|
"1758089757615_dp9tw9ka1"
|
||||||
|
],
|
||||||
|
"alias": "跳跃动画分支"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"connections": [
|
||||||
|
{
|
||||||
|
"id": "conn_1759479306749_wnwlz1638",
|
||||||
|
"sourceNodeId": "1759479295671_jflit2ek8",
|
||||||
|
"targetNodeId": "1758089659917_vjumiu9hy",
|
||||||
|
"sourcePointType": "child",
|
||||||
|
"targetPointType": "parent"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "conn_1759479325803_ln42r7198",
|
||||||
|
"sourceNodeId": "1759479318405_bptb8ltcp",
|
||||||
|
"targetNodeId": "1758089736854_t55n54hkh",
|
||||||
|
"sourcePointType": "child",
|
||||||
|
"targetPointType": "parent"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "conn_1759482041141_ok8gnqp0o",
|
||||||
|
"sourceNodeId": "1759482034741_cf3mqaqdj",
|
||||||
|
"targetNodeId": "1759478407706_w30m4btux",
|
||||||
|
"sourcePointType": "child",
|
||||||
|
"targetPointType": "parent"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "conn_1759488698126_dou7vxvo0",
|
||||||
|
"sourceNodeId": "1759488688188_qejfcso50",
|
||||||
|
"targetNodeId": "1759482034741_cf3mqaqdj",
|
||||||
|
"sourcePointType": "child",
|
||||||
|
"targetPointType": "parent"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "conn_1759488712210_gn0eom3zv",
|
||||||
|
"sourceNodeId": "1759488688188_qejfcso50",
|
||||||
|
"targetNodeId": "1759488707759_2bmdm1fqt",
|
||||||
|
"sourcePointType": "child",
|
||||||
|
"targetPointType": "parent"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "conn_1759488719553_mag45k9dx",
|
||||||
|
"sourceNodeId": "1759488707759_2bmdm1fqt",
|
||||||
|
"targetNodeId": "1759481172259_xou25wj2n",
|
||||||
|
"sourcePointType": "child",
|
||||||
|
"targetPointType": "parent"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "conn_1759488720799_ksfwij12z",
|
||||||
|
"sourceNodeId": "1759488707759_2bmdm1fqt",
|
||||||
|
"targetNodeId": "1759479295671_jflit2ek8",
|
||||||
|
"sourcePointType": "child",
|
||||||
|
"targetPointType": "parent"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "conn_1759488728262_shaymep9m",
|
||||||
|
"sourceNodeId": "1759488688188_qejfcso50",
|
||||||
|
"targetNodeId": "1759488725107_v8u160t95",
|
||||||
|
"sourcePointType": "child",
|
||||||
|
"targetPointType": "parent"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "conn_1759488732106_yg23eiw3l",
|
||||||
|
"sourceNodeId": "1759488725107_v8u160t95",
|
||||||
|
"targetNodeId": "1759481282875_5orqavi5y",
|
||||||
|
"sourcePointType": "child",
|
||||||
|
"targetPointType": "parent"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "conn_1759488733833_08kf67zp1",
|
||||||
|
"sourceNodeId": "1759488725107_v8u160t95",
|
||||||
|
"targetNodeId": "1759479318405_bptb8ltcp",
|
||||||
|
"sourcePointType": "child",
|
||||||
|
"targetPointType": "parent"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "conn_1759488741448_2in7yz3v7",
|
||||||
|
"sourceNodeId": "1759488688188_qejfcso50",
|
||||||
|
"targetNodeId": "1759488737637_axpz9aqaz",
|
||||||
|
"sourcePointType": "child",
|
||||||
|
"targetPointType": "parent"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "conn_1759488742689_15z7fchvc",
|
||||||
|
"sourceNodeId": "1759488737637_axpz9aqaz",
|
||||||
|
"targetNodeId": "1759481307863_ja6q4q9bz",
|
||||||
|
"sourcePointType": "child",
|
||||||
|
"targetPointType": "parent"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "conn_1759488745870_5rllaj2oe",
|
||||||
|
"sourceNodeId": "1759488737637_axpz9aqaz",
|
||||||
|
"targetNodeId": "1758089757615_dp9tw9ka1",
|
||||||
|
"sourcePointType": "child",
|
||||||
|
"targetPointType": "parent"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
39
bt-demo/extensions-config/bt-editor/bt-tree2.json
Normal file
39
bt-demo/extensions-config/bt-editor/bt-tree2.json
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"name": "bt-tree2",
|
||||||
|
"description": "",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"id": "1757930589538_qisfksbwz",
|
||||||
|
"className": "MemSequence",
|
||||||
|
"name": "记忆顺序节点",
|
||||||
|
"position": {
|
||||||
|
"x": -60,
|
||||||
|
"y": -280
|
||||||
|
},
|
||||||
|
"parameters": {},
|
||||||
|
"children": [
|
||||||
|
"1758090634327_mf36nwkdt"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1758090634327_mf36nwkdt",
|
||||||
|
"className": "Selector",
|
||||||
|
"name": "选择节点",
|
||||||
|
"position": {
|
||||||
|
"x": 20,
|
||||||
|
"y": -80
|
||||||
|
},
|
||||||
|
"parameters": {},
|
||||||
|
"children": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"connections": [
|
||||||
|
{
|
||||||
|
"id": "conn_1758090635620_zajj5r8g0",
|
||||||
|
"sourceNodeId": "1757930589538_qisfksbwz",
|
||||||
|
"targetNodeId": "1758090634327_mf36nwkdt",
|
||||||
|
"sourcePointType": "child",
|
||||||
|
"targetPointType": "parent"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
11
bt-demo/package.json
Executable file
11
bt-demo/package.json
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "kunpocreator",
|
||||||
|
"uuid": "f5d24040-9cd4-4a5a-8559-38bf55e621f7",
|
||||||
|
"creator": {
|
||||||
|
"version": "3.8.6"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"kunpocc-behaviortree": "^0.1.0",
|
||||||
|
"ts-node": "^10.9.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
80
bt-demo/settings/v2/packages/builder.json
Normal file
80
bt-demo/settings/v2/packages/builder.json
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
{
|
||||||
|
"__version__": "1.3.9",
|
||||||
|
"bundleConfig": {
|
||||||
|
"custom": {
|
||||||
|
"default": {
|
||||||
|
"displayName": "i18n:builder.asset_bundle.defaultConfig",
|
||||||
|
"configs": {
|
||||||
|
"native": {
|
||||||
|
"preferredOptions": {
|
||||||
|
"isRemote": false,
|
||||||
|
"compressionType": "merge_all_json"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"web": {
|
||||||
|
"preferredOptions": {
|
||||||
|
"isRemote": false,
|
||||||
|
"compressionType": "merge_dep"
|
||||||
|
},
|
||||||
|
"fallbackOptions": {
|
||||||
|
"compressionType": "merge_dep"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"miniGame": {
|
||||||
|
"fallbackOptions": {
|
||||||
|
"isRemote": true,
|
||||||
|
"compressionType": "merge_all_json"
|
||||||
|
},
|
||||||
|
"configMode": "fallback",
|
||||||
|
"overwriteSettings": {
|
||||||
|
"alipay-mini-game": {
|
||||||
|
"isRemote": true,
|
||||||
|
"compressionType": "merge_all_json"
|
||||||
|
},
|
||||||
|
"bytedance-mini-game": {
|
||||||
|
"isRemote": true,
|
||||||
|
"compressionType": "merge_all_json"
|
||||||
|
},
|
||||||
|
"fb-instant-games": {
|
||||||
|
"isRemote": true,
|
||||||
|
"compressionType": "merge_all_json"
|
||||||
|
},
|
||||||
|
"huawei-quick-game": {
|
||||||
|
"isRemote": true,
|
||||||
|
"compressionType": "merge_all_json"
|
||||||
|
},
|
||||||
|
"migu-mini-game": {
|
||||||
|
"isRemote": false,
|
||||||
|
"compressionType": "merge_all_json"
|
||||||
|
},
|
||||||
|
"oppo-mini-game": {
|
||||||
|
"isRemote": true,
|
||||||
|
"compressionType": "merge_all_json"
|
||||||
|
},
|
||||||
|
"taobao-mini-game": {
|
||||||
|
"isRemote": true,
|
||||||
|
"compressionType": "merge_all_json"
|
||||||
|
},
|
||||||
|
"vivo-mini-game": {
|
||||||
|
"isRemote": true,
|
||||||
|
"compressionType": "merge_all_json"
|
||||||
|
},
|
||||||
|
"wechatgame": {
|
||||||
|
"isRemote": true,
|
||||||
|
"compressionType": "merge_all_json"
|
||||||
|
},
|
||||||
|
"xiaomi-quick-game": {
|
||||||
|
"isRemote": true,
|
||||||
|
"compressionType": "merge_all_json"
|
||||||
|
},
|
||||||
|
"taobao-creative-app": {
|
||||||
|
"isRemote": true,
|
||||||
|
"compressionType": "merge_all_json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
23
bt-demo/settings/v2/packages/cocos-service.json
Normal file
23
bt-demo/settings/v2/packages/cocos-service.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"__version__": "3.0.9",
|
||||||
|
"game": {
|
||||||
|
"name": "未知游戏",
|
||||||
|
"app_id": "UNKNOW",
|
||||||
|
"c_id": "0"
|
||||||
|
},
|
||||||
|
"appConfigMaps": [
|
||||||
|
{
|
||||||
|
"app_id": "UNKNOW",
|
||||||
|
"config_id": "8c18cb"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"configs": [
|
||||||
|
{
|
||||||
|
"app_id": "UNKNOW",
|
||||||
|
"config_id": "8c18cb",
|
||||||
|
"config_name": "Default",
|
||||||
|
"config_remarks": "",
|
||||||
|
"services": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
3
bt-demo/settings/v2/packages/device.json
Normal file
3
bt-demo/settings/v2/packages/device.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"__version__": "1.0.1"
|
||||||
|
}
|
||||||
451
bt-demo/settings/v2/packages/engine.json
Normal file
451
bt-demo/settings/v2/packages/engine.json
Normal file
@@ -0,0 +1,451 @@
|
|||||||
|
{
|
||||||
|
"__version__": "1.0.12",
|
||||||
|
"modules": {
|
||||||
|
"graphics": {
|
||||||
|
"pipeline": "legacy-pipeline"
|
||||||
|
},
|
||||||
|
"configs": {
|
||||||
|
"migrationsConfig": {
|
||||||
|
"cache": {
|
||||||
|
"base": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"gfx-webgl": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"gfx-webgl2": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"gfx-webgpu": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"animation": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"skeletal-animation": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"3d": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"meshopt": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"2d": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"xr": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"rich-text": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"mask": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"graphics": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"ui-skew": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"affine-transform": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"ui": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"particle": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"physics": {
|
||||||
|
"_value": false,
|
||||||
|
"_option": "physics-ammo"
|
||||||
|
},
|
||||||
|
"physics-ammo": {
|
||||||
|
"_value": false,
|
||||||
|
"_flags": {
|
||||||
|
"LOAD_BULLET_MANUALLY": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"physics-cannon": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"physics-physx": {
|
||||||
|
"_value": false,
|
||||||
|
"_flags": {
|
||||||
|
"LOAD_PHYSX_MANUALLY": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"physics-builtin": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"physics-2d": {
|
||||||
|
"_value": true,
|
||||||
|
"_option": "physics-2d-builtin"
|
||||||
|
},
|
||||||
|
"physics-2d-box2d": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"physics-2d-box2d-wasm": {
|
||||||
|
"_value": false,
|
||||||
|
"_flags": {
|
||||||
|
"LOAD_BOX2D_MANUALLY": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"physics-2d-builtin": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"physics-2d-box2d-jsb": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"intersection-2d": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"primitive": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"profiler": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"occlusion-query": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"geometry-renderer": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"debug-renderer": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"particle-2d": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"audio": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"video": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"webview": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"tween": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"websocket": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"websocket-server": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"terrain": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"light-probe": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"tiled-map": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"vendor-google": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"spine": {
|
||||||
|
"_value": true,
|
||||||
|
"_option": "spine-3.8"
|
||||||
|
},
|
||||||
|
"spine-3.8": {
|
||||||
|
"_value": true,
|
||||||
|
"_flags": {
|
||||||
|
"LOAD_SPINE_MANUALLY": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"spine-4.2": {
|
||||||
|
"_value": false,
|
||||||
|
"_flags": {
|
||||||
|
"LOAD_SPINE_MANUALLY": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dragon-bones": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"marionette": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"procedural-animation": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"custom-pipeline-post-process": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"render-pipeline": {
|
||||||
|
"_value": true,
|
||||||
|
"_option": "legacy-pipeline"
|
||||||
|
},
|
||||||
|
"custom-pipeline": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"legacy-pipeline": {
|
||||||
|
"_value": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flags": {
|
||||||
|
"LOAD_SPINE_MANUALLY": false
|
||||||
|
},
|
||||||
|
"name": "迁移生成的配置",
|
||||||
|
"includeModules": [
|
||||||
|
"2d",
|
||||||
|
"affine-transform",
|
||||||
|
"animation",
|
||||||
|
"audio",
|
||||||
|
"base",
|
||||||
|
"gfx-webgl",
|
||||||
|
"gfx-webgl2",
|
||||||
|
"graphics",
|
||||||
|
"intersection-2d",
|
||||||
|
"legacy-pipeline",
|
||||||
|
"marionette",
|
||||||
|
"mask",
|
||||||
|
"particle-2d",
|
||||||
|
"physics-2d-builtin",
|
||||||
|
"procedural-animation",
|
||||||
|
"profiler",
|
||||||
|
"rich-text",
|
||||||
|
"skeletal-animation",
|
||||||
|
"spine-3.8",
|
||||||
|
"tween",
|
||||||
|
"ui",
|
||||||
|
"video",
|
||||||
|
"websocket",
|
||||||
|
"webview"
|
||||||
|
],
|
||||||
|
"noDeprecatedFeatures": {
|
||||||
|
"value": true,
|
||||||
|
"version": "<=3.8.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultConfig": {
|
||||||
|
"name": "默认配置",
|
||||||
|
"cache": {
|
||||||
|
"base": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"gfx-webgl": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"gfx-webgl2": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"gfx-webgpu": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"animation": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"skeletal-animation": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"3d": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"meshopt": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"2d": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"xr": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"rich-text": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"mask": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"graphics": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"ui-skew": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"affine-transform": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"ui": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"particle": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"physics": {
|
||||||
|
"_value": false,
|
||||||
|
"_option": "physics-ammo"
|
||||||
|
},
|
||||||
|
"physics-ammo": {
|
||||||
|
"_value": true,
|
||||||
|
"_flags": {
|
||||||
|
"LOAD_BULLET_MANUALLY": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"physics-cannon": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"physics-physx": {
|
||||||
|
"_value": false,
|
||||||
|
"_flags": {
|
||||||
|
"LOAD_PHYSX_MANUALLY": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"physics-builtin": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"physics-2d": {
|
||||||
|
"_value": true,
|
||||||
|
"_option": "physics-2d-builtin"
|
||||||
|
},
|
||||||
|
"physics-2d-box2d": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"physics-2d-box2d-wasm": {
|
||||||
|
"_value": false,
|
||||||
|
"_flags": {
|
||||||
|
"LOAD_BOX2D_MANUALLY": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"physics-2d-builtin": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"physics-2d-box2d-jsb": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"intersection-2d": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"primitive": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"profiler": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"occlusion-query": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"geometry-renderer": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"debug-renderer": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"particle-2d": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"audio": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"video": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"webview": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"tween": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"websocket": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"websocket-server": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"terrain": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"light-probe": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"tiled-map": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"vendor-google": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"spine": {
|
||||||
|
"_value": true,
|
||||||
|
"_option": "spine-3.8"
|
||||||
|
},
|
||||||
|
"spine-3.8": {
|
||||||
|
"_value": true,
|
||||||
|
"_flags": {
|
||||||
|
"LOAD_SPINE_MANUALLY": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"spine-4.2": {
|
||||||
|
"_value": false,
|
||||||
|
"_flags": {
|
||||||
|
"LOAD_SPINE_MANUALLY": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dragon-bones": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"marionette": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"procedural-animation": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"custom-pipeline-post-process": {
|
||||||
|
"_value": false
|
||||||
|
},
|
||||||
|
"render-pipeline": {
|
||||||
|
"_value": true,
|
||||||
|
"_option": "custom-pipeline"
|
||||||
|
},
|
||||||
|
"custom-pipeline": {
|
||||||
|
"_value": true
|
||||||
|
},
|
||||||
|
"legacy-pipeline": {
|
||||||
|
"_value": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flags": {
|
||||||
|
"LOAD_SPINE_MANUALLY": false
|
||||||
|
},
|
||||||
|
"includeModules": [
|
||||||
|
"2d",
|
||||||
|
"affine-transform",
|
||||||
|
"animation",
|
||||||
|
"audio",
|
||||||
|
"base",
|
||||||
|
"custom-pipeline",
|
||||||
|
"gfx-webgl",
|
||||||
|
"graphics",
|
||||||
|
"intersection-2d",
|
||||||
|
"marionette",
|
||||||
|
"mask",
|
||||||
|
"particle-2d",
|
||||||
|
"physics-2d-builtin",
|
||||||
|
"procedural-animation",
|
||||||
|
"profiler",
|
||||||
|
"rich-text",
|
||||||
|
"skeletal-animation",
|
||||||
|
"spine-3.8",
|
||||||
|
"tween",
|
||||||
|
"ui",
|
||||||
|
"video",
|
||||||
|
"websocket",
|
||||||
|
"webview"
|
||||||
|
],
|
||||||
|
"noDeprecatedFeatures": {
|
||||||
|
"value": true,
|
||||||
|
"version": "<=3.8.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"globalConfigKey": "defaultConfig"
|
||||||
|
},
|
||||||
|
"macroConfig": {
|
||||||
|
"BATCHER2D_MEM_INCREMENT": 288
|
||||||
|
}
|
||||||
|
}
|
||||||
23
bt-demo/settings/v2/packages/information.json
Normal file
23
bt-demo/settings/v2/packages/information.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"__version__": "1.0.1",
|
||||||
|
"information": {
|
||||||
|
"customSplash": {
|
||||||
|
"id": "customSplash",
|
||||||
|
"label": "customSplash",
|
||||||
|
"enable": false,
|
||||||
|
"customSplash": {
|
||||||
|
"complete": false,
|
||||||
|
"form": "https://creator-api.cocos.com/api/form/show?"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"removeSplash": {
|
||||||
|
"id": "removeSplash",
|
||||||
|
"label": "removeSplash",
|
||||||
|
"enable": false,
|
||||||
|
"removeSplash": {
|
||||||
|
"complete": false,
|
||||||
|
"form": "https://creator-api.cocos.com/api/form/show?"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
bt-demo/settings/v2/packages/ios.json
Normal file
11
bt-demo/settings/v2/packages/ios.json
Normal file
File diff suppressed because one or more lines are too long
3
bt-demo/settings/v2/packages/program.json
Normal file
3
bt-demo/settings/v2/packages/program.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"__version__": "1.0.4"
|
||||||
|
}
|
||||||
29
bt-demo/settings/v2/packages/project.json
Normal file
29
bt-demo/settings/v2/packages/project.json
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"__version__": "1.0.6",
|
||||||
|
"general": {
|
||||||
|
"designResolution": {
|
||||||
|
"height": 1334,
|
||||||
|
"width": 750,
|
||||||
|
"fitHeight": true
|
||||||
|
},
|
||||||
|
"highQuality": false
|
||||||
|
},
|
||||||
|
"custom_joint_texture_layouts": [],
|
||||||
|
"script": {
|
||||||
|
"preserveSymlinks": true
|
||||||
|
},
|
||||||
|
"layer": [
|
||||||
|
{
|
||||||
|
"name": "Window",
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Game",
|
||||||
|
"value": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Graphics",
|
||||||
|
"value": 4
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
4
bt-demo/settings/v2/packages/scene.json
Normal file
4
bt-demo/settings/v2/packages/scene.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"__version__": "1.0.3",
|
||||||
|
"current-scene": "bef93422-3e63-4c0f-a5cf-d926e7360673"
|
||||||
|
}
|
||||||
10
bt-demo/tsconfig.json
Normal file
10
bt-demo/tsconfig.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
/* Base configuration. Do not edit this field. */
|
||||||
|
"extends": "./temp/tsconfig.cocos.json",
|
||||||
|
/* Add your custom configuration here. */
|
||||||
|
"compilerOptions": {
|
||||||
|
"strict": false,
|
||||||
|
"module": "ES6",
|
||||||
|
"target": "ES6"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "kunpocc-behaviortree",
|
"name": "kunpocc-behaviortree",
|
||||||
"version": "0.0.6",
|
"version": "0.1.0",
|
||||||
"description": "行为树",
|
"description": "行为树",
|
||||||
"main": "./dist/kunpocc-behaviortree.cjs",
|
"main": "./dist/kunpocc-behaviortree.cjs",
|
||||||
"module": "./dist/kunpocc-behaviortree.mjs",
|
"module": "./dist/kunpocc-behaviortree.mjs",
|
||||||
@@ -19,7 +19,8 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rm -rf dist",
|
"clean": "rm -rf dist",
|
||||||
"build": "npm run clean && rollup -c rollup.config.mjs"
|
"copy": "cp -r dist/* ./bt-demo/node_modules/kunpocc-behaviortree/dist/",
|
||||||
|
"build": "npm run clean && rollup -c rollup.config.mjs && npm run copy"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist/kunpocc-behaviortree.cjs",
|
"dist/kunpocc-behaviortree.cjs",
|
||||||
|
|||||||
216
src/behaviortree/BT.ts
Normal file
216
src/behaviortree/BT.ts
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
/**
|
||||||
|
* 行为树装饰器和元数据管理
|
||||||
|
* 用于编辑器显示和配置节点信息
|
||||||
|
*/
|
||||||
|
|
||||||
|
export namespace BT {
|
||||||
|
/**
|
||||||
|
* 参数类型枚举
|
||||||
|
*/
|
||||||
|
export enum ParamType {
|
||||||
|
int = "number",
|
||||||
|
float = "float",
|
||||||
|
string = "string",
|
||||||
|
bool = "boolean"
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点类型枚举
|
||||||
|
*/
|
||||||
|
export enum Type {
|
||||||
|
/** 行为节点 */
|
||||||
|
Action = "action",
|
||||||
|
/** 条件节点 */
|
||||||
|
Condition = "condition",
|
||||||
|
/** 组合节点 */
|
||||||
|
Composite = "composite",
|
||||||
|
/** 装饰节点 */
|
||||||
|
Decorator = "decorator"
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数描述接口
|
||||||
|
*/
|
||||||
|
export interface ParameterInfo {
|
||||||
|
/** 参数名称 */
|
||||||
|
name: string;
|
||||||
|
/** 参数类型 */
|
||||||
|
type: ParamType;
|
||||||
|
/** 参数描述 */
|
||||||
|
description?: string;
|
||||||
|
/** 默认值 */
|
||||||
|
defaultValue?: any;
|
||||||
|
/** 步进 针对数字类型的变更的最小单位 */
|
||||||
|
step?: number,
|
||||||
|
/** 最小值 */
|
||||||
|
min?: number,
|
||||||
|
/** 最大值 */
|
||||||
|
max?: number,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点元数据接口
|
||||||
|
*/
|
||||||
|
export interface NodeMetadata {
|
||||||
|
/** 节点名称 */
|
||||||
|
name: string;
|
||||||
|
/** 节点类名 */
|
||||||
|
className: string;
|
||||||
|
/** 节点分组 */
|
||||||
|
group: string;
|
||||||
|
/** 节点类型 */
|
||||||
|
type: Type;
|
||||||
|
/** 节点描述 */
|
||||||
|
description: string;
|
||||||
|
/** 参数列表 */
|
||||||
|
parameters: ParameterInfo[];
|
||||||
|
/** 最大子节点数量:0=不允许子节点,1=最多一个子节点,-1=无限制 */
|
||||||
|
maxChildren: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册节点名 到 节点构造函数的映射
|
||||||
|
*/
|
||||||
|
const NODE_NAME_TO_CONSTRUCTOR_MAP = new Map<string, any>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点元数据存储
|
||||||
|
*/
|
||||||
|
const NODE_METADATA_MAP = new Map<any, NodeMetadata>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点参数存储
|
||||||
|
*/
|
||||||
|
const NODE_PARAMETERS_MAP = new Map<any, ParameterInfo[]>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点属性装饰器
|
||||||
|
*/
|
||||||
|
export function prop(paramInfo: Omit<ParameterInfo, "name">) {
|
||||||
|
return function (target: any, propertyKey: string) {
|
||||||
|
const ctor = target.constructor;
|
||||||
|
if (!NODE_PARAMETERS_MAP.has(ctor)) {
|
||||||
|
NODE_PARAMETERS_MAP.set(ctor, []);
|
||||||
|
}
|
||||||
|
const parameters = NODE_PARAMETERS_MAP.get(ctor)!;
|
||||||
|
parameters.push({
|
||||||
|
...paramInfo,
|
||||||
|
name: propertyKey
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 行为节点装饰器
|
||||||
|
* @param name 节点的类名 编辑器导出数据中的节点名字
|
||||||
|
* @param info.group 节点在编辑器中的分组
|
||||||
|
* @param info.name 节点在编辑器中的中文名
|
||||||
|
* @param info.desc 节点描述信息
|
||||||
|
*/
|
||||||
|
export function ClassAction(name: string, info?: { group?: string, name?: string, desc?: string }) {
|
||||||
|
return function <T extends new (...args: any[]) => any>(constructor: T) {
|
||||||
|
const parameters = NODE_PARAMETERS_MAP.get(constructor) || [];
|
||||||
|
const fullMetadata: NodeMetadata = {
|
||||||
|
className: name,
|
||||||
|
group: info?.group || '未分组',
|
||||||
|
name: info?.name || '',
|
||||||
|
description: info?.desc || '',
|
||||||
|
type: Type.Action,
|
||||||
|
maxChildren: 0,
|
||||||
|
parameters
|
||||||
|
};
|
||||||
|
NODE_METADATA_MAP.set(constructor, fullMetadata);
|
||||||
|
NODE_NAME_TO_CONSTRUCTOR_MAP.set(name, constructor);
|
||||||
|
return constructor;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 条件节点装饰器
|
||||||
|
*/
|
||||||
|
export function ClassCondition(name: string, info?: { group?: string, name?: string, desc?: string }) {
|
||||||
|
return function <T extends new (...args: any[]) => any>(constructor: T) {
|
||||||
|
const parameters = NODE_PARAMETERS_MAP.get(constructor) || [];
|
||||||
|
const fullMetadata: NodeMetadata = {
|
||||||
|
className: name,
|
||||||
|
group: info?.group || '未分组',
|
||||||
|
name: info?.name || '',
|
||||||
|
description: info?.desc || '',
|
||||||
|
type: Type.Condition,
|
||||||
|
maxChildren: 0,
|
||||||
|
parameters
|
||||||
|
};
|
||||||
|
NODE_METADATA_MAP.set(constructor, fullMetadata);
|
||||||
|
NODE_NAME_TO_CONSTRUCTOR_MAP.set(name, constructor);
|
||||||
|
return constructor;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组合节点装饰器
|
||||||
|
*/
|
||||||
|
export function ClassComposite(name: string, info?: { group?: string, name?: string, desc?: string }) {
|
||||||
|
return function <T extends new (...args: any[]) => any>(constructor: T) {
|
||||||
|
const parameters = NODE_PARAMETERS_MAP.get(constructor) || [];
|
||||||
|
const fullMetadata: NodeMetadata = {
|
||||||
|
className: name,
|
||||||
|
group: info?.group || '未分组',
|
||||||
|
name: info?.name || '',
|
||||||
|
description: info?.desc || '',
|
||||||
|
type: Type.Composite,
|
||||||
|
maxChildren: -1,
|
||||||
|
parameters
|
||||||
|
};
|
||||||
|
NODE_METADATA_MAP.set(constructor, fullMetadata);
|
||||||
|
NODE_NAME_TO_CONSTRUCTOR_MAP.set(name, constructor);
|
||||||
|
return constructor;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 装饰节点装饰器
|
||||||
|
*/
|
||||||
|
export function ClassDecorator(name: string, info?: { group?: string, name?: string, desc?: string }) {
|
||||||
|
return function <T extends new (...args: any[]) => any>(constructor: T) {
|
||||||
|
const parameters = NODE_PARAMETERS_MAP.get(constructor) || [];
|
||||||
|
const fullMetadata: NodeMetadata = {
|
||||||
|
className: name,
|
||||||
|
group: info?.group || '未分组',
|
||||||
|
name: info?.name || '',
|
||||||
|
description: info?.desc || '',
|
||||||
|
type: Type.Decorator,
|
||||||
|
maxChildren: 1,
|
||||||
|
parameters
|
||||||
|
};
|
||||||
|
NODE_METADATA_MAP.set(constructor, fullMetadata);
|
||||||
|
NODE_NAME_TO_CONSTRUCTOR_MAP.set(name, constructor);
|
||||||
|
return constructor;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有节点元数据
|
||||||
|
*/
|
||||||
|
export function getAllNodeMetadata(): Map<any, NodeMetadata> {
|
||||||
|
return new Map(NODE_METADATA_MAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过节点名 获取 节点构造函数
|
||||||
|
*/
|
||||||
|
export function getNodeConstructor(name: string): any {
|
||||||
|
return NODE_NAME_TO_CONSTRUCTOR_MAP.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过节点构造函数 找到节点元数据
|
||||||
|
*/
|
||||||
|
export function getNodeMetadata(ctor: any): NodeMetadata {
|
||||||
|
return NODE_METADATA_MAP.get(ctor)!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let _global = globalThis || window || global;
|
||||||
|
(_global as any)["getKunpoBTNodeMaps"] = function () {
|
||||||
|
return BT.getAllNodeMetadata();
|
||||||
|
};
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
/**
|
|
||||||
* @Author: Gongxh
|
|
||||||
* @Date: 2025-09-01
|
|
||||||
* @Description: 抽象节点基类
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { IBlackboard } from "../Blackboard";
|
|
||||||
import { BTNode, IBTNode } from "./BTNode";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 叶子节点 基类
|
|
||||||
* 没有子节点
|
|
||||||
*/
|
|
||||||
export abstract class LeafNode extends BTNode {
|
|
||||||
constructor() {
|
|
||||||
super([]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修饰节点 基类
|
|
||||||
* 有且仅有一个子节点
|
|
||||||
*/
|
|
||||||
export abstract class Decorator extends BTNode {
|
|
||||||
constructor(child: IBTNode) {
|
|
||||||
super([child]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 组合节点 基类
|
|
||||||
* 多个子节点
|
|
||||||
*/
|
|
||||||
export abstract class Composite extends BTNode {
|
|
||||||
constructor(...children: IBTNode[]) {
|
|
||||||
super(children);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数值型修饰节点 基类
|
|
||||||
* 包含最大值和当前值的通用逻辑,适用于所有需要数值计数的修饰节点
|
|
||||||
*/
|
|
||||||
export abstract class NumericDecorator extends Decorator {
|
|
||||||
protected readonly _max: number;
|
|
||||||
protected _value: number = 0;
|
|
||||||
|
|
||||||
constructor(child: IBTNode, max: number = 1) {
|
|
||||||
super(child);
|
|
||||||
this._max = max;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override open(): void {
|
|
||||||
super.open();
|
|
||||||
this._value = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 记忆修饰节点基类
|
|
||||||
* 只有记忆节点才需要设置局部数据
|
|
||||||
*/
|
|
||||||
export abstract class MemoryComposite extends Composite {
|
|
||||||
public override _initialize(global: IBlackboard, branch: IBlackboard): void {
|
|
||||||
super._initialize(global, branch);
|
|
||||||
this._local = branch.createChild();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override open(): void {
|
|
||||||
super.open();
|
|
||||||
this.set(`__nMemoryRunningIndex`, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
|
import { BT } from "../BT";
|
||||||
import { Status } from "../header";
|
import { Status } from "../header";
|
||||||
import { LeafNode } from "./AbstractNodes";
|
import { BTNode } from "./BTNode";
|
||||||
import { IBTNode } from "./BTNode";
|
|
||||||
|
|
||||||
export class Action extends LeafNode {
|
/**
|
||||||
protected _func: (node: IBTNode) => Status;
|
* 叶子节点 基类
|
||||||
constructor(func: (node: IBTNode) => Status) {
|
* 没有子节点
|
||||||
super();
|
*/
|
||||||
this._func = func;
|
export abstract class LeafNode extends BTNode {
|
||||||
}
|
constructor() {
|
||||||
|
super([]);
|
||||||
public tick(): Status {
|
|
||||||
return this._func?.(this) ?? Status.SUCCESS;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,7 +17,13 @@ export class Action extends LeafNode {
|
|||||||
* 次数内,返回RUNNING
|
* 次数内,返回RUNNING
|
||||||
* 超次,返回SUCCESS
|
* 超次,返回SUCCESS
|
||||||
*/
|
*/
|
||||||
|
@BT.ClassAction("WaitTicks", {
|
||||||
|
name: "等待次数",
|
||||||
|
group: "基础行为节点",
|
||||||
|
desc: "等待指定次数后返回成功",
|
||||||
|
})
|
||||||
export class WaitTicks extends LeafNode {
|
export class WaitTicks extends LeafNode {
|
||||||
|
@BT.prop({ type: BT.ParamType.int, description: "最大等待次数", defaultValue: 0, step: 1 })
|
||||||
private _max: number;
|
private _max: number;
|
||||||
private _value: number;
|
private _value: number;
|
||||||
|
|
||||||
@@ -46,22 +50,28 @@ export class WaitTicks extends LeafNode {
|
|||||||
* 时间等待节点 时间(秒)
|
* 时间等待节点 时间(秒)
|
||||||
* 时间到后返回SUCCESS,否则返回RUNNING
|
* 时间到后返回SUCCESS,否则返回RUNNING
|
||||||
*/
|
*/
|
||||||
|
@BT.ClassAction("WaitTime", {
|
||||||
|
name: "等待时间",
|
||||||
|
group: "基础行为节点",
|
||||||
|
desc: "等待指定时间(秒)后返回成功",
|
||||||
|
})
|
||||||
export class WaitTime extends LeafNode {
|
export class WaitTime extends LeafNode {
|
||||||
|
@BT.prop({ type: BT.ParamType.float, description: "等待时间(秒)", defaultValue: 0, step: 0.01 })
|
||||||
private _max: number;
|
private _max: number;
|
||||||
private _value: number = 0;
|
private _value: number = 0;
|
||||||
constructor(duration: number = 0) {
|
constructor(duration: number = 0) {
|
||||||
super();
|
super();
|
||||||
this._max = duration * 1000;
|
this._max = duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override open(): void {
|
protected override open(): void {
|
||||||
super.open();
|
super.open();
|
||||||
this._value = new Date().getTime();
|
this._value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public tick(): Status {
|
public tick(dt: number): Status {
|
||||||
const currTime = new Date().getTime();
|
this._value += dt;
|
||||||
if (currTime - this._value >= this._max) {
|
if (this._value >= this._max) {
|
||||||
return Status.SUCCESS;
|
return Status.SUCCESS;
|
||||||
}
|
}
|
||||||
return Status.RUNNING;
|
return Status.RUNNING;
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ export interface IBTNode {
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
_execute(): Status;
|
_execute(dt: number): Status;
|
||||||
tick(): Status;
|
tick(dt: number): Status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 优先写入自己的黑板数据, 如果没有则写入父节点的黑板数据
|
* 优先写入自己的黑板数据, 如果没有则写入父节点的黑板数据
|
||||||
@@ -67,7 +67,7 @@ export abstract class BTNode implements IBTNode {
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
public _execute(): Status {
|
public _execute(dt: number): Status {
|
||||||
// 首次执行时初始化
|
// 首次执行时初始化
|
||||||
const isRunning = this._local.openNodes.get(this) || false;
|
const isRunning = this._local.openNodes.get(this) || false;
|
||||||
if (!isRunning) {
|
if (!isRunning) {
|
||||||
@@ -76,14 +76,13 @@ export abstract class BTNode implements IBTNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 执行核心逻辑
|
// 执行核心逻辑
|
||||||
const status = this.tick();
|
const status = this.tick(dt);
|
||||||
|
|
||||||
// 执行完成时清理
|
// 执行完成时清理
|
||||||
if (status !== Status.RUNNING) {
|
if (status !== Status.RUNNING) {
|
||||||
this._local.openNodes.delete(this);
|
this._local.openNodes.delete(this);
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,19 +91,25 @@ export abstract class BTNode implements IBTNode {
|
|||||||
* 子类重写此方法进行状态初始化
|
* 子类重写此方法进行状态初始化
|
||||||
*/
|
*/
|
||||||
protected open(): void { }
|
protected open(): void { }
|
||||||
|
protected close(): void { }
|
||||||
|
/**
|
||||||
|
* 清理子节点的打开状态
|
||||||
|
* 一般用于装饰节点的非子节点关闭时, 用来清理子节点的打开状态
|
||||||
|
*/
|
||||||
|
protected cleanupChild(): void {
|
||||||
|
const child = this.children[0];
|
||||||
|
if (child && this._local.openNodes.has(child)) {
|
||||||
|
this._local.openNodes.delete(child);
|
||||||
|
(child as BTNode).close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行节点逻辑
|
* 执行节点逻辑
|
||||||
* 子类必须实现此方法
|
* 子类必须实现此方法
|
||||||
* @returns 执行状态
|
* @returns 执行状态
|
||||||
*/
|
*/
|
||||||
public abstract tick(): Status;
|
public abstract tick(dt: number): Status;
|
||||||
|
|
||||||
/**
|
|
||||||
* 清理节点(执行完成时调用)
|
|
||||||
* 子类重写此方法进行状态清理
|
|
||||||
*/
|
|
||||||
protected close(): void { }
|
|
||||||
|
|
||||||
public getEntity<T>(): T {
|
public getEntity<T>(): T {
|
||||||
return this._local.getEntity();
|
return this._local.getEntity();
|
||||||
|
|||||||
@@ -1,5 +1,18 @@
|
|||||||
|
import { IBlackboard } from "../Blackboard";
|
||||||
|
import { BT } from "../BT";
|
||||||
import { Status } from "../header";
|
import { Status } from "../header";
|
||||||
import { Composite, MemoryComposite } from "./AbstractNodes";
|
import { BTNode, IBTNode } from "./BTNode";
|
||||||
|
import { WeightDecorator } from "./Decorator";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组合节点基类
|
||||||
|
* 有多个子节点
|
||||||
|
*/
|
||||||
|
export abstract class Composite extends BTNode {
|
||||||
|
constructor(...children: IBTNode[]) {
|
||||||
|
super(children);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 记忆选择节点 从上到下执行
|
* 记忆选择节点 从上到下执行
|
||||||
@@ -8,78 +21,30 @@ import { Composite, MemoryComposite } from "./AbstractNodes";
|
|||||||
*
|
*
|
||||||
* 遇到 RUNNING 返回 RUNNING 下次从该节点开始
|
* 遇到 RUNNING 返回 RUNNING 下次从该节点开始
|
||||||
*/
|
*/
|
||||||
export class MemSelector extends MemoryComposite {
|
@BT.ClassComposite("Selector", { name: "选择节点", group: "基础组合节点", desc: "选择节点" })
|
||||||
public tick(): Status {
|
|
||||||
let index = this.get<number>(`__nMemoryRunningIndex`);
|
|
||||||
for (let i = index; i < this.children.length; i++) {
|
|
||||||
let status = this.children[i]!._execute();
|
|
||||||
if (status === Status.FAILURE) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (status === Status.SUCCESS) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
this.set(`__nMemoryRunningIndex`, i);
|
|
||||||
return Status.RUNNING;
|
|
||||||
}
|
|
||||||
return Status.FAILURE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 记忆顺序节点 从上到下执行
|
|
||||||
* 遇到 SUCCESS 继续下一个
|
|
||||||
* 遇到 FAILURE 停止迭代 返回 FAILURE 下次重新开始
|
|
||||||
*
|
|
||||||
* 遇到 RUNNING 返回 RUNNING 下次从该节点开始
|
|
||||||
*/
|
|
||||||
export class MemSequence extends MemoryComposite {
|
|
||||||
public tick(): Status {
|
|
||||||
let index = this.get<number>(`__nMemoryRunningIndex`);
|
|
||||||
for (let i = index; i < this.children.length; i++) {
|
|
||||||
let status = this.children[i]!._execute();
|
|
||||||
if (status === Status.SUCCESS) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (status === Status.FAILURE) {
|
|
||||||
return Status.FAILURE;
|
|
||||||
}
|
|
||||||
this.set(`__nMemoryRunningIndex`, i);
|
|
||||||
return Status.RUNNING;
|
|
||||||
}
|
|
||||||
return Status.SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 随机选择节点
|
|
||||||
* 随机选择一个子节点执行
|
|
||||||
* 返回子节点状态
|
|
||||||
*/
|
|
||||||
export class RandomSelector extends Composite {
|
|
||||||
public tick(): Status {
|
|
||||||
if (this.children.length === 0) {
|
|
||||||
return Status.FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
const childIndex = Math.floor(Math.random() * this.children.length);
|
|
||||||
const status = this.children[childIndex]!._execute();
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 选择节点 从上到下执行
|
|
||||||
* 返回第一个不为 FAILURE 的子节点状态
|
|
||||||
* 否则返回 FAILURE
|
|
||||||
*/
|
|
||||||
export class Selector extends Composite {
|
export class Selector extends Composite {
|
||||||
public tick(): Status {
|
public override _initialize(global: IBlackboard, branch: IBlackboard): void {
|
||||||
for (let i = 0; i < this.children.length; i++) {
|
super._initialize(global, branch);
|
||||||
let status = this.children[i]!._execute();
|
this._local = branch.createChild();
|
||||||
if (status !== Status.FAILURE) {
|
}
|
||||||
|
|
||||||
|
protected override open(): void {
|
||||||
|
super.open();
|
||||||
|
this.set(`__nRunningIndex`, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public tick(dt: number): Status {
|
||||||
|
let index = this.get<number>(`__nRunningIndex`);
|
||||||
|
for (let i = index; i < this.children.length; i++) {
|
||||||
|
let status = this.children[i]!._execute(dt);
|
||||||
|
if (status === Status.FAILURE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (status === Status.SUCCESS) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
this.set(`__nRunningIndex`, i);
|
||||||
|
return Status.RUNNING;
|
||||||
}
|
}
|
||||||
return Status.FAILURE;
|
return Status.FAILURE;
|
||||||
}
|
}
|
||||||
@@ -88,16 +53,34 @@ export class Selector extends Composite {
|
|||||||
/**
|
/**
|
||||||
* 顺序节点 从上到下执行
|
* 顺序节点 从上到下执行
|
||||||
* 遇到 SUCCESS 继续下一个
|
* 遇到 SUCCESS 继续下一个
|
||||||
* 否则返回子节点状态
|
* 遇到 FAILURE 停止迭代 返回 FAILURE 下次重新开始
|
||||||
|
*
|
||||||
|
* 遇到 RUNNING 返回 RUNNING 下次从该节点开始
|
||||||
*/
|
*/
|
||||||
|
@BT.ClassComposite("Sequence", { name: "顺序节点", group: "基础组合节点", desc: "顺序节点" })
|
||||||
export class Sequence extends Composite {
|
export class Sequence extends Composite {
|
||||||
public tick(): Status {
|
public override _initialize(global: IBlackboard, branch: IBlackboard): void {
|
||||||
for (let i = 0; i < this.children.length; i++) {
|
super._initialize(global, branch);
|
||||||
let status = this.children[i]!._execute();
|
this._local = branch.createChild();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override open(): void {
|
||||||
|
super.open();
|
||||||
|
this.set(`__nRunningIndex`, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public tick(dt: number): Status {
|
||||||
|
let index = this.get<number>(`__nRunningIndex`);
|
||||||
|
for (let i = index; i < this.children.length; i++) {
|
||||||
|
let status = this.children[i]!._execute(dt);
|
||||||
if (status === Status.SUCCESS) {
|
if (status === Status.SUCCESS) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return status;
|
if (status === Status.FAILURE) {
|
||||||
|
return Status.FAILURE;
|
||||||
|
}
|
||||||
|
this.set(`__nRunningIndex`, i);
|
||||||
|
return Status.RUNNING;
|
||||||
}
|
}
|
||||||
return Status.SUCCESS;
|
return Status.SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -107,11 +90,12 @@ export class Sequence extends Composite {
|
|||||||
* 并行节点 从上到下执行 全部执行一遍
|
* 并行节点 从上到下执行 全部执行一遍
|
||||||
* 返回优先级 FAILURE > RUNNING > SUCCESS
|
* 返回优先级 FAILURE > RUNNING > SUCCESS
|
||||||
*/
|
*/
|
||||||
|
@BT.ClassComposite("Parallel", { name: "并行节点", group: "基础组合节点", desc: "同时执行所有子节点,全部成功才返回成功" })
|
||||||
export class Parallel extends Composite {
|
export class Parallel extends Composite {
|
||||||
public tick(): Status {
|
public tick(dt: number): Status {
|
||||||
let result = Status.SUCCESS;
|
let result = Status.SUCCESS;
|
||||||
for (let i = 0; i < this.children.length; i++) {
|
for (let i = 0; i < this.children.length; i++) {
|
||||||
let status = this.children[i]!._execute();
|
let status = this.children[i]!._execute(dt);
|
||||||
if (result === Status.FAILURE || status === Status.FAILURE) {
|
if (result === Status.FAILURE || status === Status.FAILURE) {
|
||||||
result = Status.FAILURE;
|
result = Status.FAILURE;
|
||||||
} else if (status === Status.RUNNING) {
|
} else if (status === Status.RUNNING) {
|
||||||
@@ -122,15 +106,78 @@ export class Parallel extends Composite {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机选择节点
|
||||||
|
* 随机选择一个子节点执行
|
||||||
|
* 返回子节点状态
|
||||||
|
*/
|
||||||
|
@BT.ClassComposite("RandomSelector", {
|
||||||
|
name: "随机选择节点",
|
||||||
|
group: "基础组合节点",
|
||||||
|
desc: "随机选择一个子节点执行",
|
||||||
|
})
|
||||||
|
export class RandomSelector extends Composite {
|
||||||
|
private _totalWeight: number = 0;
|
||||||
|
private _weights: number[] = [];
|
||||||
|
|
||||||
|
constructor(...children: IBTNode[]) {
|
||||||
|
super(...children);
|
||||||
|
this._totalWeight = 0;
|
||||||
|
this._weights = [];
|
||||||
|
|
||||||
|
for (const child of children) {
|
||||||
|
const weight = this.getChildWeight(child);
|
||||||
|
this._totalWeight += weight;
|
||||||
|
this._weights.push(this._totalWeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private getChildWeight(child: IBTNode): number {
|
||||||
|
return (child instanceof WeightDecorator) ? (child.weight) : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public tick(dt: number): Status {
|
||||||
|
if (this.children.length === 0) {
|
||||||
|
return Status.FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 基于权重的随机选择
|
||||||
|
const randomValue = Math.random() * this._totalWeight;
|
||||||
|
|
||||||
|
// 使用二分查找找到对应的子节点索引(O(log n)复杂度)
|
||||||
|
let left = 0;
|
||||||
|
let right = this._weights.length - 1;
|
||||||
|
let childIndex = 0;
|
||||||
|
|
||||||
|
while (left <= right) {
|
||||||
|
const mid = Math.floor((left + right) / 2);
|
||||||
|
if (this._weights[mid]! > randomValue) {
|
||||||
|
childIndex = mid;
|
||||||
|
right = mid - 1;
|
||||||
|
} else {
|
||||||
|
left = mid + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const status = this.children[childIndex]!._execute(dt);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 并行节点 从上到下执行 全部执行一遍
|
* 并行节点 从上到下执行 全部执行一遍
|
||||||
* 返回优先级 SUCCESS > RUNNING > FAILURE
|
* 返回优先级 SUCCESS > RUNNING > FAILURE
|
||||||
*/
|
*/
|
||||||
|
@BT.ClassComposite("ParallelAnySuccess", {
|
||||||
|
name: "并行任意成功",
|
||||||
|
group: "基础组合节点",
|
||||||
|
desc: "同时执行所有子节点,任意一个成功即返回成功",
|
||||||
|
})
|
||||||
export class ParallelAnySuccess extends Composite {
|
export class ParallelAnySuccess extends Composite {
|
||||||
public tick(): Status {
|
public tick(dt: number): Status {
|
||||||
let result = Status.FAILURE;
|
let result = Status.FAILURE;
|
||||||
for (let i = 0; i < this.children.length; i++) {
|
for (let i = 0; i < this.children.length; i++) {
|
||||||
let status = this.children[i]!._execute();
|
let status = this.children[i]!._execute(dt);
|
||||||
if (result === Status.SUCCESS || status === Status.SUCCESS) {
|
if (result === Status.SUCCESS || status === Status.SUCCESS) {
|
||||||
result = Status.SUCCESS;
|
result = Status.SUCCESS;
|
||||||
} else if (status === Status.RUNNING) {
|
} else if (status === Status.RUNNING) {
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
import { Status } from "../header";
|
|
||||||
import { LeafNode } from "./AbstractNodes";
|
|
||||||
import { IBTNode } from "./BTNode";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 条件节点
|
* @Author: Gongxh
|
||||||
* 根据条件函数返回SUCCESS或FAILURE
|
* @Date: 2025-09-17
|
||||||
|
* @Description: 条件节点基类
|
||||||
*/
|
*/
|
||||||
export class Condition extends LeafNode {
|
|
||||||
/** 执行函数 @internal */
|
import { Status } from "../header";
|
||||||
private readonly _func: (node: IBTNode) => boolean;
|
import { LeafNode } from "./Action";
|
||||||
constructor(func: (node: IBTNode) => boolean) {
|
|
||||||
super();
|
/** 条件叶子节点 */
|
||||||
this._func = func;
|
export abstract class Condition extends LeafNode {
|
||||||
}
|
/**
|
||||||
|
* 判断是否满足条件
|
||||||
|
* @returns 是否满足条件
|
||||||
|
*/
|
||||||
|
protected abstract isEligible(): boolean;
|
||||||
|
|
||||||
public tick(): Status {
|
public tick(): Status {
|
||||||
return this._func?.(this) ? Status.SUCCESS : Status.FAILURE;
|
return this.isEligible() ? Status.SUCCESS : Status.FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,9 +4,35 @@
|
|||||||
* @Description: 装饰节点 装饰节点下必须包含子节点
|
* @Description: 装饰节点 装饰节点下必须包含子节点
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { BT } from "../BT";
|
||||||
import { Status } from "../header";
|
import { Status } from "../header";
|
||||||
import { Decorator, NumericDecorator } from "./AbstractNodes";
|
import { BTNode, IBTNode } from "./BTNode";
|
||||||
import { IBTNode } from "./BTNode";
|
|
||||||
|
/**
|
||||||
|
* 修饰节点 基类
|
||||||
|
* 有且仅有一个子节点
|
||||||
|
*/
|
||||||
|
export abstract class Decorator extends BTNode {
|
||||||
|
constructor(child: IBTNode) {
|
||||||
|
super([child]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 条件装饰节点基类 */
|
||||||
|
export abstract class ConditionDecorator extends Decorator {
|
||||||
|
/**
|
||||||
|
* 判断是否满足条件
|
||||||
|
* @returns 是否满足条件
|
||||||
|
*/
|
||||||
|
protected abstract isEligible(): boolean;
|
||||||
|
|
||||||
|
public tick(dt: number): Status {
|
||||||
|
if (this.isEligible()) {
|
||||||
|
return this.children[0]!._execute(dt);
|
||||||
|
}
|
||||||
|
return Status.FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 结果反转节点
|
* 结果反转节点
|
||||||
@@ -14,9 +40,10 @@ import { IBTNode } from "./BTNode";
|
|||||||
* 第一个Child Node节点, 返回 FAILURE, 本Node向自己的Parent Node也返回 SUCCESS
|
* 第一个Child Node节点, 返回 FAILURE, 本Node向自己的Parent Node也返回 SUCCESS
|
||||||
* 第一个Child Node节点, 返回 SUCCESS, 本Node向自己的Parent Node也返回 FAILURE
|
* 第一个Child Node节点, 返回 SUCCESS, 本Node向自己的Parent Node也返回 FAILURE
|
||||||
*/
|
*/
|
||||||
|
@BT.ClassDecorator("Inverter", { name: "反转器", group: "基础装饰节点", desc: "反转子节点的执行结果,成功变失败,失败变成功" })
|
||||||
export class Inverter extends Decorator {
|
export class Inverter extends Decorator {
|
||||||
public tick(): Status {
|
public tick(dt: number): Status {
|
||||||
const status = this.children[0]!._execute();
|
const status = this.children[0]!._execute(dt);
|
||||||
|
|
||||||
if (status === Status.SUCCESS) {
|
if (status === Status.SUCCESS) {
|
||||||
return Status.FAILURE;
|
return Status.FAILURE;
|
||||||
@@ -34,26 +61,33 @@ export class Inverter extends Decorator {
|
|||||||
* 规定时间内, 根据Child Node的结果, 本节点向自己的父节点也返回相同的结果
|
* 规定时间内, 根据Child Node的结果, 本节点向自己的父节点也返回相同的结果
|
||||||
* 超时后, 直接返回 FAILURE
|
* 超时后, 直接返回 FAILURE
|
||||||
*/
|
*/
|
||||||
export class LimitTime extends NumericDecorator {
|
@BT.ClassDecorator("LimitTime", { name: "时间限制器", group: "基础装饰节点", desc: "限制子节点执行时间,超时返回失败" })
|
||||||
|
export class LimitTime extends Decorator {
|
||||||
|
@BT.prop({ type: BT.ParamType.float, description: "最大时间(秒)", defaultValue: 1 })
|
||||||
|
protected _max: number = 1;
|
||||||
|
|
||||||
|
private _value: number = 0;
|
||||||
/**
|
/**
|
||||||
* 时间限制节点
|
* 时间限制节点
|
||||||
* @param child 子节点
|
* @param child 子节点
|
||||||
* @param max 最大时间 (秒) 默认1秒
|
* @param max 最大时间 (秒) 默认1秒
|
||||||
*/
|
*/
|
||||||
constructor(child: IBTNode, max: number = 1) {
|
constructor(child: IBTNode, max: number = 1) {
|
||||||
super(child, max * 1000);
|
super(child);
|
||||||
|
this._max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override open(): void {
|
protected override open(): void {
|
||||||
this._value = Date.now();
|
this._value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public tick(): Status {
|
public tick(dt: number): Status {
|
||||||
const currentTime = Date.now();
|
this._value += dt;
|
||||||
if (currentTime - this._value > this._max) {
|
if (this._value > this._max) {
|
||||||
|
this.cleanupChild();
|
||||||
return Status.FAILURE;
|
return Status.FAILURE;
|
||||||
}
|
}
|
||||||
return this.children[0]!._execute();
|
return this.children[0]!._execute(dt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,13 +96,31 @@ export class LimitTime extends NumericDecorator {
|
|||||||
* 必须且只能包含一个子节点
|
* 必须且只能包含一个子节点
|
||||||
* 次数超过后, 直接返回失败; 次数未超过, 返回子节点状态
|
* 次数超过后, 直接返回失败; 次数未超过, 返回子节点状态
|
||||||
*/
|
*/
|
||||||
export class LimitTicks extends NumericDecorator {
|
@BT.ClassDecorator("LimitTicks", { name: "次数限制器", group: "基础装饰节点", desc: "限制子节点执行次数,超过次数返回失败" })
|
||||||
public tick(): Status {
|
export class LimitTicks extends Decorator {
|
||||||
this._value++;
|
@BT.prop({ type: BT.ParamType.int, description: "最大次数", defaultValue: 1 })
|
||||||
|
protected _max: number = 1;
|
||||||
|
|
||||||
|
private _value: number = 0;
|
||||||
|
constructor(child: IBTNode, max: number = 1) {
|
||||||
|
super(child);
|
||||||
|
this._max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override open(): void {
|
||||||
|
this._value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public tick(dt: number): Status {
|
||||||
if (this._value > this._max) {
|
if (this._value > this._max) {
|
||||||
|
this.cleanupChild();
|
||||||
return Status.FAILURE;
|
return Status.FAILURE;
|
||||||
}
|
}
|
||||||
return this.children[0]!._execute();
|
let status = this.children[0]!._execute(dt);
|
||||||
|
if (status !== Status.RUNNING) {
|
||||||
|
this._value++;
|
||||||
|
}
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,12 +130,26 @@ export class LimitTicks extends NumericDecorator {
|
|||||||
* 子节点是成功或失败,累加计数
|
* 子节点是成功或失败,累加计数
|
||||||
* 次数超过之后返回子节点状态,否则返回 RUNNING
|
* 次数超过之后返回子节点状态,否则返回 RUNNING
|
||||||
*/
|
*/
|
||||||
export class Repeat extends NumericDecorator {
|
@BT.ClassDecorator("Repeat", { name: "重复节点", group: "基础装饰节点", desc: "重复执行子节点指定次数" })
|
||||||
public tick(): Status {
|
export class Repeat extends Decorator {
|
||||||
|
@BT.prop({ type: BT.ParamType.int, description: "重复次数", defaultValue: 1, min: 1 })
|
||||||
|
protected _max: number = 1;
|
||||||
|
|
||||||
|
private _value: number = 0;
|
||||||
|
constructor(child: IBTNode, max: number = 1) {
|
||||||
|
super(child);
|
||||||
|
this._max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override open(): void {
|
||||||
|
this._value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public tick(dt: number): Status {
|
||||||
// 执行子节点
|
// 执行子节点
|
||||||
const status = this.children[0]!._execute();
|
const status = this.children[0]!._execute(dt);
|
||||||
// 如果子节点完成(成功或失败),增加计数
|
// 如果子节点完成(成功或失败),增加计数
|
||||||
if (status === Status.SUCCESS || status === Status.FAILURE) {
|
if (status !== Status.RUNNING) {
|
||||||
this._value++;
|
this._value++;
|
||||||
// 检查是否达到最大次数
|
// 检查是否达到最大次数
|
||||||
if (this._value >= this._max) {
|
if (this._value >= this._max) {
|
||||||
@@ -101,9 +167,23 @@ export class Repeat extends NumericDecorator {
|
|||||||
*
|
*
|
||||||
* 子节点成功 计数+1
|
* 子节点成功 计数+1
|
||||||
*/
|
*/
|
||||||
export class RepeatUntilFailure extends NumericDecorator {
|
@BT.ClassDecorator("RepeatUntilFailure", { name: "重复直到失败", group: "基础装饰节点", desc: "重复执行子节点直到失败或达到最大次数" })
|
||||||
public tick(): Status {
|
export class RepeatUntilFailure extends Decorator {
|
||||||
const status = this.children[0]!._execute();
|
@BT.prop({ type: BT.ParamType.int, description: "最大重试次数", defaultValue: 1, min: 1 })
|
||||||
|
protected _max: number = 1;
|
||||||
|
|
||||||
|
private _value: number = 0;
|
||||||
|
constructor(child: IBTNode, max: number = 1) {
|
||||||
|
super(child);
|
||||||
|
this._max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override open(): void {
|
||||||
|
this._value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public tick(dt: number): Status {
|
||||||
|
const status = this.children[0]!._execute(dt);
|
||||||
if (status === Status.FAILURE) {
|
if (status === Status.FAILURE) {
|
||||||
return Status.FAILURE;
|
return Status.FAILURE;
|
||||||
}
|
}
|
||||||
@@ -125,10 +205,24 @@ export class RepeatUntilFailure extends NumericDecorator {
|
|||||||
*
|
*
|
||||||
* 子节点失败, 计数+1
|
* 子节点失败, 计数+1
|
||||||
*/
|
*/
|
||||||
export class RepeatUntilSuccess extends NumericDecorator {
|
@BT.ClassDecorator("RepeatUntilSuccess", { name: "重复直到成功", group: "基础装饰节点", desc: "重复执行子节点直到成功或达到最大次数" })
|
||||||
public tick(): Status {
|
export class RepeatUntilSuccess extends Decorator {
|
||||||
|
@BT.prop({ type: BT.ParamType.int, description: "最大重试次数", defaultValue: 1, step: 1 })
|
||||||
|
protected _max: number = 1;
|
||||||
|
|
||||||
|
private _value: number = 0;
|
||||||
|
constructor(child: IBTNode, max: number = 1) {
|
||||||
|
super(child);
|
||||||
|
this._max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override open(): void {
|
||||||
|
this._value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public tick(dt: number): Status {
|
||||||
// 执行子节点
|
// 执行子节点
|
||||||
const status = this.children[0]!._execute();
|
const status = this.children[0]!._execute(dt);
|
||||||
if (status === Status.SUCCESS) {
|
if (status === Status.SUCCESS) {
|
||||||
return Status.SUCCESS;
|
return Status.SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -142,3 +236,26 @@ export class RepeatUntilSuccess extends NumericDecorator {
|
|||||||
return Status.RUNNING;
|
return Status.RUNNING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权重装饰节点
|
||||||
|
*/
|
||||||
|
@BT.ClassDecorator("WeightDecorator", { name: "权重装饰器", group: "基础装饰节点", desc: "权重装饰节点" })
|
||||||
|
export class WeightDecorator extends Decorator {
|
||||||
|
@BT.prop({ type: BT.ParamType.int, description: "权重", defaultValue: 1, step: 1 })
|
||||||
|
private _weight: number;
|
||||||
|
|
||||||
|
constructor(child: IBTNode, weight?: number) {
|
||||||
|
super(child);
|
||||||
|
// 优先使用构造函数参数,否则使用装饰器默认参数
|
||||||
|
this._weight = weight || 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public tick(dt: number): Status {
|
||||||
|
return this.children[0]!._execute(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public get weight(): number {
|
||||||
|
return this._weight;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,8 +34,8 @@ export class BehaviorTree<T> {
|
|||||||
/**
|
/**
|
||||||
* 执行行为树
|
* 执行行为树
|
||||||
*/
|
*/
|
||||||
public tick(): Status {
|
public tick(dt: number): Status {
|
||||||
return this._root._execute();
|
return this._root._execute(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
71
src/behaviortree/Factory.ts
Normal file
71
src/behaviortree/Factory.ts
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
/**
|
||||||
|
* @Author: Gongxh
|
||||||
|
* @Date: 2025-09-16
|
||||||
|
* @Description: 根据数据创建一颗行为树
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { BehaviorTree } from "./BehaviorTree";
|
||||||
|
import { BT } from "./BT";
|
||||||
|
import { IBTNode } from "./BTNode/BTNode";
|
||||||
|
|
||||||
|
export interface INodeConfig {
|
||||||
|
id: string,
|
||||||
|
className: string,
|
||||||
|
parameters: Record<string, any>,
|
||||||
|
children: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据节点配置递归创建节点
|
||||||
|
* @param info 节点配置
|
||||||
|
* @param nodeMap 所有节点配置的映射表
|
||||||
|
* @returns 创建的节点实例
|
||||||
|
*/
|
||||||
|
function createNodeRecursively(info: INodeConfig, nodeMap: Map<string, INodeConfig>): IBTNode {
|
||||||
|
// 获取节点构造函数
|
||||||
|
const ctor = BT.getNodeConstructor(info.className);
|
||||||
|
if (!ctor) {
|
||||||
|
throw new Error(`未找到节点【${info.className}】的构造函数`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 递归创建子节点
|
||||||
|
const childNodes: IBTNode[] = [];
|
||||||
|
for (const childId of info.children || []) {
|
||||||
|
const childInfo = nodeMap.get(childId);
|
||||||
|
if (!childInfo) {
|
||||||
|
throw new Error(`未找到子节点【${childId}】,行为树配置导出信息错误`);
|
||||||
|
}
|
||||||
|
const childNode = createNodeRecursively(childInfo, nodeMap);
|
||||||
|
childNodes.push(childNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建节点实例
|
||||||
|
let btnode: IBTNode;
|
||||||
|
const metadata = BT.getNodeMetadata(ctor);
|
||||||
|
if (metadata.type === BT.Type.Action || metadata.type === BT.Type.Condition) {
|
||||||
|
btnode = new ctor();
|
||||||
|
} else if (metadata.type === BT.Type.Decorator) {
|
||||||
|
btnode = new ctor(childNodes[0]!);
|
||||||
|
} else {
|
||||||
|
btnode = new ctor(...childNodes);
|
||||||
|
}
|
||||||
|
// 设置节点参数
|
||||||
|
for (const key in info.parameters) {
|
||||||
|
(btnode as any)[key] = info.parameters[key];
|
||||||
|
}
|
||||||
|
return btnode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createBehaviorTree<T>(config: INodeConfig[], entity: T): BehaviorTree<T> {
|
||||||
|
// 验证配置
|
||||||
|
if (!config || !Array.isArray(config) || config.length === 0) {
|
||||||
|
throw new Error("Config is empty or invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建配置映射表
|
||||||
|
const nodeMap = new Map<string, INodeConfig>();
|
||||||
|
for (const info of config) {
|
||||||
|
nodeMap.set(info.id, info);
|
||||||
|
}
|
||||||
|
return new BehaviorTree(entity, createNodeRecursively(config[0]!, nodeMap));
|
||||||
|
}
|
||||||
@@ -2,12 +2,14 @@
|
|||||||
/** 行为树 */
|
/** 行为树 */
|
||||||
export { BehaviorTree } from "./behaviortree/BehaviorTree";
|
export { BehaviorTree } from "./behaviortree/BehaviorTree";
|
||||||
export { Blackboard } from "./behaviortree/Blackboard";
|
export { Blackboard } from "./behaviortree/Blackboard";
|
||||||
export * from "./behaviortree/BTNode/AbstractNodes";
|
|
||||||
export * from "./behaviortree/BTNode/Action";
|
export * from "./behaviortree/BTNode/Action";
|
||||||
export { IBTNode } from "./behaviortree/BTNode/BTNode";
|
export { IBTNode } from "./behaviortree/BTNode/BTNode";
|
||||||
export * from "./behaviortree/BTNode/Composite";
|
export * from "./behaviortree/BTNode/Composite";
|
||||||
export { Condition } from "./behaviortree/BTNode/Condition";
|
export * from "./behaviortree/BTNode/Condition";
|
||||||
export * from "./behaviortree/BTNode/Decorator";
|
export * from "./behaviortree/BTNode/Decorator";
|
||||||
|
export { createBehaviorTree, INodeConfig } from "./behaviortree/Factory";
|
||||||
export { Status } from "./behaviortree/header";
|
export { Status } from "./behaviortree/header";
|
||||||
|
|
||||||
|
// 导出装饰器内容
|
||||||
|
import { BT } from "./behaviortree/BT";
|
||||||
|
export const { ClassAction, ClassCondition, ClassComposite, ClassDecorator, prop, ParamType } = BT;
|
||||||
@@ -1,581 +0,0 @@
|
|||||||
/**
|
|
||||||
* 简单的测试运行器 - 无需外部依赖
|
|
||||||
* 验证所有行为树功能
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { BehaviorTree } from '../src/behaviortree/BehaviorTree';
|
|
||||||
import { Blackboard, globalBlackboard } from '../src/behaviortree/Blackboard';
|
|
||||||
import { Status } from '../src/behaviortree/header';
|
|
||||||
|
|
||||||
// 导入所有节点类型
|
|
||||||
import { Action, WaitTicks, WaitTime } from '../src/behaviortree/BTNode/Action';
|
|
||||||
import { Condition } from '../src/behaviortree/BTNode/Condition';
|
|
||||||
import {
|
|
||||||
Selector, Sequence, Parallel, ParallelAnySuccess,
|
|
||||||
MemSelector, MemSequence, RandomSelector
|
|
||||||
} from '../src/behaviortree/BTNode/Composite';
|
|
||||||
import {
|
|
||||||
Inverter, LimitTime, LimitTicks, Repeat,
|
|
||||||
RepeatUntilFailure, RepeatUntilSuccess
|
|
||||||
} from '../src/behaviortree/BTNode/Decorator';
|
|
||||||
|
|
||||||
interface TestEntity {
|
|
||||||
name: string;
|
|
||||||
value: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 简单断言函数
|
|
||||||
function assert(condition: boolean, message: string) {
|
|
||||||
if (!condition) {
|
|
||||||
console.error(`❌ FAIL: ${message}`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function assertEqual<T>(actual: T, expected: T, message: string) {
|
|
||||||
if (actual !== expected) {
|
|
||||||
console.error(`❌ FAIL: ${message}`);
|
|
||||||
console.error(` Expected: ${expected}`);
|
|
||||||
console.error(` Actual: ${actual}`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function sleep(ms: number): Promise<void> {
|
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试计数器
|
|
||||||
let totalTests = 0;
|
|
||||||
let passedTests = 0;
|
|
||||||
|
|
||||||
function runTest(testName: string, testFn: () => void | Promise<void>) {
|
|
||||||
totalTests++;
|
|
||||||
try {
|
|
||||||
const result = testFn();
|
|
||||||
if (result instanceof Promise) {
|
|
||||||
return result.then(() => {
|
|
||||||
console.log(`✅ ${testName}`);
|
|
||||||
passedTests++;
|
|
||||||
}).catch(error => {
|
|
||||||
console.error(`❌ FAIL: ${testName} - ${error.message}`);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log(`✅ ${testName}`);
|
|
||||||
passedTests++;
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error(`❌ FAIL: ${testName} - ${error.message}`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
console.log('🚀 开始行为树全面功能测试...\n');
|
|
||||||
|
|
||||||
const testEntity: TestEntity = { name: 'test', value: 0 };
|
|
||||||
|
|
||||||
// 重置函数
|
|
||||||
function reset() {
|
|
||||||
testEntity.name = 'test';
|
|
||||||
testEntity.value = 0;
|
|
||||||
globalBlackboard.clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('📋 1. Action节点测试');
|
|
||||||
|
|
||||||
runTest('Action节点 - 成功执行', () => {
|
|
||||||
reset();
|
|
||||||
let executed = false;
|
|
||||||
const action = new Action(() => {
|
|
||||||
executed = true;
|
|
||||||
return Status.SUCCESS;
|
|
||||||
});
|
|
||||||
const tree = new BehaviorTree(testEntity, action);
|
|
||||||
const result = tree.tick();
|
|
||||||
assertEqual(result, Status.SUCCESS, 'Action应该返回SUCCESS');
|
|
||||||
assert(executed, 'Action函数应该被执行');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('Action节点 - 失败执行', () => {
|
|
||||||
reset();
|
|
||||||
let executed = false;
|
|
||||||
const action = new Action(() => {
|
|
||||||
executed = true;
|
|
||||||
return Status.FAILURE;
|
|
||||||
});
|
|
||||||
const tree = new BehaviorTree(testEntity, action);
|
|
||||||
const result = tree.tick();
|
|
||||||
assertEqual(result, Status.FAILURE, 'Action应该返回FAILURE');
|
|
||||||
assert(executed, 'Action函数应该被执行');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('WaitTicks节点 - 等待指定次数', () => {
|
|
||||||
reset();
|
|
||||||
const waitNode = new WaitTicks(3);
|
|
||||||
const tree = new BehaviorTree(testEntity, waitNode);
|
|
||||||
|
|
||||||
assertEqual(tree.tick(), Status.RUNNING, '第1次tick应该返回RUNNING');
|
|
||||||
assertEqual(tree.tick(), Status.RUNNING, '第2次tick应该返回RUNNING');
|
|
||||||
assertEqual(tree.tick(), Status.SUCCESS, '第3次tick应该返回SUCCESS');
|
|
||||||
});
|
|
||||||
|
|
||||||
await runTest('WaitTime节点 - 时间等待', async () => {
|
|
||||||
reset();
|
|
||||||
const waitNode = new WaitTime(0.1); // 100ms
|
|
||||||
const tree = new BehaviorTree(testEntity, waitNode);
|
|
||||||
|
|
||||||
assertEqual(tree.tick(), Status.RUNNING, '时间未到应该返回RUNNING');
|
|
||||||
|
|
||||||
await sleep(150);
|
|
||||||
assertEqual(tree.tick(), Status.SUCCESS, '时间到了应该返回SUCCESS');
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('\n📋 2. Condition节点测试');
|
|
||||||
|
|
||||||
runTest('Condition节点 - 条件为真', () => {
|
|
||||||
reset();
|
|
||||||
const condition = new Condition(() => true);
|
|
||||||
const tree = new BehaviorTree(testEntity, condition);
|
|
||||||
assertEqual(tree.tick(), Status.SUCCESS, 'true条件应该返回SUCCESS');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('Condition节点 - 条件为假', () => {
|
|
||||||
reset();
|
|
||||||
const condition = new Condition(() => false);
|
|
||||||
const tree = new BehaviorTree(testEntity, condition);
|
|
||||||
assertEqual(tree.tick(), Status.FAILURE, 'false条件应该返回FAILURE');
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('\n📋 3. Composite节点测试');
|
|
||||||
|
|
||||||
runTest('Selector节点 - 第一个成功', () => {
|
|
||||||
reset();
|
|
||||||
const selector = new Selector(
|
|
||||||
new Action(() => Status.SUCCESS),
|
|
||||||
new Action(() => Status.FAILURE)
|
|
||||||
);
|
|
||||||
const tree = new BehaviorTree(testEntity, selector);
|
|
||||||
assertEqual(tree.tick(), Status.SUCCESS, 'Selector第一个成功应该返回SUCCESS');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('Selector节点 - 全部失败', () => {
|
|
||||||
reset();
|
|
||||||
const selector = new Selector(
|
|
||||||
new Action(() => Status.FAILURE),
|
|
||||||
new Action(() => Status.FAILURE)
|
|
||||||
);
|
|
||||||
const tree = new BehaviorTree(testEntity, selector);
|
|
||||||
assertEqual(tree.tick(), Status.FAILURE, 'Selector全部失败应该返回FAILURE');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('Sequence节点 - 全部成功', () => {
|
|
||||||
reset();
|
|
||||||
const sequence = new Sequence(
|
|
||||||
new Action(() => Status.SUCCESS),
|
|
||||||
new Action(() => Status.SUCCESS)
|
|
||||||
);
|
|
||||||
const tree = new BehaviorTree(testEntity, sequence);
|
|
||||||
assertEqual(tree.tick(), Status.SUCCESS, 'Sequence全部成功应该返回SUCCESS');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('Sequence节点 - 中途失败', () => {
|
|
||||||
reset();
|
|
||||||
let firstExecuted = false;
|
|
||||||
let secondExecuted = false;
|
|
||||||
|
|
||||||
const sequence = new Sequence(
|
|
||||||
new Action(() => {
|
|
||||||
firstExecuted = true;
|
|
||||||
return Status.SUCCESS;
|
|
||||||
}),
|
|
||||||
new Action(() => {
|
|
||||||
secondExecuted = true;
|
|
||||||
return Status.FAILURE;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const tree = new BehaviorTree(testEntity, sequence);
|
|
||||||
|
|
||||||
assertEqual(tree.tick(), Status.FAILURE, 'Sequence中途失败应该返回FAILURE');
|
|
||||||
assert(firstExecuted, '第一个Action应该被执行');
|
|
||||||
assert(secondExecuted, '第二个Action也应该被执行');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('MemSelector节点 - 记忆运行状态', () => {
|
|
||||||
reset();
|
|
||||||
let firstCallCount = 0;
|
|
||||||
let secondCallCount = 0;
|
|
||||||
|
|
||||||
const memSelector = new MemSelector(
|
|
||||||
new Action(() => {
|
|
||||||
firstCallCount++;
|
|
||||||
return Status.RUNNING;
|
|
||||||
}),
|
|
||||||
new Action(() => {
|
|
||||||
secondCallCount++;
|
|
||||||
return Status.SUCCESS;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const tree = new BehaviorTree(testEntity, memSelector);
|
|
||||||
|
|
||||||
assertEqual(tree.tick(), Status.RUNNING, '第一次tick应该返回RUNNING');
|
|
||||||
assertEqual(firstCallCount, 1, '第一个Action应该执行1次');
|
|
||||||
assertEqual(secondCallCount, 0, '第二个Action不应该执行');
|
|
||||||
|
|
||||||
assertEqual(tree.tick(), Status.RUNNING, '第二次tick应该从第一个节点继续');
|
|
||||||
assertEqual(firstCallCount, 2, '第一个Action应该执行2次');
|
|
||||||
assertEqual(secondCallCount, 0, '第二个Action仍不应该执行');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('Parallel节点 - FAILURE优先级最高', () => {
|
|
||||||
reset();
|
|
||||||
const parallel = new Parallel(
|
|
||||||
new Action(() => Status.SUCCESS),
|
|
||||||
new Action(() => Status.FAILURE),
|
|
||||||
new Action(() => Status.RUNNING)
|
|
||||||
);
|
|
||||||
const tree = new BehaviorTree(testEntity, parallel);
|
|
||||||
assertEqual(tree.tick(), Status.FAILURE, 'Parallel有FAILURE应该返回FAILURE');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('Parallel节点 - RUNNING次优先级', () => {
|
|
||||||
reset();
|
|
||||||
const parallel = new Parallel(
|
|
||||||
new Action(() => Status.SUCCESS),
|
|
||||||
new Action(() => Status.RUNNING),
|
|
||||||
new Action(() => Status.SUCCESS)
|
|
||||||
);
|
|
||||||
const tree = new BehaviorTree(testEntity, parallel);
|
|
||||||
assertEqual(tree.tick(), Status.RUNNING, 'Parallel有RUNNING无FAILURE应该返回RUNNING');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('ParallelAnySuccess节点 - SUCCESS优先级最高', () => {
|
|
||||||
reset();
|
|
||||||
const parallel = new ParallelAnySuccess(
|
|
||||||
new Action(() => Status.SUCCESS),
|
|
||||||
new Action(() => Status.FAILURE),
|
|
||||||
new Action(() => Status.RUNNING)
|
|
||||||
);
|
|
||||||
const tree = new BehaviorTree(testEntity, parallel);
|
|
||||||
assertEqual(tree.tick(), Status.SUCCESS, 'ParallelAnySuccess有SUCCESS应该返回SUCCESS');
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('\n📋 4. Decorator节点测试');
|
|
||||||
|
|
||||||
runTest('Inverter节点 - 反转SUCCESS', () => {
|
|
||||||
reset();
|
|
||||||
const inverter = new Inverter(new Action(() => Status.SUCCESS));
|
|
||||||
const tree = new BehaviorTree(testEntity, inverter);
|
|
||||||
assertEqual(tree.tick(), Status.FAILURE, 'Inverter应该将SUCCESS反转为FAILURE');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('Inverter节点 - 反转FAILURE', () => {
|
|
||||||
reset();
|
|
||||||
const inverter = new Inverter(new Action(() => Status.FAILURE));
|
|
||||||
const tree = new BehaviorTree(testEntity, inverter);
|
|
||||||
assertEqual(tree.tick(), Status.SUCCESS, 'Inverter应该将FAILURE反转为SUCCESS');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('LimitTicks节点 - 次数限制内成功', () => {
|
|
||||||
reset();
|
|
||||||
let executeCount = 0;
|
|
||||||
const limitTicks = new LimitTicks(
|
|
||||||
new Action(() => {
|
|
||||||
executeCount++;
|
|
||||||
return Status.SUCCESS;
|
|
||||||
}),
|
|
||||||
3
|
|
||||||
);
|
|
||||||
const tree = new BehaviorTree(testEntity, limitTicks);
|
|
||||||
|
|
||||||
assertEqual(tree.tick(), Status.SUCCESS, '限制内应该返回SUCCESS');
|
|
||||||
assertEqual(executeCount, 1, '应该执行1次');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('LimitTicks节点 - 超过次数限制', () => {
|
|
||||||
reset();
|
|
||||||
let executeCount = 0;
|
|
||||||
const limitTicks = new LimitTicks(
|
|
||||||
new Action(() => {
|
|
||||||
executeCount++;
|
|
||||||
return Status.RUNNING;
|
|
||||||
}),
|
|
||||||
2
|
|
||||||
);
|
|
||||||
const tree = new BehaviorTree(testEntity, limitTicks);
|
|
||||||
|
|
||||||
assertEqual(tree.tick(), Status.RUNNING, '第1次应该返回RUNNING');
|
|
||||||
assertEqual(tree.tick(), Status.RUNNING, '第2次应该返回RUNNING');
|
|
||||||
assertEqual(tree.tick(), Status.FAILURE, '第3次超限应该返回FAILURE');
|
|
||||||
assertEqual(executeCount, 2, '应该只执行2次');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('Repeat节点 - 指定次数重复', () => {
|
|
||||||
reset();
|
|
||||||
let executeCount = 0;
|
|
||||||
const repeat = new Repeat(
|
|
||||||
new Action(() => {
|
|
||||||
executeCount++;
|
|
||||||
return Status.SUCCESS;
|
|
||||||
}),
|
|
||||||
3
|
|
||||||
);
|
|
||||||
const tree = new BehaviorTree(testEntity, repeat);
|
|
||||||
|
|
||||||
assertEqual(tree.tick(), Status.RUNNING, '第1次应该返回RUNNING');
|
|
||||||
assertEqual(tree.tick(), Status.RUNNING, '第2次应该返回RUNNING');
|
|
||||||
assertEqual(tree.tick(), Status.SUCCESS, '第3次应该完成返回SUCCESS');
|
|
||||||
assertEqual(executeCount, 3, '应该执行3次');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('RepeatUntilSuccess节点 - 直到成功', () => {
|
|
||||||
reset();
|
|
||||||
let attempts = 0;
|
|
||||||
const repeatUntilSuccess = new RepeatUntilSuccess(
|
|
||||||
new Action(() => {
|
|
||||||
attempts++;
|
|
||||||
return attempts >= 3 ? Status.SUCCESS : Status.FAILURE;
|
|
||||||
}),
|
|
||||||
5
|
|
||||||
);
|
|
||||||
const tree = new BehaviorTree(testEntity, repeatUntilSuccess);
|
|
||||||
|
|
||||||
assertEqual(tree.tick(), Status.RUNNING, '第1次失败应该返回RUNNING');
|
|
||||||
assertEqual(tree.tick(), Status.RUNNING, '第2次失败应该返回RUNNING');
|
|
||||||
assertEqual(tree.tick(), Status.SUCCESS, '第3次成功应该返回SUCCESS');
|
|
||||||
assertEqual(attempts, 3, '应该尝试3次');
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('\n📋 5. 黑板数据存储与隔离测试');
|
|
||||||
|
|
||||||
runTest('黑板基本读写功能', () => {
|
|
||||||
reset();
|
|
||||||
const action = new Action((node) => {
|
|
||||||
node.set('test_key', 'test_value');
|
|
||||||
const value = node.get<string>('test_key');
|
|
||||||
assertEqual(value, 'test_value', '应该能读取设置的值');
|
|
||||||
return Status.SUCCESS;
|
|
||||||
});
|
|
||||||
const tree = new BehaviorTree(testEntity, action);
|
|
||||||
tree.tick();
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('黑板层级数据隔离 - 树级黑板', () => {
|
|
||||||
reset();
|
|
||||||
let rootValue: string | undefined;
|
|
||||||
let localValue: string | undefined;
|
|
||||||
|
|
||||||
const action = new Action((node) => {
|
|
||||||
node.setRoot('root_key', 'root_value');
|
|
||||||
node.set('local_key', 'local_value');
|
|
||||||
|
|
||||||
rootValue = node.getRoot<string>('root_key');
|
|
||||||
localValue = node.get<string>('local_key');
|
|
||||||
|
|
||||||
return Status.SUCCESS;
|
|
||||||
});
|
|
||||||
const tree = new BehaviorTree(testEntity, action);
|
|
||||||
tree.tick();
|
|
||||||
|
|
||||||
assertEqual(rootValue, 'root_value', '应该能读取树级数据');
|
|
||||||
assertEqual(localValue, 'local_value', '应该能读取本地数据');
|
|
||||||
assertEqual(tree.blackboard.get<string>('root_key'), 'root_value', '树级黑板应该有数据');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('黑板层级数据隔离 - 全局黑板', () => {
|
|
||||||
reset();
|
|
||||||
const action1 = new Action((node) => {
|
|
||||||
node.setGlobal('global_key', 'global_value');
|
|
||||||
return Status.SUCCESS;
|
|
||||||
});
|
|
||||||
|
|
||||||
const action2 = new Action((node) => {
|
|
||||||
const value = node.getGlobal<string>('global_key');
|
|
||||||
assertEqual(value, 'global_value', '应该能读取全局数据');
|
|
||||||
return Status.SUCCESS;
|
|
||||||
});
|
|
||||||
|
|
||||||
const tree1 = new BehaviorTree(testEntity, action1);
|
|
||||||
const tree2 = new BehaviorTree({ name: 'test2', value: 1 }, action2);
|
|
||||||
|
|
||||||
tree1.tick();
|
|
||||||
tree2.tick();
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('实体数据关联', () => {
|
|
||||||
reset();
|
|
||||||
const action = new Action((node) => {
|
|
||||||
const entity = node.getEntity<TestEntity>();
|
|
||||||
assertEqual(entity.name, 'test', '实体name应该正确');
|
|
||||||
assertEqual(entity.value, 0, '实体value应该正确');
|
|
||||||
return Status.SUCCESS;
|
|
||||||
});
|
|
||||||
const tree = new BehaviorTree(testEntity, action);
|
|
||||||
tree.tick();
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('\n📋 6. 行为树重置逻辑测试');
|
|
||||||
|
|
||||||
runTest('行为树重置清空黑板数据', () => {
|
|
||||||
reset();
|
|
||||||
const action = new Action((node) => {
|
|
||||||
node.set('test_key', 'test_value');
|
|
||||||
node.setRoot('root_key', 'root_value');
|
|
||||||
return Status.SUCCESS;
|
|
||||||
});
|
|
||||||
|
|
||||||
const tree = new BehaviorTree(testEntity, action);
|
|
||||||
tree.tick();
|
|
||||||
|
|
||||||
// 确认数据存在
|
|
||||||
assertEqual(tree.blackboard.get<string>('test_key'), 'test_value', '数据应该存在');
|
|
||||||
assertEqual(tree.blackboard.get<string>('root_key'), 'root_value', '根数据应该存在');
|
|
||||||
|
|
||||||
// 重置
|
|
||||||
tree.reset();
|
|
||||||
|
|
||||||
// 确认数据被清空
|
|
||||||
assertEqual(tree.blackboard.get<string>('test_key'), undefined, '数据应该被清空');
|
|
||||||
assertEqual(tree.blackboard.get<string>('root_key'), undefined, '根数据应该被清空');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('Memory节点重置后内存索引重置', () => {
|
|
||||||
reset();
|
|
||||||
let firstCallCount = 0;
|
|
||||||
let secondCallCount = 0;
|
|
||||||
|
|
||||||
const memSequence = new MemSequence(
|
|
||||||
new Action(() => {
|
|
||||||
firstCallCount++;
|
|
||||||
return Status.SUCCESS;
|
|
||||||
}),
|
|
||||||
new Action(() => {
|
|
||||||
secondCallCount++;
|
|
||||||
return Status.RUNNING;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const tree = new BehaviorTree(testEntity, memSequence);
|
|
||||||
|
|
||||||
// 第一次运行
|
|
||||||
assertEqual(tree.tick(), Status.RUNNING, '应该返回RUNNING');
|
|
||||||
assertEqual(firstCallCount, 1, '第一个节点应该执行1次');
|
|
||||||
assertEqual(secondCallCount, 1, '第二个节点应该执行1次');
|
|
||||||
|
|
||||||
// 第二次运行,应该从第二个节点继续
|
|
||||||
assertEqual(tree.tick(), Status.RUNNING, '应该继续返回RUNNING');
|
|
||||||
assertEqual(firstCallCount, 1, '第一个节点不应该再执行');
|
|
||||||
assertEqual(secondCallCount, 2, '第二个节点应该执行2次');
|
|
||||||
|
|
||||||
// 重置
|
|
||||||
tree.reset();
|
|
||||||
|
|
||||||
// 重置后运行,应该从第一个节点重新开始
|
|
||||||
assertEqual(tree.tick(), Status.RUNNING, '重置后应该返回RUNNING');
|
|
||||||
assertEqual(firstCallCount, 2, '第一个节点应该重新执行');
|
|
||||||
assertEqual(secondCallCount, 3, '第二个节点应该再次执行');
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('\n📋 7. 其他关键功能测试');
|
|
||||||
|
|
||||||
runTest('复杂行为树结构测试', () => {
|
|
||||||
reset();
|
|
||||||
// 构建复杂嵌套结构
|
|
||||||
const complexTree = new Selector(
|
|
||||||
new Sequence(
|
|
||||||
new Condition(() => false), // 导致Sequence失败
|
|
||||||
new Action(() => Status.SUCCESS)
|
|
||||||
),
|
|
||||||
new MemSelector(
|
|
||||||
new Inverter(new Action(() => Status.SUCCESS)), // 反转为FAILURE
|
|
||||||
new Repeat(
|
|
||||||
new Action(() => Status.SUCCESS),
|
|
||||||
2
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
const tree = new BehaviorTree(testEntity, complexTree);
|
|
||||||
|
|
||||||
assertEqual(tree.tick(), Status.RUNNING, '第一次应该返回RUNNING(Repeat第1次)');
|
|
||||||
assertEqual(tree.tick(), Status.SUCCESS, '第二次应该返回SUCCESS(Repeat完成)');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('边界情况 - 空子节点', () => {
|
|
||||||
reset();
|
|
||||||
const emptySelector = new Selector();
|
|
||||||
const emptySequence = new Sequence();
|
|
||||||
const emptyParallel = new Parallel();
|
|
||||||
|
|
||||||
const tree1 = new BehaviorTree(testEntity, emptySelector);
|
|
||||||
const tree2 = new BehaviorTree(testEntity, emptySequence);
|
|
||||||
const tree3 = new BehaviorTree(testEntity, emptyParallel);
|
|
||||||
|
|
||||||
assertEqual(tree1.tick(), Status.FAILURE, '空Selector应该返回FAILURE');
|
|
||||||
assertEqual(tree2.tick(), Status.SUCCESS, '空Sequence应该返回SUCCESS');
|
|
||||||
assertEqual(tree3.tick(), Status.SUCCESS, '空Parallel应该返回SUCCESS');
|
|
||||||
});
|
|
||||||
|
|
||||||
runTest('黑板数据类型测试', () => {
|
|
||||||
reset();
|
|
||||||
const action = new Action((node) => {
|
|
||||||
// 测试各种数据类型
|
|
||||||
node.set('string', 'hello');
|
|
||||||
node.set('number', 42);
|
|
||||||
node.set('boolean', true);
|
|
||||||
node.set('array', [1, 2, 3]);
|
|
||||||
node.set('object', { a: 1, b: 'test' });
|
|
||||||
node.set('null', null);
|
|
||||||
|
|
||||||
assertEqual(node.get<string>('string'), 'hello', 'string类型');
|
|
||||||
assertEqual(node.get<number>('number'), 42, 'number类型');
|
|
||||||
assertEqual(node.get<boolean>('boolean'), true, 'boolean类型');
|
|
||||||
|
|
||||||
const arr = node.get<number[]>('array');
|
|
||||||
assert(Array.isArray(arr) && arr.length === 3, 'array类型');
|
|
||||||
|
|
||||||
const obj = node.get<any>('object');
|
|
||||||
assertEqual(obj.a, 1, 'object属性a');
|
|
||||||
assertEqual(obj.b, 'test', 'object属性b');
|
|
||||||
|
|
||||||
assertEqual(node.get<any>('null'), null, 'null值');
|
|
||||||
|
|
||||||
return Status.SUCCESS;
|
|
||||||
});
|
|
||||||
|
|
||||||
const tree = new BehaviorTree(testEntity, action);
|
|
||||||
tree.tick();
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(`\n🎉 测试完成! 通过 ${passedTests}/${totalTests} 个测试`);
|
|
||||||
|
|
||||||
if (passedTests === totalTests) {
|
|
||||||
console.log('✅ 所有测试通过!');
|
|
||||||
|
|
||||||
console.log('\n📊 测试覆盖总结:');
|
|
||||||
console.log('✅ Action节点: 4个测试 (Action, WaitTicks, WaitTime)');
|
|
||||||
console.log('✅ Condition节点: 2个测试 (true/false条件)');
|
|
||||||
console.log('✅ Composite节点: 7个测试 (Selector, Sequence, MemSelector, Parallel等)');
|
|
||||||
console.log('✅ Decorator节点: 6个测试 (Inverter, LimitTicks, Repeat等)');
|
|
||||||
console.log('✅ 黑板功能: 4个测试 (数据存储、隔离、实体关联)');
|
|
||||||
console.log('✅ 重置逻辑: 2个测试 (数据清空、状态重置)');
|
|
||||||
console.log('✅ 其他功能: 3个测试 (复杂结构、边界情况、数据类型)');
|
|
||||||
|
|
||||||
console.log('\n🔍 验证的核心功能:');
|
|
||||||
console.log('• 所有节点类型的正确行为');
|
|
||||||
console.log('• 黑板三级数据隔离 (本地/树级/全局)');
|
|
||||||
console.log('• Memory节点的状态记忆');
|
|
||||||
console.log('• 行为树重置的完整清理');
|
|
||||||
console.log('• 复杂嵌套结构的正确执行');
|
|
||||||
console.log('• 各种数据类型的存储支持');
|
|
||||||
|
|
||||||
process.exit(0);
|
|
||||||
} else {
|
|
||||||
console.log('❌ 有测试失败!');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
main().catch(console.error);
|
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
"lib": ["es6", "dom"],
|
"lib": ["es6", "dom"],
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"experimentalDecorators": true, // 启用ES装饰器
|
"experimentalDecorators": true, // 启用ES装饰器
|
||||||
|
"emitDecoratorMetadata": true, // 启用装饰器元数据
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"strictNullChecks": true,
|
"strictNullChecks": true,
|
||||||
@@ -20,7 +21,6 @@
|
|||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"./src/**/*"
|
"./src/**/*"
|
||||||
// "libs"
|
|
||||||
],
|
],
|
||||||
// 排除
|
// 排除
|
||||||
"exclude": [
|
"exclude": [
|
||||||
|
|||||||
Reference in New Issue
Block a user