当前位置:网站首页>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
边栏推荐
- RocketMQ的tag过滤和sql过滤
- Notes on spintronics - zhangshufeng
- 【TcaplusDB知识库】TcaplusDB单据受理-创建业务介绍
- 如何使用物联网低代码平台进行服务管理?
- 1. 使用STM32CubeMX建立STM32G030C8T6项目工程
- Apache Doris basic usage summary
- 剑指 Offer 34. 二叉树中和为某一值的路径-dfs法
- Detailed analysis on the use of MySQL stored procedure loop
- 报错Failed to allocate graph: MYRIAD device is not opened.
- 保持jupyter notebook在终端关闭时的连接方法
猜你喜欢

Application and practice of DDD in domestic hotel transaction -- Theory

Adobe Premiere基础-常用的视频特效(裁剪,黑白,剪辑速度,镜像,镜头光晕)(十五)

龙canvas动画
Detailed analysis on the use of MySQL stored procedure loop

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

Anfulai embedded weekly report no. 271: June 20, 2022 to June 26, 2022

The 8th "Internet +" competition - cloud native track invites you to challenge

Failed to allocate graph: myriad device is not opened

如何在树莓派上使用OAK相机?

Redis(一)--Redis入门(1)--Redis介绍、安装与启动、常用配置
随机推荐
Know that Chuangyu has helped the energy industry in asset management and was selected into the 2021 IOT demonstration project of the Ministry of industry and information technology
Anaconda installs and configures jupyter notebook remote
Machine learning 7-Support vector machine
Servlet student management system (Mengxin hands-on version)
Application and practice of DDD in domestic hotel transaction -- Theory
Adobe Premiere基础-时间重映射(十)
Elegant writing controller (parameter verification + unified exception handling)
MySQL Enterprise Development Specification
Adobe Premiere foundation - batch material import sequence - variable speed and rewind (recall) - continuous action shot switching - subtitle requirements (13)
《安富莱嵌入式周报》第271期:2022.06.20--2022.06.26
Svg circle drawing path animation
熊猫跑酷js小游戏代码
面试题 10.10. 数字流的秩
Adobe Premiere Basics - common video effects (corner positioning, mosaic, blur, sharpen, handwriting tools, effect control hierarchy) (16)
WBF: new method of NMS post filter frame for detection task?
Anaconda安装并配置jupyter notebook远程
Sister Juan takes you to learn database -- 5-day sprint Day1
JWT登录验证
Understanding of strong caching and negotiation caching
Adobe Premiere foundation - opacity (mixed mode) (XII)