UE4添加模块

添加模块在这篇文章里已经有详细的描述了:

https://orfeasel.com/creating-custom-modules/

但是这篇文章中少写了一个步骤:

最后要在

  <工程名>Editor.Target.cs

以及

  <工程名>.Target.cs

中做一点修改:

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

这里也要加入新的模块名称字符串。在4.21中实际测试发现只有这样才能正常编译。

下面举一例子,给一个名称为Test的工程添加一个叫做Ken的模块。

Ken.h:

#pragma once
#include "CoreMinimal.h"
#include "ModuleManager.h"
class FKen:public IModuleInterface
{
    public:
    /** IModuleInterface implementation */
    virtual void StartupModule() override;
    virtual void ShutdownModule() override;
};

Ken.cpp:

#include "Ken.h"
#include "Modules/ModuleManager.h"
#define LOCTEXT_NAMESPACE "FKen"
void FKen::StartupModule()
{    
UE_LOG(LogTemp, Warning, TEXT("KEN MODULE Start"));
}
void FKen::ShutdownModule()
{
    UE_LOG(LogTemp, Warning, TEXT("KEN MODULE End"));
}
IMPLEMENT_MODULE(FKen, Ken)
#undef LOCTEXT_NAMESPACE

Ken.Build.cs文件:

// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
public class Ken : ModuleRules
{
    public Ken(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[]
            {
                "Test",
                "Projects",
                "InputCore",
                "UnrealEd",
                "LevelEditor",
                "CoreUObject",
                "Engine",
                // ... add private dependencies that you statically link with here ...    
            }
            );
        DynamicallyLoadedModuleNames.AddRange(
            new string[]
            {
                // ... add any modules that your module loads dynamically here ...
            }
            );
    }
}

Test.Target.cs文件:

using UnrealBuildTool;
using System.Collections.Generic;

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

        ExtraModuleNames.AddRange( new string[] { "Test","Ken" } );
    }
}

TestEditor.Target.cs文件:

using UnrealBuildTool;
using System.Collections.Generic;

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

        ExtraModuleNames.AddRange( new string[] { "Test","Ken" } );
    }
}

 

 

请使用手机"扫一扫"x

posted @ 2019-04-04 14:17  Ken_An  阅读(2738)  评论(0编辑  收藏  举报