wip location manipulation static functions

This commit is contained in:
Brandon Thomas
2021-03-08 23:56:11 -05:00
parent 41418721d9
commit 2f0ad5f419
2 changed files with 69 additions and 0 deletions
@@ -0,0 +1,28 @@
#include "LocationLibrary.h"
#include "Kismet/GameplayStatics.h"
FVector ULocationLibrary::GetPlayerLocation(UObject* worldContext)
{
APawn* playerPawn = GetPlayerPawn(worldContext);
return playerPawn->GetActorLocation();
}
FVector ULocationLibrary::GetPlayerLocationWithOffset(UObject* worldContext,
float x, float y, float z)
{
FVector playerLocation = GetPlayerLocation(worldContext);
return playerLocation;
}
FVector ULocationLibrary::GetPlayerLocationWithRandomOffset(UObject* worldContext,
float minX, float maxX, float minY, float maxY, float minZ, float maxZ)
{
FVector playerLocation = GetPlayerLocation(worldContext);
return playerLocation;
}
APawn* ULocationLibrary::GetPlayerPawn(UObject* worldContext)
{
APawn* playerPawn = UGameplayStatics::GetPlayerPawn(worldContext, 0);
return playerPawn;
}
@@ -0,0 +1,41 @@
#pragma once
// Unreal Core
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
// Function Library
#include "Kismet/BlueprintFunctionLibrary.h"
#include "LocationLibrary.generated.h"
/**
* Helper functions for obtaining and manipulating locations.
* The world context is automatically injected.
*/
UCLASS()
class ACTORSPAWNINGPLUGIN_API ULocationLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
// The player's location
UFUNCTION(BlueprintPure, Category = "SpawningPluginLocationFunctions",
meta = (WorldContext = "WorldContextObject", UnsafeDuringActorConstruction = "true"))
static FVector GetPlayerLocation(UObject* WorldContextObject);
// The player's location with a static offset
UFUNCTION(BlueprintPure, Category = "SpawningPluginLocationFunctions",
meta = (WorldContext = "WorldContextObject", UnsafeDuringActorConstruction = "true"))
static FVector GetPlayerLocationWithOffset(UObject* WorldContextObject, float x, float y, float z);
// The player's location with a random offset
UFUNCTION(BlueprintPure, Category = "SpawningPluginLocationFunctions",
meta = (WorldContext = "WorldContextObject", UnsafeDuringActorConstruction = "true"))
static FVector GetPlayerLocationWithRandomOffset(UObject* WorldContextObject,
float minX, float maxX, float minY,
float maxY, float minZ, float maxZ);
private:
static APawn* GetPlayerPawn(UObject* WorldContextObject);
};