行业知识
UE5 文字游戏(2) C++实时读取CSV文件(游戏开始读取本地CSV剧本)
2026-11-15 17:40:48
来源:互联网转载
1.结构体代码
// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"#include "Engine/DataTable.h"#include "MyCharacterStats.generated.h"USTRUCT(BlueprintType)struct FMyCharacterStats : public FTableRowBase{ GENERATED_BODY() UPROPERTY(EditAnywhere, BlueprintReadWrite) FString Name; UPROPERTY(EditAnywhere, BlueprintReadWrite) int32 Health; UPROPERTY(EditAnywhere, BlueprintReadWrite) int32 Attack;}; 2.写一个C++蓝��函数库
.h
// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"#include "Misc/Paths.h"#include "Serialization/Csv/CsvParser.h"#include "Misc/FileHelper.h"#include "MyCharacterStats.h"#include "Kismet/BlueprintFunctionLibrary.h"#include "MyBlueprintFunctionLibrary.generated.h"/** * */UCLASS()class WEBH5_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary{GENERATED_BODY()public:UFUNCTION(BlueprintCallable,Category="Data")static TArray LoadCSVData(const FString& CSVFilePath);/*UDataTable* LoadCSVData(const FString& CSVFilePath, TArray& DataTable);*/}; .cpp
// Fill out your copyright notice in the Description page of Project Settings.#include "MyBlueprintFunctionLibrary.h"TArray UMyBlueprintFunctionLibrary::LoadCSVData(const FString& CSVFilePath){TArray outStats;FString CSVContent;if(!FFileHelper::LoadFileToString(CSVContent,*CSVFilePath))return outStats;const FCsvParser Parser(CSVContent);const FCsvParser::FRows& Rows = Parser.GetRows();for (int32 RowIndex = 1; RowIndex
上一篇:服务器哪里可以不备案?
下一篇:我的世界服务器怎么补偿?