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'
)