赞
踩
1.创建一个PAK文件:
用CMD运行打开D:\Epic Games\UE_4.15\Engine\Binaries\Win64下有个UnrealPak文件
cd到路径后 通过运行时传递参数 UnrealPak.exe [要生成的pak文件] -create=[要打包的文件列表] -order=[文件在pak中排序描述文件] [输出格式] [是否加密] [是否压缩]
例如:UnrealPak.exe test.pak -create=paklist.txt -order=CookerOpenOrder.log -UTF8Output -encrypt -compress
UnrealPak.exe D:\OutPak.Pak C:\Users\Administrator\Desktop\Client\UnrealProjects\IDHome\Content\Materials\bingxiang.uasset
这样就有一个PAK文件了,接下来创建代码
(txt里可以写文件夹如C:\wenjian\*)
/****************分割线**********************/
最新方案:
打包pak方法:
D:\Epic Games\UE_4.18\Engine\Binaries\Win64\UnrealPak.exe D:\UE4project\PakProj\out.pak -create="D:\UE4project\PakProj\plist.txt" -encryptionini -
enginedir="D:\Epic Games\UE_4.18\Engine" -projectdir="D:\UE4project\PakProj" -platform=Windows -abslog="C:\Users\Administrator\AppData\Roaming\Unreal Engine\AutomationTool\Logs\D+Epic+Games+UE_4.18\PakLog_PakProj-WindowsNoEditor.log" -installed -order=D:\UE4project\PakProj\Build\WindowsNoEditor\FileOpenOrder\CookerOpenOrder.log -UTF8Output -multiprocess -pat
chpaddingalign=2048
plist.txt里写:
"D:\UE4project\PakProj\Saved\Cooked\WindowsNoEditor\PakProj\*" "../../../PakProj/*" –compress
.h
- UFUNCTION(BlueprintCallable, Category = "PAK")
- void LoadPakComplete();
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PAK")
- UObject* TheLoadObject ;
.cpp
#include "IPlatformFilePak.h"
- void AMyActor::LoadPakComplete()
- { //如果你想直接加载本地的pak的话,方法的参数列表删掉,然后把SaveArrayToFile这句话也删了,SaveContentDir填写你要加载的路径就可以了...
- //1.把下载好的文件保存起来
- FString SaveContentDir = FPaths::GameContentDir() + TEXT("OutPak.pak");
- //2.加载刚才保存的文件
- //获取当前使用的平台,这里使用的是WIN64平台
- IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
- //初始化PakPlatformFile
- FPakPlatformFile* PakPlatformFile = new FPakPlatformFile();
- PakPlatformFile->Initialize(&PlatformFile, TEXT(""));
- FPlatformFileManager::Get().SetPlatformFile(*PakPlatformFile);
-
- //获取Pak文件
- FPakFile PakFile(*SaveContentDir, false);
- UE_LOG(LogClass, Log, TEXT("get PakFile..."))
- //设置pak文件的Mount点.
- FString MountPoint(FPaths::EngineContentDir()); //"/../../../Engine/Content/"对应路径
- PakFile.SetMountPoint(*MountPoint);
- //对pak文件mount到前面设定的MountPoint
- if (PakPlatformFile->Mount(*SaveContentDir, 0, *MountPoint))
- {
- UE_LOG(LogClass, Log, TEXT("Mount Success"));
- TArray<FString> FileList;
- //得到Pak文件中MountPoint路径下的所有文件
- PakFile.FindFilesAtPath(FileList, *PakFile.GetMountPoint(), true, false, true);
- FStreamableManager StreamableManager;
- //对文件的路径进行处理,转换成StaticLoadObject的那种路径格式
- FString AssetName = FileList[0];
- FString AssetShortName = FPackageName::GetShortName(AssetName);
- FString LeftStr;
- FString RightStr;
- AssetShortName.Split(TEXT("."), &LeftStr, &RightStr);
- AssetName = TEXT("/Engine/") + LeftStr + TEXT(".") + LeftStr; //我们加载的时候用的是这个路径
- FStringAssetReference reference = AssetName;
- //加载UObject
- UObject* LoadObject = StreamableManager.SynchronousLoad(reference);
- if (LoadObject != nullptr)
- {
- UE_LOG(LogClass, Log, TEXT("Object Load Success..."))
- TheLoadObject = LoadObject;
- }
- else
- {
- UE_LOG(LogClass, Log, TEXT("Can not Load asset..."))
- }
- }
- else
- {
- UE_LOG(LogClass, Error, TEXT("Mount Failed"));
- }
- }
这样就加载到内存了。
PS(最新参考https://blog.ch-wind.com/unrealpak-note/
https://arcecho.github.io/2017/07/02/UE4-Pak-%E7%9B%B8%E5%85%B3%E7%9F%A5%E8%AF%86%E6%80%BB%E7%BB%93/)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。