UE4-【C++】【打包NonUASSET文件并加载】

使用自定义IO操作,将目标文件(txt)放在Content

1.设置附加打包目录

void UMyBlueprintFunctionLibrary::ExecuteTestCode(const FString &InPaksDir)
{
	UMyBlueprintFunctionLibrary::ShowGameDir();
	FString read_str;
	bool is_load = UMyBlueprintFunctionLibrary::LoadTxt("Datas/TbHero.txt", read_str);
	if (is_load)
	{
		UE_LOG(LogTemp, Log, TEXT("read_str = %s"), *read_str);
	}
	return;
    FString PaksDir = InPaksDir;
    FPaths::MakeStandardFilename(PaksDir);
    UE_LOG(LogMyBPLibrary, Log, TEXT("ExecuteTestCode InPaksDir: %s"), *PaksDir);

    {
        FMyFileVisitor MyFileVisitor;
        FPlatformFileManager::Get().GetPlatformFile().IterateDirectoryRecursively(*PaksDir, MyFileVisitor);

        for (auto &f : MyFileVisitor.Files)
        {
            if (FPaths::GetExtension(f) == "pak")
            {
                UE_LOG(LogMyBPLibrary, Log, TEXT("Find and mount pak file: %s"), *f);
                GetPakPlatformFile()->Mount(*f, 0);
            }
        }
    }
}


bool UMyBlueprintFunctionLibrary::LoadTxt(FString FileNameA, FString& SaveTextA)
{
	const FString ThePath = FPaths::ConvertRelativePathToFull(FPaths::GameContentDir());
	UE_LOG(LogTemp, Log, TEXT("TbHero Path = %s"), *(ThePath + FileNameA));
	return FFileHelper::LoadFileToString(SaveTextA, *(ThePath + FileNameA));
}


bool UMyBlueprintFunctionLibrary::SaveTxt(FString SaveTextB, FString FileNameB)
{
	return FFileHelper::SaveStringToFile(SaveTextB, *(FPaths::GameDir() + FileNameB));
}

发布了469 篇原创文章 · 获赞 110 · 访问量 158万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览