金融网站建设方案网站建设 在线购买
web/
2025/9/26 13:20:45/
文章来源:
金融网站建设方案,网站建设 在线购买,云南网站建设定做,制作公众号的编辑器本篇博文介绍了#xff0c;如果在UE 中如何使用第三方库#xff0c;及制作成插件的方法。 DLL 文件是上篇文章中创键的具体的方法见上篇文章。下面开始介绍方法 首先#xff0c;创建一个空白的 UE5 C 项目#xff0c;然后再创建一个空白内容的插件#xff0c;如下图所示 …本篇博文介绍了如果在UE 中如何使用第三方库及制作成插件的方法。 DLL 文件是上篇文章中创键的具体的方法见上篇文章。下面开始介绍方法 首先创建一个空白的 UE5 C 项目然后再创建一个空白内容的插件如下图所示
修改UeWllApi.uplugin 里面的内容 如下图所示 在 插件的文件夹中 添加文件夹及DLL,LIB,.H 文件注意具体的路径不要错否则可能插件制作不成功如下图所示 首先在插件中添加一个ThridParty的文件夹文件夹名字不要错如下图所示 然后在ThridParty 内再添加一个文件夹WllApi如下图所示 然后在 WllApi 里面添加三个文件夹 bin,inc,lib(名字不要错)如下图所示 然后再bin ,lib分别添加x64 文件夹 inc 里面添加WllApi 文件夹 如下图所示 然后再bin ,lib,的x64文件夹下添加 Debug,Release 文件夹然后在Debug,Release 里面添加对应的Dll ,lib文件在inc 里面的WllApi文件夹下添加需要的头文件.如下图所示 在 插件的的Build.cs UeWllApi.Build.cs中添加以下代码
// Copyright Epic Games, Inc. All Rights Reserved.
using System.IO;
using UnrealBuildTool;public class UeWllApi : ModuleRules
{public UeWllApi(ReadOnlyTargetRules Target) : base(Target){PCHUsage ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;PublicIncludePaths.AddRange(new string[] {// ... add public include paths required here ...});PrivateIncludePaths.AddRange(new string[] {// ... add other private include paths required here ...});PublicDependencyModuleNames.AddRange(new string[]{Core,// ... add other public dependencies that you statically link with here ...});PrivateDependencyModuleNames.AddRange(new string[]{CoreUObject,Engine,Slate,SlateCore,// ... add private dependencies that you statically link with here ... Projects});DynamicallyLoadedModuleNames.AddRange(new string[]{// ... add any modules that your module loads dynamically here ...});LoadPlugins(Target);}public void LoadPlugins(ReadOnlyTargetRules Target){bool bSupport false;string BinPath , LibPath ;//初始化BIN,LIB路径为空string PluginPath Path.Combine(ThridParty, WllApi);PrivateIncludePaths.Add(Path.Combine(PluginDirectory,PluginPath,inc));if(Target.PlatformUnrealTargetPlatform.Win64){if(Target.ConfigurationUnrealTargetConfiguration.Debug){BinPath Path.Combine(PluginPath, bin, x64, Debug);LibPath Path.Combine(PluginPath, lib, x64, Debug);}else{BinPath Path.Combine(PluginPath, bin, x64, Release);LibPath Path.Combine(PluginPath, lib, x64, Release);}bSupport true;}if(bSupport){PublicAdditionalLibraries.Add(Path.Combine(PluginDirectory, LibPath, FirstDll.lib));PublicDelayLoadDLLs.Add(FirstDll.dll);RuntimeDependencies.Add(Path.Combine($(PluginDir), BinPath, FirstDll.dll));}}
}
还有要注意添加 “Projects” 模块 具体结果如下图所示
在UeWllApi.h中添加以下代码如下图所示
public :static constexpr wchar_t* ModuleName{ LUeWllApi };//插件的名字
public:/** IModuleInterface implementation */virtual void StartupModule() override;virtual void ShutdownModule() override;
public:static FName GetModularFeatureName(){static FName FeatureName FName(ModuleName);return FeatureName;}static inline IModuleInterface Get(){return FModuleManager::LoadModuleCheckedIModuleInterface(ModuleName);}static inline bool IsAvailable()//是否可以获得{return FModuleManager::Get().IsModuleLoaded(ModuleName);}
private:FString GetLibaryPath();void* LibraryHandle nullptr;在UeWllApi.cpp中添加以下代码如下图所示
#include UeWllApi.h
#includeMisc/MessageDialog.h//消息框头文件
#include Interfaces/IPluginManager.h//插件管理头文件
#define LOCTEXT_NAMESPACE FUeWllApiModulevoid FUeWllApiModule::StartupModule()
{FString LibraryPath GetLibaryPath();LibraryHandle LibraryPath.IsEmpty() ? nullptr : FPlatformProcess::GetDllHandle(*LibraryPath);//当前的路径是否为空不为空的话获取句柄if (!LibraryHandle){FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT(ThridPartyLibraryError, Failed to load WllApi Library));}
}void FUeWllApiModule::ShutdownModule()
{FPlatformProcess::FreeDllHandle(LibraryHandle);//释放句柄LibraryHandle nullptr;
}
FString FUeWllApiModule::GetLibaryPath()
{FString BaseDir IPluginManager::Get().FindPlugin(ModuleName)-GetBaseDir();//寻找插件FString LibraryPath;
#if PLATFORM_WINDOWS
# if PLATFORM_64BITS
# if UE_BUILD_DEBUGLibraryPath FPaths::Combine(*BaseDir, TEXT(ThridParty/WllApi/bin/x64/Debug/FirstDll.dll));
# elseLibraryPath FPaths::Combine(*BaseDir, TEXT(ThridParty/WllApi/bin/x64/Release/FirstDll.dll));
# endif
# else
# if UE_BUILD_DEBUGLibraryPath FPaths::Combine(*BaseDir, TEXT(ThridParty/WllApi/bin/x86/Debug/FirstDll.dll));
# elseLibraryPath FPaths::Combine(*BaseDir, TEXT(ThridParty/WllApi/bin/x86/Release/FirstDll.dll));
# endif
# endif
#endifreturn LibraryPath;}
#undef LOCTEXT_NAMESPACEIMPLEMENT_MODULE(FUeWllApiModule, UeWllApi)添加C类型的Blueprint Function Library如下图所示运行时是插件 在UeWllApiFunctionLibrary.h 添加以下代码如下图所示
public:UFUNCTION(BlueprintCallable,CategoryUeWllApi)static int GetSum();在UeWllApiFunctionLibrary.cpp 添加以下代码 如图所示
int UUeWllApiFunctionLibrary::GetSum()
{return sum(3,4);
} 到此为止插件就制作完成了只要打包调用就可以了可以看到在本程序内可以调用结果也正确 打包出来在其他程序调用也正确结果如下图所示
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/81526.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!