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 /*
163 * Try to Spawn Actor
164 */
165 static AActor* TrySpawnActor(TSubclassOf<AActor> ActorClass, FTransform& Transform,
166 FString ActorName, FString ActorID,
167 bool SnapToGround, bool RandomZRotation,
168 ESpawnActorCollisionHandlingMethod CollisionMethod = ESpawnActorCollisionHandlingMethod::Undefined);
169
170 /*
171 * Try to Spawn Actor deferred (Need to call FinishSpawning manually)
172 */
173 static AActor* TrySpawnActorDeferred(TSubclassOf<AActor> ActorClass, FTransform& Transform,
174 FString ActorName, FString ActorID,
175 bool SnapToGround, bool RandomZRotation,
176 ESpawnActorCollisionHandlingMethod CollisionMethod = ESpawnActorCollisionHandlingMethod::Undefined);
177
178 static void DestroyOverlappingActorsSphere(AActor* SpawnedActor);
179
180 static void SetupVehicleDataAsset();
181 static TWeakObjectPtr<UVehicleActorAssetMapDataAsset> VehicleDataAsset;
182 static TArray<FVehicleData> SpawnedVehicles;
183
184 static void SetupFoliageDataAsset();
185 static TWeakObjectPtr<UFoliageActorAssetMapDataAsset> FoliageActorAssetMapDataAsset;
186 static TMap<EFoliageTypes, FString> FoliageTypeMap;
187 static TArray<FInstancedActorData> AddedFoliageActors;
188 static TArray<EFoliageTypes> FoliageKeys;
189
190 static void SetupPropDataAsset();
191 static TWeakObjectPtr<UPropActorAssetMapDataAsset> PropActorAssetMapDataAsset;
192 static TArray<FInstancedActorData> SpawnedPropActors;
193 static TMap<EPropTypes, FString> PropTypeMap;
194 static TArray<EPropTypes> PropKeys;
195
196 static void SetupWalkerDataAsset();
197 static TWeakObjectPtr<UWalkerActorAssetMapDataAsset> WalkerActorAssetMapDataAsset;
198 static TArray<TWeakObjectPtr<AWalker>> SpawnedWalkers;
199};
EFoliageTypes
Definition: FoliageTypes.h:15
EPropTypes
Definition: PropTypes.h:15
EVehicleTypes
Definition: VehicleTypes.h:15
Definition: Walker.h:30
static TWeakObjectPtr< UFoliageActorAssetMapDataAsset > FoliageActorAssetMapDataAsset
Definition: AssetLibrary.h:185
static TArray< FInstancedActorData > SpawnedPropActors
Definition: AssetLibrary.h:192
static TMap< EFoliageTypes, FString > FoliageTypeMap
Definition: AssetLibrary.h:186
static TWeakObjectPtr< UVehicleActorAssetMapDataAsset > VehicleDataAsset
Definition: AssetLibrary.h:181
static TArray< EPropTypes > PropKeys
Definition: AssetLibrary.h:194
static TArray< EFoliageTypes > FoliageKeys
Definition: AssetLibrary.h:188
static TMap< EPropTypes, FString > PropTypeMap
Definition: AssetLibrary.h:193
static TWeakObjectPtr< UPropActorAssetMapDataAsset > PropActorAssetMapDataAsset
Definition: AssetLibrary.h:191
static TWeakObjectPtr< UWalkerActorAssetMapDataAsset > WalkerActorAssetMapDataAsset
Definition: AssetLibrary.h:197
static TArray< FVehicleData > SpawnedVehicles
Definition: AssetLibrary.h:182
static TArray< TWeakObjectPtr< AWalker > > SpawnedWalkers
Definition: AssetLibrary.h:198
static TArray< FInstancedActorData > AddedFoliageActors
Definition: AssetLibrary.h:187