上一篇已经创建了角色和角色代理,要加载到STAGE场景编辑器,或要被GameManager识别,还需要创建一个角色注册器,这篇就来介绍角色注册器并编译角色库导入到STAGE中使用
6、在场景编辑器中加载角色
创建角色注册器
要创建角色注册器,很简单,只需要创建一个类并继承至dtCore::ActorPluginRegistry并实现特定的方法即可,见以下代码(原文中继承的是dtDAL,由于dtDAL并入到了dtCore,因此需要改为dtCore)
// ActorsRegistry.h
#ifndef ActorsRegistry_h__
#define ActorsRegistry_h__
#include "delta3d_export.h"
#include <dtCore/actorpluginregistry.h>
// 一个角色注册器可以注册多个角色
class DELTA3D_EXPORT ActorsRegistry : public dtCore::ActorPluginRegistry
{
public:
ActorsRegistry();
// 在此函数中注册角色类型
virtual void RegisterActorTypes() override;
};
#endif // ActorsRegistry_h__
下面是实现:
// ActorsRegistry.cpp
#include "ActorsRegistry.h"
#include "HoverTankActorProxy.h"
// 下面的Create和Destory是告诉STAGE和GameManager函数入口点,可以通过宏进行封装
extern "C" DELTA3D_EXPORT dtCore::ActorPluginRegistry *CreatePluginRegistry()
{
return new ActorsRegistry();
}
extern "C" DELTA3D_EXPORT void DestroyPluginRegistry(dtCore::ActorPluginRegistry *registry)
{
delete registry;
}
ActorsRegistry::ActorsRegistry()
: dtCore::ActorPluginRegistry("Actors")
{
SetDescription("this is an actors registry");
}
void ActorsRegistry::RegisterActorTypes()
{
dtCore::RefPtr<dtCore::ActorType> actorType = new dtCore::ActorType(
"HoverTank",
"Actors",
"description of actortype");
this->mActorFactory->RegisterType<HoverTankActorProxy>(actorType);
}
这时进行编译,成功后会在输出目录生成一个dll文件,如下:
启动STAGE场景编辑器
首先配置下输出目录下的文件,即将delta3d生成的所有依赖库进行集中。
将Delta3D(1)VS2010+Qt4.8.7环境编译Delta3D
最后生成的build/bin目录下的所有文件都拷贝到角色库输出路径下面,如下:
同时将源码文件夹中example目录下的data文件夹全部拷贝到上面的Debug文件夹下与data文件夹进行合并。
这时打开Debug目录下的STAGEd.exe文件启动STAGE场景编辑器,启动后如下图:
如果启动时,报以下关于Qt库的错,则需要在系统环境变量Path中添加Qt4的bin目录,如下:
导入角色库
1、切换工程目录
2、创建一个map
3、导入角色库
成功导入后,在场景编辑器中的Actors标签页中的Actors节点下展开就会法线我们创建的角色HoverTank
4、使用角色
拖动HoverTank节点到中间的视景中,即可添加一个HoverTank Actor到场景中,选中此Actor,在PropertyEditor标签中,可修改属性,如图,修改了GameMesh,即物理模型,对应视景图中则显示相应的物理模型。
至此,角色创建并导入到STAGE中使用就介绍完了。
同时就学会的怎么创建角色,怎么导入到场景编辑器中使用。
以后的文章则会根据不同的功能点进行介绍。。。基础的部分就到这里。