Agrarsense
AssetLibrary.h
Go to the documentation of this file.
1// Copyright (c) 2023 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#pragma once
7
8#include "CoreMinimal.h"
9#include "Kismet/BlueprintFunctionLibrary.h"
10#include "Math/UnrealMathUtility.h"
11#include "GameFramework/Actor.h"
12
16
20
23
26
27#include "AssetLibrary.generated.h"
28
30
31USTRUCT(Blueprintable)
32struct AGRARSENSE_API FVehicleData
33{
34 GENERATED_BODY()
35
36
39 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
40 TWeakObjectPtr<AVehicle> Vehicle;
41
45 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
47};
48
52UCLASS()
53class AGRARSENSE_API UAssetLibrary : public UBlueprintFunctionLibrary
54{
55 GENERATED_BODY()
56
57public:
58
63 UFUNCTION(BlueprintCallable, Category = "Asset Library")
64 static AActor* SpawnFoliage(EFoliageTypes FoliageType, FTransform Transform,
65 FString ActorName = "", FString ActorID = "",
66 bool RandomZRotation = true, bool SnapToGround = true);
67
72 UFUNCTION(BlueprintCallable, Category = "Asset Library")
73 static AVehicle* SpawnVehicle(EVehicleTypes VehicleType, FTransform SpawnTransform,
74 const FString& ActorName, const FString& ActorID,
75 bool SnapAboveGround = false, float AboveOffset = 150.0f,
76 bool DestroyOverlappingActors = false);
77
82 UFUNCTION(BlueprintCallable, Category = "Asset Library")
83 static AActor* SpawnProp(EPropTypes PropType, FTransform Transform,
84 FString ActorName = "", FString ActorID = "",
85 bool RandomZRotation = false, bool SnapToGround = false);
86
91 UFUNCTION(BlueprintCallable, Category = "Asset Library")
92 static AWalker* SpawnWalker(FWalkerParameters Parameters, const FString& ActorName = "",
93 const FString& ActorID = "", bool StartAutomatically = true);
94
95public:
96
97 /*
98 * Get Prop actor asset map data asset
99 */
100 UFUNCTION(BlueprintCallable, Category = "Asset Library")
101 static UPropActorAssetMapDataAsset* GetPropActorAssetMapDataAsset();
102
103 /*
104 * Get random prop type
105 */
106 UFUNCTION(BlueprintCallable, Category = "Asset Library")
107 static EPropTypes GetRandomPropType();
108
113 UFUNCTION(BlueprintCallable, Category = "Asset Library")
114 static TArray<AInstancedActor*> GetAllAddedPropActors();
115
116 /*
117 * Get Foliage Actor Asset Map Data Asset
118 */
119 UFUNCTION(BlueprintCallable, Category = "Asset Library")
120 static UFoliageActorAssetMapDataAsset* GetFoliageActorAssetMapDataAsset();
121
122 /*
123 * Get random foliage type
124 */
125 UFUNCTION(BlueprintCallable, Category = "Asset Library")
126 static EFoliageTypes GetRandomFoliageType();
127
132 UFUNCTION(BlueprintCallable, Category = "Asset Library")
133 static TArray<AInstancedActor*> GetAllAddedFoliageActors();
134
138 UFUNCTION(BlueprintCallable, Category = "Asset Library")
139 static TArray<FVehicleData> GetSpawnedVehicles();
140
144 UFUNCTION(BlueprintCallable, Category = "Asset Library")
145 static void DestroyAllWalkers();
146
150 UFUNCTION(BlueprintCallable, Category = "Asset Library")
151 static TArray<AWalker*> GetAllWalkers();
152
153 /*
154 * Get WalkerActorAssetMapDataAsset.
155 * @return UWalkerActorAssetMapDataAsset pointer or nullptr
156 */
157 UFUNCTION(BlueprintCallable, Category = "Asset Library")
158 static UWalkerActorAssetMapDataAsset* GetWalkerActorAssetMapDataAsset();
159
160private:
161
162 static AActor* TrySpawnActor(TSubclassOf<AActor> ActorClass, FTransform& Transform,
163 FString ActorName, FString ActorID,
164 bool SnapToGround, bool RandomZRotation,
165 ESpawnActorCollisionHandlingMethod CollisionMethod = ESpawnActorCollisionHandlingMethod::Undefined);
166
167 static void DestroyOverlappingActorsSphere(AActor* SpawnedActor);
168
169 static void SetupVehicleDataAsset();
170 static TWeakObjectPtr<UVehicleActorAssetMapDataAsset> VehicleDataAsset;
171 static TArray<FVehicleData> SpawnedVehicles;
172
173 static void SetupFoliageDataAsset();
174 static TWeakObjectPtr<UFoliageActorAssetMapDataAsset> FoliageActorAssetMapDataAsset;
175 static TMap<EFoliageTypes, FString> FoliageTypeMap;
176 static TArray<FInstancedActorData> AddedFoliageActors;
177 static TArray<EFoliageTypes> FoliageKeys;
178
179 static void SetupPropDataAsset();
180 static TWeakObjectPtr<UPropActorAssetMapDataAsset> PropActorAssetMapDataAsset;
181 static TArray<FInstancedActorData> SpawnedPropActors;
182 static TMap<EPropTypes, FString> PropTypeMap;
183 static TArray<EPropTypes> PropKeys;
184
185 static void SetupWalkerDataAsset();
186 static TWeakObjectPtr<UWalkerActorAssetMapDataAsset> WalkerActorAssetMapDataAsset;
187 static TArray<TWeakObjectPtr<AWalker>> SpanwedWalkers;
188};
EFoliageTypes
Definition: FoliageTypes.h:15
EPropTypes
Definition: PropTypes.h:15
EVehicleTypes
Definition: VehicleTypes.h:15
Definition: Walker.h:28
static TWeakObjectPtr< UFoliageActorAssetMapDataAsset > FoliageActorAssetMapDataAsset
Definition: AssetLibrary.h:174
static TArray< FInstancedActorData > SpawnedPropActors
Definition: AssetLibrary.h:181
static TMap< EFoliageTypes, FString > FoliageTypeMap
Definition: AssetLibrary.h:175
static TWeakObjectPtr< UVehicleActorAssetMapDataAsset > VehicleDataAsset
Definition: AssetLibrary.h:170
static TArray< TWeakObjectPtr< AWalker > > SpanwedWalkers
Definition: AssetLibrary.h:187
static TArray< EPropTypes > PropKeys
Definition: AssetLibrary.h:183
static TArray< EFoliageTypes > FoliageKeys
Definition: AssetLibrary.h:177
static TMap< EPropTypes, FString > PropTypeMap
Definition: AssetLibrary.h:182
static TWeakObjectPtr< UPropActorAssetMapDataAsset > PropActorAssetMapDataAsset
Definition: AssetLibrary.h:180
static TWeakObjectPtr< UWalkerActorAssetMapDataAsset > WalkerActorAssetMapDataAsset
Definition: AssetLibrary.h:186
static TArray< FVehicleData > SpawnedVehicles
Definition: AssetLibrary.h:171
static TArray< FInstancedActorData > AddedFoliageActors
Definition: AssetLibrary.h:176