Unreal Engine 4 —— 使用IPlatformFile进行Shader文件在开发团队间的共享
2016-11-04 16:11
489 查看
这篇博客介绍了如何使用
这篇博客所涉及的代码来自Temaran的UE4ShaderPluginDemo里面的
但是由于UE4的着色器必须位于
那么我们要做的便是在引擎打开时,将项目下的
使用插件
由于UE4的插件可以将
在整个模块startup时,使用
同样的,在模块退出时,将这些文件删除:
这样一来,团队中的成员只需要启用这个插件,然后维护
<全文完>
IPlatformFile来实现Shaders文件在开发团队间的共享。
这篇博客所涉及的代码来自Temaran的UE4ShaderPluginDemo里面的
ShaderCopyHelper插件。
背景
虽然UE4的材质编辑器已经足够强大并且可以支持大部分的需求了,但是有时候我们还是需要自定义自己的Shader。但是由于UE4的着色器必须位于
Engine/Shaders/文件夹下,这样一来针对那些不进行定制化UE4的开发团队来说,对Shaders文件夹进行代码管理就不太方便了。
解决方案
对于开发团队来说,最好的解决方案便是在项目文件夹下维护一个Shaders文件夹。由于Shaders文件夹位于项目文件夹下,因此对其进行代码管理就是一件非常容易的事。
那么我们要做的便是在引擎打开时,将项目下的
Shaders下的文件复制到
Engine/Shaders/文件夹中,并且在引擎关闭时,将这些文件删除。
使用插件uplugin
由于UE4的插件可以将StartupModule()和
ShutdownModule()直接暴露出来,并且可以指定其只在编辑器(
Developer)下启用,因此无疑成为了这个功能实现的最好平台。
"Modules" : [ { "Name" : "ShaderCopyHelper", "Type" : "Developer", "LoadingPhase" : "PostConfigInit" } ]
代码实现
了解原理后,具体的实现就很简单了。先遍历项目文件夹下的Shaders文件夹并获得所有的Shader文件名:
bool FShaderFileVisitor::Visit(const TCHAR* FilenameOrDirectory, bool bIsDirectory) { if (!bIsDirectory) { ShaderFilePaths.Add(FPaths::GetCleanFilename(FilenameOrDirectory)); } return true; }
在整个模块startup时,使用
IPlatformFile::CopyFile(const TCHAR* To, const TCHAR* From)函数进行文件的拷贝:
void FShaderCopyHelperModule::StartupModule() { UE_LOG(ShaderCopyHelper, Log, TEXT("Shader Copy Helper Plugin loaded!")); FString GameShadersDirectory = FPaths::Combine(*FPaths::GameDir(), TEXT("Shaders")); FString EngineShadersDirectory = FPaths::Combine(*FPaths::EngineDir(), TEXT("Shaders")); ShaderFiles = new FShaderFileVisitor(); IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); PlatformFile.IterateDirectoryRecursively(*GameShadersDirectory, *ShaderFiles); UE_LOG(ShaderCopyHelper, Log, TEXT("Copying project shader files to Engine/Shaders/")); for (int32 ShaderFileIndex = 0; ShaderFileIndex < ShaderFiles->ShaderFilePaths.Num(); ShaderFileIndex++) { FString CurrentShaderFile = ShaderFiles->ShaderFilePaths[ShaderFileIndex]; FString GameShaderFullPath = FPaths::Combine(*GameShadersDirectory, *CurrentShaderFile); FString EngineShaderFullPath = FPaths::Combine(*EngineShadersDirectory, *CurrentShaderFile); if (PlatformFile.CopyFile(*EngineShaderFullPath, *GameShaderFullPath)) { UE_LOG(ShaderCopyHelper, Log, TEXT("Shader file %s copied to %s."), *GameShaderFullPath, *EngineShaderFullPath); } else { UE_LOG(ShaderCopyHelper, Warning, TEXT("Could not copy %s to %s!"), *GameShaderFullPath, *EngineShaderFullPath); } } }
同样的,在模块退出时,将这些文件删除:
void FShaderCopyHelperModule::ShutdownModule() { FString EngineShadersDirectory = FPaths::Combine(*FPaths::EngineDir(), TEXT("Shaders")); IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); UE_LOG(ShaderCopyHelper, Log, TEXT("Deleting project shaders from Engine/Shaders/")); for (int32 ShaderFileIndex = 0; ShaderFileIndex < ShaderFiles->ShaderFilePaths.Num(); ShaderFileIndex++) { FString EngineShaderFullPath = FPaths::Combine(*EngineShadersDirectory, *ShaderFiles->ShaderFilePaths[ShaderFileIndex]); if (PlatformFile.DeleteFile(*EngineShaderFullPath)) { UE_LOG(ShaderCopyHelper, Log, TEXT("Shader file %s deleted."), *EngineShaderFullPath); } else { UE_LOG(ShaderCopyHelper, Warning, TEXT("Could not delete %s!"), *EngineShaderFullPath); } } delete ShaderFiles; UE_LOG(ShaderCopyHelper, Log, TEXT("Shader Copy Helper Plugin unloaded!")); }
这样一来,团队中的成员只需要启用这个插件,然后维护
Shaders文件夹就可以了。
<全文完>
相关文章推荐
- 使用文件映射的方式进行共享数据中CreateFileMapping、MapViewOfFile函数参数说明
- 在Windows服务器的命令窗口中用ftp方式与使用了File Zilla Sever软件共享了文件的另一个Windows服务器进行文件传输
- 学生使用极限编程进行团队开发的方案【转】
- 图解使用Win8Api进行Metro风格的程序开发二----使用文件选择器访问和保存文件
- 使用fileinput模块进行原地修改文件
- Android应用开发之使用Socket进行大文件断点上传续传
- 由于Python本身自带的界面库功能并不强大,我们使用Python+wxPython作为界面开发平台,在公司新的项目中进行界面开发。开发过程使用Eclipse+PyDev 作为集成开发环境。产品发布时使用Py2exe进行打包。如今,在我的团队中,Pytho
- AS/400开发经验点滴(八)使用共享文件打开提高软件性能
- 使用libcurl进行文件下载类项目开发(一) libcurl简单使用介绍
- 关于使用platform和file_operations开发驱动的不同
- 使用fileinput模块进行原地修改文件 分类: python 小练习 2013-08-13 16:47 618人阅读 评论(0) 收藏
- SVN最新可视化版本库安装和Eclipse中使用SVN插件进行团队开发
- linux下使用文件来模拟硬盘进行ASM测试-开发技术
- 三步实现Eclipse中使用SVN插件进行团队开发和SVN最新可视化版本库安装
- 学生使用极限编程进行团队开发的方案
- 使用VSS进行.net平台Win系统及Web系统的团队开发
- 使用apache.commons.fileupload等进行文件上传
- 使用VB.NET的FileInfo和DirectoryInfo类进行文件操作
- 使用FindFirstFile和FindNextFile对给定目录下所有文件进行广度优先遍历
- 关于使用platform和file_operations开发驱动的不同