UE4->Plugin 认识UE4插件 2

原创文章,转载请注明出处。

本文介绍 两个知识点Plugin/Module 插件和模块的联系区别,同时介绍插件和我们的Source中创建多模块。

**

一、Plugin/Module 插件和模块的联系区别

**
1> 一个插件至少有一个模块
2>一般插件都是做底层做通用设计的,而模块做的负责的我理解为逻辑

ProjectName.Build.cs		//主要管理的是链接, dll的链接
ProjectName.Target.cs		//管理的是编译,加上才会编译你的Module, 如果你是runtime模块,放到这里
ProjectName.Editor.Target.cs	//管理的是编译,加上才会编译你的Module, 如果你的是editor模块,那么好,放这里

关于.Build.cs中的一些介绍

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

PrivateDependencyModuleNames.AddRange(new string[] {  });
PublicDependencyModuleNames 里面的所有模块都会被引用该模块的模块所继承使用,你就理解成public
PrivateDependencyModuleNames 与上面相反了,按private理解

二、在Plugin中创建多模块以及在我们的Source中创建多模块

1>我的SelectDialog插件,放置三个模块。如下图
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
2>在你的Plugin中加上你的模块引用,如下图
在这里插入图片描述
3>加上模块中的 StartupModule和ShutdownModule可以在模块初始化和模块卸载时增加你的业务逻辑,如下图

头文件.h

// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "ISlateFileDialogModuleEx.h"

class FSlateFileDialogsStyle;

class FSlateFileDialogsModule : public ISlateFileDialogsModule
{
public:

	// IModuleInterface interface

	virtual void StartupModule() override;
	virtual void ShutdownModule() override;

public:
	//ISlateFileDialogModule interface

	bool OpenFileDialog(const void* ParentWindowHandle, const FString& DialogTitle, const FString& DefaultPath,
		const FString& DefaultFile, const FString& FileTypes, uint32 Flags, TArray<FString>& OutFilenames, int32& OutFilterIndex);

	bool OpenFileDialog(const void* ParentWindowHandle, const FString& DialogTitle, const FString& DefaultPath,
		const FString& DefaultFile, const FString& FileTypes, uint32 Flags, TArray<FString>& OutFilenames);

	bool OpenDirectoryDialog(const void* ParentWindowHandle, const FString& DialogTitle, const FString& DefaultPath,
		FString& OutFoldername);

	bool SaveFileDialog(const void* ParentWindowHandle, const FString& DialogTitle, const FString& DefaultPath,
		const FString& DefaultFile, const FString& FileTypes, uint32 Flags, TArray<FString>& OutFilenames);

	ISlateFileDialogsModule* Get();

	FSlateFileDialogsStyle *GetFileDialogsStyle() { return FileDialogStyle; }

private:
	ISlateFileDialogsModule *SlateFileDialog;

	FSlateFileDialogsStyle	*FileDialogStyle;
};

实现.cpp

// Copyright Epic Games, Inc. All Rights Reserved.

#include "CoreMinimal.h"
#include "Modules/ModuleManager.h"
#include "SlateFileDialogsEx.h"
#include "SlateFileDialogsStylesEx.h"
#include "SlateFileDlgWindowEx.h"

void FSlateFileDialogsModule::StartupModule()
{
	SlateFileDialog = new FSlateFileDialogsModule();

	FileDialogStyle = new FSlateFileDialogsStyle;
	FileDialogStyle->Initialize();
}


void FSlateFileDialogsModule::ShutdownModule()
{
	if (SlateFileDialog != NULL)
	{
		FileDialogStyle->Shutdown();
		delete FileDialogStyle;

		delete SlateFileDialog;
		SlateFileDialog = NULL;
	}
}


bool FSlateFileDialogsModule::OpenFileDialog(const void* ParentWindowHandle, const FString& DialogTitle, const FString& DefaultPath,
		const FString& DefaultFile, const FString& FileTypes, uint32 Flags, TArray<FString>& OutFilenames, int32& OutFilterIndex)
{
	FSlateFileDlgWindow dialog(FileDialogStyle);
	return dialog.OpenFileDialog(ParentWindowHandle, DialogTitle, DefaultPath, DefaultFile, FileTypes, Flags, OutFilenames, OutFilterIndex);
}


bool FSlateFileDialogsModule::OpenFileDialog(const void* ParentWindowHandle, const FString& DialogTitle, const FString& DefaultPath,
		const FString& DefaultFile, const FString& FileTypes, uint32 Flags, TArray<FString>& OutFilenames)
{
	FSlateFileDlgWindow dialog(FileDialogStyle);
	return dialog.OpenFileDialog(ParentWindowHandle, DialogTitle, DefaultPath, DefaultFile, FileTypes, Flags, OutFilenames);
}


bool FSlateFileDialogsModule::OpenDirectoryDialog(const void* ParentWindowHandle, const FString& DialogTitle, const FString& DefaultPath,
		FString& OutFoldername)
{
	FSlateFileDlgWindow dialog(FileDialogStyle);
	return dialog.OpenDirectoryDialog(ParentWindowHandle, DialogTitle, DefaultPath, OutFoldername);
}


bool FSlateFileDialogsModule::SaveFileDialog(const void* ParentWindowHandle, const FString& DialogTitle, const FString& DefaultPath,
	const FString& DefaultFile, const FString& FileTypes, uint32 Flags, TArray<FString>& OutFilenames)
{
	FSlateFileDlgWindow dialog(FileDialogStyle);
	return dialog.SaveFileDialog(ParentWindowHandle, DialogTitle, DefaultPath, DefaultFile, FileTypes, Flags, OutFilenames);
}


ISlateFileDialogsModule* FSlateFileDialogsModule::Get()
{
	return SlateFileDialog;
}

IMPLEMENT_MODULE(FSlateFileDialogsModule, SlateFileDialogsEx);

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WhiteTian

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值