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 篇原創文章 · 獲贊 113 · 訪問量 159萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章