diff --git a/Source/ActorSpawningPlugin/Private/LocationLibrary.cpp b/Source/ActorSpawningPlugin/Private/LocationLibrary.cpp new file mode 100644 index 0000000..71cbe88 --- /dev/null +++ b/Source/ActorSpawningPlugin/Private/LocationLibrary.cpp @@ -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; +} diff --git a/Source/ActorSpawningPlugin/Public/LocationLibrary.h b/Source/ActorSpawningPlugin/Public/LocationLibrary.h new file mode 100644 index 0000000..1e41176 --- /dev/null +++ b/Source/ActorSpawningPlugin/Public/LocationLibrary.h @@ -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); +};