owl bt
1.0.0
owl-bt 是行为树的编辑器。它在某种程度上受到虚幻引擎行为树的启发,它支持装饰器和服务等特殊节点项。这使得树更小并且更具可读性。
创建 owl-bt 是因为我们需要为我们的游戏 Tendril:Echo Received 提供一个行为树编辑器,我们专注于实时 npc 行为。
我们尝试了一些现有的解决方案,但它们还不能满足我们的要求,例如:
npm install owl-bt -g
owlbt -h
cd < project-dir >
owlbt i
owlbt c < tree-path >
owlbt o path
默认情况下,owl-bt 作为服务在端口8955
上运行。这可以在配置文件.owlbtrc
中更改,该文件必须在用户的主目录中创建。
{
"port" : 1234
}
在owl-bt中,共有三种类型的项目:
ctrl+shift+p
访问项目文件 ( owl-bt.json
) 定义了可在树中使用的所有节点和节点项类型。
fa-
前缀){{PropertyName}}
的占位符fa-
前缀){{PropertyName}}
的占位符fa-
前缀){{PropertyName}}
的占位符允许定义自定义属性类型
例子:
{
"types" :{
"myString" : {
"type" : " string " ,
"pattern" : " v[0-9] "
}
},
"nodes" : [
{
"name" : " SetAlertLevel " ,
"icon" : " exclamation " ,
"description" : " Set alert level to " {{Level}} " " ,
"isComposite" : false ,
"properties" : [
{
"name" : " Level " ,
"default" : " None " ,
"type" : " enum " ,
"values" : [
" None " ,
" Investigate " ,
" HighAlert " ,
" Panic "
]
}
]
}
],
"decorators" : [
{
"name" : " HasZoneReportedEnemy " ,
"icon" : " phone " ,
"properties" : [
{
"name" : " MaxReportAge " ,
"default" : 1 ,
"type" : " number "
}
]
}
],
"services" : [
{
"name" : " ReadPlayerPos " ,
"icon" : " pencil " ,
"description" : " Store player pos to " {{BlackboardKey}} " " ,
"properties" : [
{
"name" : " BlackboardKey " ,
"default" : " Target " ,
"type" : " string "
}
]
}
]
}
{
"type" : " Selector " ,
"name" : " rootNode " ,
"childNodes" : [
{
"type" : " Sequence " ,
"services" : [
{
"type" : " Sample service "
}
],
"decorators" : [
{
"type" : " IsBlackboardValueSet " ,
"properties" : [
{
"name" : " Field " ,
"value" : " myValue "
}
],
"periodic" : true
}
]
}
]
}
可以使用base
设置从另一种类型派生节点项类型。
可以使用string
或array of strings
进行base
设置。如果是数组,则按指定顺序应用基本项类型。这意味着后面的项目类型会覆盖之前指定的项目。
等式我们可以创建一个基本节点:
{
"name" : " MyBaseNode " ,
"icon" : " arrow-right " ,
"color" : " red " ,
"isAbstract" : true ,
"properties" : [
{
"name" : " prop-from-base1 " ,
"type" : " string "
},
{
"name" : " prop-from-base2 " ,
"type" : " number "
}
]
},
以及派生节点:
{
"name" : " MyDerivedNode " ,
"color" : " blue " ,
"base" : " MyBaseNode " ,
"properties" : [
{
"name" : " prop1 " ,
"type" : " string "
},
{
"name" : " prop-from-base2 " ,
"default" : " abc " ,
"type" : " string "
}
]
},
应用继承后的结果节点将如下所示:
{
"name" : " MyDerivedNode " ,
"icon" : " arrow-right " ,
"color" : " blue " ,
"base" : " MyBaseNode " ,
"properties" : [
{
"name" : " prop-from-base1 " ,
"type" : " string "
},
{
"name" : " prop-from-base2 " ,
"default" : " abc " ,
"type" : " string "
},
{
"name" : " prop1 " ,
"type" : " string "
}
]
},
与项目文件owl-bt.json
位于同一目录中的owl-bt.js
文件被视为插件。插件js文件导出带有插件功能的对象。
module . exports = {
onTreeSave : ( { tree , path , project , projectPath } ) => {
} ,
onTreeLoad : ( { tree , path , project , projectPath } ) => {
}
}
onTreeSave
- 在将树 json 文件保存到磁盘之前执行。只允许修改tree
对象。tree
- 树对象(根据树 json 文件)path
- 树文件路径project
- 项目对象(根据owl-bt.json
文件)projectPath
- 项目文件路径return
- 当返回值为false
或字符串时,则阻止保存并将错误返回给客户端onTreeLoad
- 从磁盘加载树 json 文件后执行。只允许修改tree
对象。tree
- 树对象(根据树 json 文件)path
- 树文件路径project
- 项目对象(根据owl-bt.json
文件)projectPath
- 项目文件路径例如,可以使用onTreeSave
和onTreeLoad
创建自定义树文件格式。如果我们想将项目路径存储在树文件中,我们可以创建以下插件:
module . exports = {
onTreeSave : ( { tree , path , project , projectPath } ) => {
tree . projectPath = projectPath ;
}
}
base
和isAbstract
属性ctrl+shift+p
-> 'core:Set Node Type'
或rmb
-> 'Set Node Type'
)