Skip to content
Snippets Groups Projects
tutorialcode.txt 2.67 KiB
Newer Older
Neil Smith's avatar
Neil Smith committed
//.h

USTRUCT(BlueprintType)
struct FScreenData
{
	GENERATED_USTRUCT_BODY()


		UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "OffAxisProjection")
		int32 id;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "OffAxisProjection")
		FString name;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "OffAxisProjection")
		FVector center;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "OffAxisProjection")
		FRotator rot;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "OffAxisProjection")
		FVector2D resolution;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "OffAxisProjection")
		float width;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "OffAxisProjection")
		float height;
};

UFUNCTION(BlueprintCallable, meta = (DisplayName = "Load Id", Keywords = "OffAxisProjection"), Category = "OffAxisProjection")
		static int32 LoadScreenId();
		
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Load Config", Keywords = "OffAxisProjection"), Category = "OffAxisProjection")
		static TArray<FScreenData> LoadConfig(FString filename);

//.cpp

int32 UOffAxisBlueprintFunctionLibrary::LoadScreenId()
{
	int32 id = -1;
	FString result;
	FString filename = FPaths::ProjectSavedDir() + "/screenid.txt";
	GEngine->AddOnScreenDebugMessage(-1, 30.0f, FColor::Green, filename);
	if (FFileHelper::LoadFileToString(result, *filename))
	{
		id = (FCString::Atoi(*result));
	}

	return id;
}
TArray<FScreenData> UOffAxisBlueprintFunctionLibrary::LoadConfig(FString filename)
{
	TArray<FScreenData> screenData;
	FString result;
	filename = FPaths::ProjectSavedDir() + "/" + filename;

	GEngine->AddOnScreenDebugMessage(-1, 30.0f, FColor::Green, filename);

	if (FFileHelper::LoadFileToString(result, *filename))
	{

		TArray<FString> stringData;
		FString comma = "\n";
		int32 num = 0;
		num = result.ParseIntoArray(stringData, *comma);

		for (int i = 1; i < stringData.Num(); i++)
		{
			
			comma = " ";
			TArray<FString> lineData;

			num = stringData[i].ParseIntoArray(lineData, *comma);
			FScreenData item;
			item.id = (FCString::Atoi(*lineData[0]));
			item.name = lineData[1];
			
			double x = (FCString::Atod(*lineData[2]));
			double y = (FCString::Atod(*lineData[3]));
			double z = (FCString::Atod(*lineData[4]));
			item.center = FVector(x, y, z);

			float rx = (FCString::Atof(*lineData[5]));
			float ry = (FCString::Atof(*lineData[6]));
			float rz = (FCString::Atof(*lineData[7]));

			float px = (FCString::Atof(*lineData[8]));
			float py = (FCString::Atof(*lineData[9]));

			item.rot = FRotator(rx, ry, rz);

			item.width = (FCString::Atof(*lineData[10]));
			item.height = (FCString::Atof(*lineData[11]));
			

			screenData.Add(item);
		}
	}

	return screenData;
}