当前位置:网站首页>UnrealEngine插件中使用protobuf 链接mysql
UnrealEngine插件中使用protobuf 链接mysql
2022-06-29 18:20:00 【shuizhidaoniaaa】
UnrealEngine插件中使用protobuf 链接mysql
该章完成需求:完成项目插件,能够提供自定义的protobuf协议
步骤:编译protobuf,新建插件导入protobuf库并使用,项目工程调用插件开放的接口
准备
先把下面官方教程看懂
插件创建和使用最佳实践-模块和引擎结构
模块
第三方库
游戏模块
注意事项
UE4 调试第三方库相关问题
要点
模块是UE4的构建块。引擎是以大量模块的集合形式实现的,游戏提供自己的模块来扩充自己。
模块是通过C#源文件声明的,扩展名为.build.cs
UE4编译器默认不支持使用debug版本的第三方库。(默认选项可改)
默认生成的运行库选项为/MD,即多线程Dll[/MD]。若链接库出现XXX不匹配项: 值“0”不匹配值“2”,多半为运行库版本错误
多线程[/MT]:0
多线程调试[/MTd]:1
多线程DLL[/MD]:2
多线程调试DLL[/MDd]:3
小试牛刀
连接mysql库 unreal连接mysql
编译protobuf
坑点:protobuf 按照 README 编译出来的是 lib 静态库,网上大部分编译教程也是/MT 版本
参照protobuf编译
用cmake-gui生成vs工程,注意生成时勾选的选项,runtime=off,test=off, shared_lib=on,之后编译生成libprotobuf.dll即可
编写插件
先写个简单插件,熟练的同学直接在文件管理器里面构建文件层次,从头编写文件,不熟练的打开ue编辑器,Edit->Plugins->New Plugin->Blank建空插件,我这里命名为TestProtobuf。建完先跑一下,跑通就ok
在Public文件夹下新建文件夹Include,Library(图方便,建哪里都ok),里面丢相应的东西
添加下面两行到build.cs文件。注意这里库没有拷贝到Binaries文件夹下,不适用打包发布。
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Private", "Include"));
PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "Private", "Library", "libprotobuf.lib"));
PS:文件夹位置跟实际的的私有包含和公有包含无关,只是为了规范才将私有文件放在Private文件夹下,公有的放在Public文件夹下。可以做个test:在Public文件夹下,将protobuf源码的google文件夹与生成的pb.h文件放在同级目录下,在Build.cs文件中使用PrivateIncludePaths.Add(),此时也能通过编译
坑点:生成的 ph.h用的是<>,用PrivateInclude…后,如果 ph.cc与 google文件夹的相对位置有问题会产生许多麻烦
坑点:有时候编译后会报外部符号链接错误,特点是 StartupModule的函数错误。因为导出库要在class后面加 PLUGINNAME_API,否则使用插件会链接不到。要谨记模块会编译成库
下面随便写点做test,类只添加了一个函数
TestData.proto
syntax = "proto3";
message Account {
string name = 1; // 账户名字
string password = 2; // 密码
int32 loginType = 3; // 登陆类型,0注册 1登陆
}
class TESTPROTOBUF_API FTestProtobufModule : public IModuleInterface
{
public:
/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
void SetAccount(const FString& name, const FString& password, const int32& loginType);
Account account;
};
void FTestProtobufModule::SetAccount(const FString& name, const FString& password, const int32& loginType)
{
account.set_name(TCHAR_TO_ANSI(*name));
account.set_password(TCHAR_TO_ANSI((*password)));
account.set_logintype(loginType);
}
测试
此时插件就编写好了。先在项目的build.cs里面导入模块。这里沿用上面小试牛刀里mysql的例子,在蓝图库里里面测试
UCLASS()
class TESTPLUGIN_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category="MySQL")
static bool TestMySQL();
UFUNCTION(BlueprintCallable, Category="MySQL")
static void TestProtobuf();
};
void UMyBlueprintFunctionLibrary::TestProtobuf()
{
FTestProtobufModule ProtobufModule;
ProtobufModule.SetAccount("hui", "test", 0);
}
坑点:如果protobuf库错误,先想到有没有参照 protobuf编译,添加#define PROTOBUF_USE_DLLS
边栏推荐
- 山东大学项目实训(八)设计轮播图进入页面
- Shandong University project training (VIII) design rotation map entry page
- Us judge ruled that the former security director of Uber accused of covering up hacking must face fraud charges
- 报错Failed to allocate graph: MYRIAD device is not opened.
- 龙canvas动画
- JDBC Codes connexes
- Source code installation mavros
- How to use the low code platform of the Internet of things for service management?
- Mac: MySQL 66 questions, 20000 words + 50 pictures!
- 您好,请问mysql cdc、和postgresql cdc有官网样例吗?给个链接学习了
猜你喜欢

Adobe Premiere foundation - material nesting (animation of Tiktok ending avatar) (IX)

数据仓库模型分层ODS、DWD、DWM实战

Cannot retrieve repository metadata processing records
![报错[warning] Neural network inference was performed on socket ‘RGB’, depth frame is aligned to socket](/img/8a/ebad75daa581e22d50dddde49e1fac.jpg)
报错[warning] Neural network inference was performed on socket ‘RGB’, depth frame is aligned to socket

Adobe Premiere Basics - common video effects (cropping, black and white, clip speed, mirroring, lens halo) (XV)

山东大学项目实训(七)添加导航栏选择城市

C Primer Plus 第12章_存储类别、链接和内存管理_代码和练习题

Adobe Premiere基础-素材嵌套(制作抖音结尾头像动画)(九)

How to use an oak camera as a webcam?

How to use the oak camera on raspberry pie?
随机推荐
MySQL Enterprise Development Specification
Failed to allocate graph: myriad device is not opened
2. 银河麒麟离线模式下如何安装MySQL数据库
BeanUtils属性复制的用法
对强缓存和协商缓存的理解
如何将OAK相机当做网络摄像头使用?
jdbc认识上手
svg画圆路径动画
源码安装MAVROS
Sd6.22 summary of intensive training
Anaconda installs and configures jupyter notebook remote
什么是多范式编程语言,其中的“多范式”是什么意思?
Anaconda安装并配置jupyter notebook远程
MySQL 企業級開發規範
My first experience of remote office | community essay solicitation
Interview question 10.10 Rank of digital stream
Adobe Premiere基础-时间重映射(十)
Sister Juan takes you to learn database -- 5-day sprint Day1
Elegant writing controller (parameter verification + unified exception handling)
[daily training] 535 Encryption and decryption of tinyurl