找回密码
 立即注册
查看: 320|回复: 1

第3期(1):UE4插件编写技巧(2)

[复制链接]
发表于 2022-1-11 18:53 | 显示全部楼层 |阅读模式
1. 在编译打包你的UE4插件时,包含插件中的其他文件夹和文件

为了在打包你的UE4插件时(这里指的是只编译打包插件,而不是指的是打包你的虚幻工程项目),包含你在该插件中添加的其他文件夹和文件,你需要在你的插件文件夹中包含一个“Config”文件夹,在该“Config”文件夹中包含一个“FilterPlugin.ini”文件。该文件的内容类似于:
[FilterPlugin]
; This section lists additional files which will be packaged along with your plugin. Paths should be listed relative to the root plugin directory, and
; may include "...", "*", and "?" wildcards to match directories, files, and individual characters respectively.
;
; Examples:
;    /README.txt
;    /Extras/...
;    /Binaries/ThirdParty/*.dll
/README.txt
/Extras/...
/Binaries/ThirdParty/*.dll
你可以采用下图的方法打包你的插件(点击下图中的“Package...”按钮):



参考:
【1】:Plugins
【2】: Marketing FAQ

2. 在编译打包你的UE4工程项目时,包含你的插件中的第三方DLL文件

为了在打包你的UE4工程项目时,让UE4自动把你的插件中的第三方(ThirdParty)DLL文件一起打包,你需要在插件模块的对应“*.Build.cs”文件中添加如下代码:
RuntimeDependencies.Add(new RuntimeDependency(Path.Combine(ThirdPartyDLLDirectory, "QRCodeSDK.dll")));

完整例子如下所示:

/*
*  Copyright (c) 2016-2017 YeHaike(841660657@qq.com).
*  All rights reserved.
*  @ Date : 2017/05/11
*
*/
using System;
using System.IO;
using UnrealBuildTool;

public class QRCodeUE4Library : ModuleRules
{
    public QRCodeUE4Library(ReadOnlyTargetRules Target) : base(Target)
    {
        Type = ModuleType.External;

        string PluginDirectory = Path.GetFullPath(Path.Combine(ModuleDirectory, "..", "..", ".."));
        string ThirdPartyDLLDirectory = Path.Combine(PluginDirectory, "Binaries\\ThirdParty", Path.GetFileName(ModuleDirectory), Target.Platform.ToString());
        Console.WriteLine("ThirdPartyDLLDirectory: " + ThirdPartyDLLDirectory);
        if (Target.Platform == UnrealTargetPlatform.Win64)
        {
            // Add the import library
            PublicLibraryPaths.Add(Path.Combine(ModuleDirectory, "QRCodeSDK\\QRCodeSDK\\x64", "Release"));
            // Console.WriteLine(Path.Combine(ModuleDirectory, "QRCodeSDK\\QRCodeSDK\\x64", "Release"));
            PublicAdditionalLibraries.Add("QRCodeSDK.lib");

            // Delay-load the DLL, so we can load it from the right place first
            PublicDelayLoadDLLs.Add("QRCodeSDK.dll");
            // List of files which this module depends on at runtime. These files will be staged along with the target.
            RuntimeDependencies.Add(new RuntimeDependency(Path.Combine(ThirdPartyDLLDirectory, "QRCodeSDK.dll")));
        }
        else if (Target.Platform == UnrealTargetPlatform.Mac)
        {
            PublicDelayLoadDLLs.Add(Path.Combine(ModuleDirectory, "Mac", "Release", "libQRCodeSDK.dylib"));
        }
    }
}

<hr/>3. 提交UE4插件到虚幻商城上,插件Demo的“.uproject”中,需要添加如下代码:

"Plugins": [
                {
                        "Name": "HiSQLite3",
                        "Enabled": true,
                        "MarketplaceURL": "com.epicgames.launcher://ue/marketplace/content/c8c0f3c46971495b8a8d400ec8627caa"
                }
        ]
插件Demo的“.uproject”文件可以参考如下内容:
{
        "FileVersion": 3,
        "EngineAssociation": "4.18",
        "Category": "",
        "Description": "",
        "Modules": [
                {
                        "Name": "HiSQLite3_UE4Demo",
                        "Type": "Runtime",
                        "LoadingPhase": "Default",
                        "AdditionalDependencies": [
                                "Engine"
                        ]
                }
        ],
        "Plugins": [
                {
                        "Name": "HiSQLite3",
                        "Enabled": true,
                        "MarketplaceURL": "com.epicgames.launcher://ue/marketplace/content/c8c0f3c46971495b8a8d400ec8627caa"
                }
        ]
}
-----------------------------------------------------------------------------------------------
更新列表:

  • YeHaike(2017-12-06):添加《1. 在你的UE4插件中包含其他文件夹和文件》;
  • YeHaike(2017-12-06):添加《2. 在编译打包你的UE4工程项目时,包含你的插件中的第三方DLL文件》;
  • YeHaike(2018-01-27):添加《3. 提交UE4插件到虚幻商城上,插件Demo的“.uproject”中,需要添加如下代码》
-----------------------------------------------------------------------------------------------

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
发表于 2022-1-11 18:59 | 显示全部楼层
解决了问题.....
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-4-29 01:39 , Processed in 0.114673 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表