behaviac是游戏AI的开发框架组件,也是游戏原型的快速设计工具。支持全平台,适用于客户端和服务器,助力游戏快速迭代开发 。c++
编辑器能够运行在PC上,操做方便直观可靠,支持实时和离线调试;编辑器能够导出xml,bson等多种格式,更能够导出C++、C#源码,提供最高效率。git
运行时支持全平台,有C++和C#两个版本,原生支持Unity。程序员
已被多款知名游戏及更多其余预研项目使用。github
全部代码,包括编辑器和运行时所有开源https://github.com/Tencent/behaviacc#
behaviac做为游戏AI的开发框架组件,有编辑器和运行时两个部分,这两个部分经过类型信息(描述AI实例属性和能力方法的信息)交换信息。安全
类型信息用来描述类型的属性和方法。在3.5及以前的旧版本经过运行时端导出类型信息,3.6及以后的新版本经过编辑器建立类型信息,以下所示。编辑器中,该类型信息做为基本的语法单位用来建立行为树。服务器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<agent classfullname=
"framework::GameObject"
base=
"behaviac::Agent"
inherited=
"true"
DisplayName=
""
Desc=
""
IsRefType=
"true"
>
<Member Name=
"HP"
DisplayName=
""
Desc=
""
Type=
"uint"
Class=
"framework::GameObject"
/>
<Member Name=
"age"
DisplayName=
""
Desc=
""
Type=
"long"
Class=
"framework::GameObject"
/>
<Method Name=
"GoStraight"
DisplayName=
""
Desc=
""
Class=
"framework::GameObject"
ReturnType=
"void"
>
<Param DisplayName=
"speed"
Desc=
"speed"
Type=
"int"
/>
</Method>
<Method Name=
"TurnTowardsTarget"
DisplayName=
""
Desc=
""
Class=
"framework::GameObject"
ReturnType=
"int"
>
<Param DisplayName=
"turnSpeed"
Desc=
"turnSpeed"
Type=
"float"
/>
</Method>
<Method Name=
"alignedWithPlayer"
DisplayName=
""
Desc=
""
Class=
"framework::GameObject"
ReturnType=
"bool"
/>
<Method Name=
"playerIsAligned"
DisplayName=
""
Desc=
""
Class=
"framework::GameObject"
ReturnType=
"bool"
/>
<Method Name=
"projectileNearby"
DisplayName=
""
Desc=
""
Class=
"framework::GameObject"
ReturnType=
"bool"
>
<Param DisplayName=
"radius"
Desc=
"radius"
Type=
"float"
/>
</Method>
<Method Name=
"distanceToPlayer"
DisplayName=
""
Desc=
""
Class=
"framework::GameObject"
ReturnType=
"float"
/>
</agent>
|
在3.x版本以前的版本中,类型信息必须经过运行时来导出,策划须要新的属性或方法时,必须等待程序员更新代码重现导出类型信息后才能使用。而在3.x版本中,能够直接在编辑器中建立一个类型,而且建立它的属性和方法,并且能够导出类型的c++或c#源码,这极大的加速了迭代的过程,从而把编辑器做为一个原型设计工具。网络
编辑器是一个能够运行在Windows平台上的编辑工具。
在编辑器内,使用鼠标或快捷键,能够添加、编辑、配置、修改行为树(包括FSM,或HTN),也能够实时或离线调试游戏的行为,既能够设断点,也能够查看或修改变量的值。框架
运行时有C++和C#两个版本,Unity使用C#的实现,像是cocos等使用C++的引擎或平台使用C++的实现。其具体逻辑是一致的,即加载编辑器中导出的行为树,解释运行之。socket
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
g_player = behaviac::Agent::Create<CBTPlayer>();
bool
bRet =
false
;
bRet = g_player->btload(pszTreeName);
assert
(bRet);
g_player->btsetcurrent(pszTreeName);
behaviac::EBTStatus status = behaviac::BT_RUNNING;
while
(status == behaviac::BT_RUNNING)
{
status = g_player->btexec();
}
|
在编辑器内建立好行为后,须要导出,而后运行时才能够加载运行。编辑器支持导出多种格式:
其中xml和bson做为数据,能够被加载,而cpp或c#做为源码直接编辑连接进程序,用户能够根据须要选择使用最合适的格式。