要将源码中的非运行时模块移植到Runtime下使用,需要将目标模块复制到项目的source目录内,修改模块文件夹名称
修改模块.build.cs与文件夹名称保持一致
修改build.cs内的类名
刷新项目后修改项目.uproject文件,添加启动模块
在项目build.cs中添加依赖项
修改模块中的Mode.h,Mode.cpp中的类名
修改模块中的include路径
//#include "DesktopPlatformModule.h" #include "DesktopPlatformRuntime/Public/DesktopPlatformRuntimeModule.h"
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "DesktopPlatformRuntime/Public/IDesktopPlatformRuntime.h"
#include "Modules/ModuleInterface.h"
#include "Modules/ModuleManager.h"
class IDesktopPlatformRuntime;
class FDesktopPlatformRuntimeModule : public IModuleInterface
{
public:
virtual void StartupModule();
virtual void ShutdownModule();
static IDesktopPlatformRuntime* Get()
{
FDesktopPlatformRuntimeModule& DesktopPlatformModule = FModuleManager::Get().LoadModuleChecked<FDesktopPlatformRuntimeModule>("DesktopPlatform");
return DesktopPlatformModule.GetSingleton();
}
static IDesktopPlatformRuntime* TryGet()
{
if (FDesktopPlatformRuntimeModule* DesktopPlatformModule = FModuleManager::Get().LoadModulePtr<FDesktopPlatformRuntimeModule>("DesktopPlatform"))
{
return DesktopPlatformModule->GetSingleton();
}
return nullptr;
}
private:
virtual IDesktopPlatformRuntime* GetSingleton() const { return DesktopPlatform; }
IDesktopPlatformRuntime* DesktopPlatform;
};
// Copyright Epic Games, Inc. All Rights Reserved.
//#include "DesktopPlatformModule.h"
#include "DesktopPlatformRuntime/Public/DesktopPlatformRuntimeModule.h"
#include "DesktopPlatformPrivate.h"
#include "Null/NullPlatformApplicationMisc.h"
IMPLEMENT_MODULE( FDesktopPlatformRuntimeModule, DesktopPlatform );
DEFINE_LOG_CATEGORY(LogDesktopPlatform);
void FDesktopPlatformRuntimeModule::StartupModule()
{
DesktopPlatform = FDesktopPlatformRuntimeModule::Get();
//if(FNullPlatformApplicationMisc::IsUsingNullApplication())
//{
// DesktopPlatform = new FDesktopPlatformNull();
//}
//else
//{
// DesktopPlatform = new FDesktopPlatform();
//}
FPlatformMisc::SetEnvironmentVar(TEXT("UE_DesktopUnrealProcess"), TEXT("1"));
}
void FDesktopPlatformRuntimeModule::ShutdownModule()
{
FPlatformMisc::SetEnvironmentVar(TEXT("UE_DesktopUnrealProcess"), TEXT("0"));
if (DesktopPlatform != NULL)
{
delete DesktopPlatform;
DesktopPlatform = NULL;
}
}