当前位置:   article > 正文

ue4打包多模块

ue4打包多模块

首先,每个模块,包含插件内的模块在内,都要用IMPLEMENT_MODULE(类名, 模块名)的方式,模块名就是带.build.cs的第一个单词。

build.cs里就说了这个模块该怎么用,用c#编写。

打包中要考虑到target.cs,将工程中相应的模块打包进去
uproject就要连插件和模块一起写进去

比如
在这里插入图片描述

这里,CoreOne和CoreTwo是工程里的多模块,myplugin和otherM是插件里的多模块。废话不多说,上代码

以工程中的一个模块CoreOne为例

coreOne.h

#pragma once

#include “CoreMinimal.h”
#include “Modules/ModuleManager.h”

class FCoreOneModule : public FDefaultGameModuleImpl
{
public:

/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
  • 1
  • 2
  • 3

};

coreone.cpp

#include “CoreOne.h”
#include “Modules/ModuleManager.h”

#define LOCTEXT_NAMESPACE “CoreOne”

void FCoreOneModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
}

void FCoreOneModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.
}

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FCoreOneModule, CoreOne);

coreone.build.cs
// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;

public class CoreOne : ModuleRules
{
public CoreOne(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

	PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine" });

	PrivateDependencyModuleNames.AddRange(new string[] {  });

	// Uncomment if you are using Slate UI
	// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
	
	// Uncomment if you are using online features
	// PrivateDependencyModuleNames.Add("OnlineSubsystem");

	// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

}
再以插件中的一个模块otherM为例
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
otherM.h
#pragma once

#include “CoreMinimal.h”
#include “Modules/ModuleManager.h”

class FOtherMModule : public IModuleInterface
{
public:

/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
  • 1
  • 2
  • 3

};

otherM.cpp
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.

#include “OtherM.h”

#define LOCTEXT_NAMESPACE “OtherM”

void FOtherMModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
}

void FOtherMModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.
}

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FOtherMModule, OtherM)

otherM.build.cs
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;

public class OtherM : ModuleRules
{
public OtherM(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 ...	
		}
		);
	
	
	DynamicallyLoadedModuleNames.AddRange(
		new string[]
		{
			// ... add any modules that your module loads dynamically here ...
		}
		);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42

}

同样myplugin模块也是如此
myplugin.h
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.

#pragma once

#include “CoreMinimal.h”
#include “Modules/ModuleManager.h”

class FMyPluginModule : public IModuleInterface
{
public:

/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
  • 1
  • 2
  • 3

};

myplugin.cpp
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.

#include “MyPlugin.h”

#define LOCTEXT_NAMESPACE “FMyPluginModule”

void FMyPluginModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
}

void FMyPluginModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.
}

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FMyPluginModule, MyPlugin)

加上一个蓝图能调用的类,用以测试

DllTask.h

#pragma once

#include “CoreMinimal.h”
#include “GameFramework/pawn.h”
#include “DllTask.generated.h”

/**
*
*/
UCLASS(Blueprintable, BlueprintType)
class MYPLUGIN_API ADllTask : public APawn
{
GENERATED_BODY()

public:
UFUNCTION(BlueprintCallable, Category = “Dll”)
void HelloDLL();
};

DllTask.cpp
#include “DllTask.h”
#include <Engine.h>
void ADllTask::HelloDLL()
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 200.0f, FColor::Blue, TEXT(“Hello Dll”));
}
}
PluginTest.Target.cs
// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;
using System.Collections.Generic;

public class PluginTestTarget : TargetRules
{
public PluginTestTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game;

	ExtraModuleNames.AddRange( new string[] { "PluginTest", "CoreOne", "CoreTwo" } );
}
  • 1
  • 2

}
PluginTestEditor.Target.cs
// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;
using System.Collections.Generic;

public class PluginTestEditorTarget : TargetRules
{
public PluginTestEditorTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Editor;

	ExtraModuleNames.AddRange( new string[] { "PluginTest", "CoreOne", "CoreTwo" } );
}
  • 1
  • 2

}
PluginTest.uproject

{
“FileVersion”: 3,
“EngineAssociation”: “4.22”,
“Category”: “”,
“Description”: “”,
“Modules”: [
{
“Name”: “PluginTest”,
“Type”: “Runtime”,
“LoadingPhase”: “Default”
},
{
“Name”: “CoreOne”,
“Type”: “Runtime”,
“LoadingPhase”: “Default”
},
{
“Name”: “CoreTwo”,
“Type”: “Runtime”,
“LoadingPhase”: “Default”
}
],

“Plugins”: [
{
“Name”: “MyPlugin”,
“Enabled” : true
}
]
}

现在编辑器里试验下
设置默认地图为newmap
在这里插入图片描述
将dlltask拖进场景
在这里插入图片描述

打开关卡蓝图测试
在这里插入图片描述
运行正常
在这里插入图片描述
现在开始打包,先烘培
在这里插入图片描述
在这里插入图片描述
再打包64位windows
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
找到打包位置,双击打开
在这里插入图片描述
在这里插入图片描述
ok

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号