好久不写文章啦,主要最近工作略忙,一直木有抽出时间来研究Unreal。
当然啦,也不会亏待大家啦。这次带来的教程有点重磅。。。。
我们讨论如何在Unreal的蓝图中调用我们预定义好的DLL。本教程分为两大部分:
一、如何创建基于C++的DLL库
方法很简单,创建工程时选择Visual C++>Win32,创建的工程名称为
CreateAndLinkDLLTut。之后在工程引导中选择DLL和空工程即可。创建完成之后添加新类。此处命名为CreateAndLinkDLL。工程目录结构如下图:
之后将下面的代码分别粘贴到.h和.cpp文件中,代码如下:
#pragma once
#define DLL_EXPORT __declspec(dllexport) //shortens __declspec(dllexport) to DLL_EXPORT
#ifdef __cplusplus //if C++ is used convert it to C to prevent C++'s name mangling of method names
extern "C"
{
#endif
bool DLL_EXPORT getInvertedBool(bool boolState);
int DLL_EXPORT getIntPlusPlus(int lastInt);
float DLL_EXPORT getCircleArea(float radius);
char DLL_EXPORT *getCharArray(char* parameterText);
float DLL_EXPORT *getVector4(float x, float y, float z, float w);
#ifdef __cplusplus
}
#endif
#pragma once
#include "string.h"
#include "CreateAndLinkDLLFile.h"
//Exported method that invertes a given boolean.
bool getInvertedBool(bool boolState)
{
return bool(!boolState);
}
//Exported method that iterates a given int value.
int getIntPlusPlus(int lastInt)
{
return int(++lastInt);
}
//Exported method that calculates the are of a circle by a given radius.
float getCircleArea(float radius)
{
return float(3.1416f * (radius * radius));
}
//Exported method that adds a parameter text to an additional text and returns them combined.
char *getCharArray(char* parameterText)
{
char* additionalText = " world!";
if (strlen(parameterText) + strlen(additionalText) + 1 > 256)
{
return "Error: Maximum size of the char array is 256 chars.";
}
char combinedText[256] = "";
strcpy_s(combinedText, 256, parameterText);
strcat_s(combinedText, 256, additionalText);
return (char*)combinedText;
}
//Exported method that adds a vector4 to a given vector4 and returns the sum.
float *getVector4(float x, float y, float z, float w)
{
float* modifiedVector4 = new float[4];
modifiedVector4[