Space Plunder
Loading...
Searching...
No Matches
LineOfSightComponent.h
Go to the documentation of this file.
1// Copyright (c) 2021 Evgeniy Oshmarin
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "ProceduralMeshComponent.h"
7#include "Materials/MaterialInterface.h"
8#include "LineOfSightComponent.generated.h"
9
10DECLARE_STATS_GROUP(TEXT("LineOfSight Stat Group"), STATGROUP_LineOfSight, STATCAT_Advanced);
11DECLARE_CYCLE_STAT_EXTERN(TEXT("LineOfSight Tick (All functions) "), STAT_LineOfSightTick, STATGROUP_LineOfSight, LINEOFSIGHT_API);
12DECLARE_CYCLE_STAT_EXTERN(TEXT("LineOfSight Line Trace"), STAT_LineOfSightLineTrace, STATGROUP_LineOfSight, LINEOFSIGHT_API);
13DECLARE_CYCLE_STAT_EXTERN(TEXT("LineOfSight Build Mesh"), STAT_LineOfSightBuildMesh, STATGROUP_LineOfSight, LINEOFSIGHT_API);
14
15
16UENUM()
17enum class ETypeTriangle : uint8
18{
19 E_LR UMETA(DisplayName = "Left -> Right"),
20 E_RL UMETA(DisplayName = "Right -> Left"),
21 E_LR_RL UMETA(DisplayName = "Left -> Right | Right -> Left (Beta)"),
22 E_RL_LR UMETA(DisplayName = "Right -> Left | Left -> Right (Beta)")
23};
24
25UENUM()
26enum class ETypeArc : uint8
27{
28 Arc_VectorLenght UMETA(DisplayName = "Arc"),
29 ArcVectorLenghtFlat UMETA(DisplayName = "Line")
30};
31
32UENUM(BlueprintType)
33enum class EAxisTypeComp : uint8
34{
35 Z,
36 Y,
37 X
38};
39
40UENUM()
41enum class ETypeRotation : uint8
42{
43 Relative_Rotation UMETA(DisplayName = "Relative_Rotation (Gimbal_Lock)"),
44 World_Rotation UMETA(DisplayName = "Alternative method (No Gimbal_Lock for 1 or 2 axes)"),
45};
46
47DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FHitEveryFrame, const FHitResult&, Hit);
48DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FHitStart, const FHitResult&, Hit);
51
52
53UCLASS(ClassGroup = Custom, meta = (BlueprintSpawnableComponent))
54class LINEOFSIGHT_API ULineOfSightComponent : public UProceduralMeshComponent
55{
56 GENERATED_BODY()
57
58public:
59
60 ULineOfSightComponent(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
61
62 virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
63 virtual void BeginPlay() override;
64 virtual void BeginDestroy() override;
65
66 /* The event is similar to On Component Begin Overlap */
67 UPROPERTY(BlueprintAssignable, BlueprintCallable, Category = "LineOfSight Component\|Event")
68 FHitStart BeginOverlap;
69
70 /* The event is similar to On Component End Overlap */
71 UPROPERTY(BlueprintAssignable, BlueprintCallable, Category = "LineOfSight Component\|Event")
72 FHitEnd EndOverlap;
73
74 /* Disabled by default */
75 UPROPERTY(BlueprintAssignable, BlueprintCallable, Category = "LineOfSight Component\|Event")
76 FHitEveryFrame HitEveryFrame;
77
78 UPROPERTY(BlueprintAssignable, BlueprintCallable, Category = "LineOfSight Component\|Event")
79 FRotateToAngleEnd RotateToAngleEnd;
80
81
82 UPROPERTY(EditAnywhere, Category = "LineOfSight Component")
83 ETypeArc GeometryType;
84
85 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LineOfSight Component")
86 float Angle1;
87
88 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LineOfSight Component")
89 float Angle2;
90
91 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LineOfSight Component")
92 float Radius1;
93
94 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LineOfSight Component")
95 float Radius2;
96
97 UPROPERTY(EditAnywhere, Category = "LineOfSight Component")
98 ETypeTriangle Type_Of_Triangles;
99
100 UPROPERTY(EditAnywhere, Category = "LineOfSight Component", meta = (ClampMin = "2", EditCondition = "GeometryType == ETypeArc::Arc_VectorLenght"))
101 bool ReverseArch1;
102
103 /* Adds an actor to the list for trace exceptions. */
104 UPROPERTY(EditAnywhere, Category = "LineOfSight Component")
105 bool IgnoreSelf;
106
107 // Calls Event Hit Every Frame when an object is detected
108 UPROPERTY(EditAnywhere, Category = "LineOfSight Component", meta = (DisplayName = "HitEveryFrameEvent (Deprecated)"))
109 bool HitEveryFrameEvent;
110
111 /* Calls Events: Hit Start and Hit End. Similar to Event On Component Begin Overlap. */
112 UPROPERTY(EditAnywhere, Category = "LineOfSight Component")
113 bool BeginAndEndOverlapEvent;
114
115 /* Used for optimization. Use false if you only need 1 arch instead of Radius 1 = 0 and Angle 1 = 0. */
116 UPROPERTY(EditAnywhere, Category = "LineOfSight Component")
117 bool OnlyOneArc;
118
119 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LineOfSight Component")
120 bool Only_Z_Rotation;
121
122 UPROPERTY(EditAnywhere, Category = "LineOfSight Component")
123 bool TraceComplex;
124
125#if WITH_EDITORONLY_DATA
126 /* Only available in the editor. Draws tracing lines. */
127 UPROPERTY(EditAnywhere, Category = "LineOfSight Component")
128 bool Debug;
129
130 UPROPERTY(EditAnywhere, Category = "LineOfSight Component")
131 float DebugLineThickness = 2.0f;
132#endif
133
134 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LineOfSight Component")
135 UMaterialInterface* Material;
136
137 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
138 void SetAngle1(const float NewAngle);
139
140 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
141 void SetAngle2(const float NewAngle);
142
143 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
144 FORCEINLINE float GetAngle1() const { return Angle1; };
145
146 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
147 FORCEINLINE float GetAngle2() const { return Angle2; };
148
149 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
150 void SetRadius1(const float NewRadius);
151
152 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
153 void SetRadius2(const float NewRadius);
154
155 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
156 FORCEINLINE float GetRadius1() const { return Radius1; };
157
158 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
159 FORCEINLINE float GetRadius2() const { return Radius2; };
160
162
163 /* This function must be called before Start Build Arc. */
164 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
165 void SetStandardCollision(const bool NewStatus);
166
167 void InterpAngle();
168
169 bool bInterpAngleBool;
170
171 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
172 void StartInterpAngle(const float NewAngle1, const float NewAngle2, const float Speed1, const float Speed2);
173
174 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
175 void StopInterpAngle();
176
177 float AngleForInterpAngle1;
178
179 float AngleForInterpAngle2;
180
181 float SpeedInterpAngle1;
182
183 float SpeedInterpAngle2;
184
185 void InterpRadius();
186
187 bool InterpRadiusBool;
188
189 /* Smoothly changes the radius */
190 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
191 void StartInterpRadius(const float NewRadius1, const float NewRadius2, const float Speed1, const float Speed2);
192
193 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
194 void StopInterpRadius();
195
196 float Radius1ForInterp;
197
198 float Radius2ForInterp;
199
200 float SpeedInterpRadius;
201
202 float SpeedInterpRadius1;
203
204 float SpeedInterpRadius2;
205
206
207 UPROPERTY(BlueprintReadWrite, Category = "LineOfSight Component")
208 ETypeTriangle TypeTriangle;
209
210 UPROPERTY()
211 bool FlipDirection;
212
213 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
214 FORCEINLINE uint8 GetHitEveryFrame() const { return HitEveryFrameEvent; }
215
216 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
217 FORCEINLINE uint8 GetBeginAndEndOverlapEvent() const { return BeginAndEndOverlapEvent; }
218
219 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
220 void SetHitEveryFrame(const bool NewValue);
221
222 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
223 void SetBeginAndEndOverlapEvent(const bool NewValue);
224
225 FCollisionQueryParams TraceParams;
226
227 ECollisionChannel TraceChanne2;
228
229
230 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
231 void SetTraceChannel(const ETraceTypeQuery NewTraceChanne);
232
233 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
234 void SetTraceComplex(const bool NewValue);
235
236
237 /* It is not recommended to use this function. Change Trace Responces in Collision settings instead */
238 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
239 void AddIgnoredActor(UPARAM(ref) const AActor* ActorToIgnore);
240
241 /* It is not recommended to use this function. Change Trace Responces in Collision settings instead */
242 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
243 void AddActorsToIgnore(UPARAM(ref) TArray<AActor*>& ActorsToIgnore);
244
245 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
246 void ClearActorsToIgnore(const bool NewIgnoreSelf = true);
247
248 /* Set the Ignore Self option, but clear the actor array added using AddActorsToIgnore */
249 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
250 void SetIgnoreSelf(const bool NewValueIgnoreSelf);
251
252 void BuildArcVectorLenght();
253
254 void BuildArcVectorLenghtFlat();
255
256 void BuildMesh();
257
258 /* Does TraceLine */
259 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
260 void StartLineTrace(ETraceTypeQuery TraceChannel, int32 NumberOfLines = 60);
261
262 bool Cloned;
263
264 UPROPERTY(Transient, DuplicateTransient)
265 ULineOfSightComponent* LineOfSightComponentForClone;
266
267 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
268 void ZStartCloneTo(ULineOfSightComponent* OtherLineOfSightComponent);
269
270 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
271 void ZStopCloneTo();
272
273 void CloneTick();
274
275 /* Essentially disables the component. Stops tracing and building the mesh. But the tick function will continue to work. To disable it completely,
276 call StopLineTrace () and call SetTickComponentEnabled (false). */
277 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
278 void StopLineTrace();
279
280 /* Create Mesh After TraceLine */
281 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
282 void StartBuildMesh();
283
284 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
285 void StopBuildMesh();
286
287 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
288 void SetTickEnable(const bool Enable);
289
290 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
291 void SetVisibilityOfMesh(const bool NewVisibility);
292
293 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
294 bool MeshIsBuilt() const;
295
296 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
297 bool LineOfSightIsActive() const;
298
299 int16 SlackArray;
300
301 uint8 bRotateInRangeActive;
302
303 uint8 bRotateToAngleActive;
304
305 FRotator AngleRotateRot;
306
307 FRotator AngleRotateRot2;
308
309 FQuat AngleRotateQuat;
310
311 FQuat AngleRotateQuat2;
312
313 float SpeedRotate;
314
315 float Tolerance = 0.0000005f;
316
317 /* Tolerance to compare angles. Default 0.000005f. */
318 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
319 void SetTolerance(const float NewTolerance);
320
321 EAxisTypeComp AxisForRotateAngle;
322
323 ETypeRotation TypeRotationGlobal;
324
325 void RotateInRange();
326
327 void RotateToAngle();
328
329 /* Maximum angle 89 */
330 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
331 void StartRotateInRangeAxis(const EAxisTypeComp Axis, const float Angle, float Speed, const ETypeRotation TypeRotation, const bool NegativeToPositive);
332
333 /* When the rotation is finished, event RotateToAngleEnd will be called. */
334 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
335 void StartRotateToAngleAxis(const EAxisTypeComp Axis, const float Angle, const float Speed, const ETypeRotation TypeRotation, const bool AddToCurrent = true);
336
337 /* This function uses World Rotation */
338 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
339 void StartRotateToActor(const EAxisTypeComp Axis, AActor* Actor, const float Speed);
340
341 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
342 void StopRotateToAngle();
343
344 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
345 void StopRotateInRange();
346
347 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
348 void StopAllRotate();
349
350 float GetAxisValue(EAxisTypeComp Axis, FRotator& Rotator);
351
352 FRotator SetAxisValue(EAxisTypeComp Axis, const float Value, FRotator& Rotator);
353
354 /* Returns the corner to the target. Same as FindLookAtRotation. Works correctly for the Z axis. */
355 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
356 FRotator FindAngleRotate(UPARAM(ref) AActor*& Actor);
357
358 /* Changes the Geometry Type. Can only be called before Start Line Trace or after Stop Line Trace */
359 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
360 void SetGeometryType(const ETypeArc NewType);
361
362 /* Can only be called after Start Build Mesh */
363 UFUNCTION(BlueprintCallable, Category = "LineOfSight Component")
364 void SetNormals(const FVector Normals);
365 /*
366 #if WITH_EDITORONLY_DATA
367 virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
368 virtual void PostInitProperties() override;
369 #endif
370 */
371
372protected:
374 bool bBuildMeshActive;
376 bool StartLineTraceActive;
378 TArray<FHitResult> WasStartOverlapArray;
379
380 UPROPERTY(Transient)
381 TArray<FVector> PointArray1;
382
383 UPROPERTY(Transient)
384 TArray<FVector> NormalVertex;
385
386 UPROPERTY(Transient)
387 TArray<FVector2D> UV0;
388
389 UPROPERTY(Transient)
390 TArray<FLinearColor> VertexColors;
391
392 UPROPERTY(Transient)
393 TArray<FProcMeshTangent> Tangents;
394
395 UPROPERTY(Transient)
396 TArray<int32> Triangle;
397
398private:
400 int Number_Of_Lines;
401
402};
UCLASS(Blueprintable, BlueprintType, ClassGroup=(BucciGames), meta=(BlueprintSpawnableComponent)) class CHATSYSTEM_API UChatSystemComponent
Definition ChatSystemComponent.h:13
DECLARE_CYCLE_STAT_EXTERN(TEXT("LineOfSight Tick (All functions) "), STAT_LineOfSightTick, STATGROUP_LineOfSight, LINEOFSIGHT_API)
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FRotateToAngleEnd)
ETypeTriangle
Definition LineOfSightComponent.h:18
DECLARE_STATS_GROUP(TEXT("LineOfSight Stat Group"), STATGROUP_LineOfSight, STATCAT_Advanced)
ETypeArc
Definition LineOfSightComponent.h:27
ETypeRotation
Definition LineOfSightComponent.h:42
EAxisTypeComp
Definition LineOfSightComponent.h:34
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FHitEveryFrame, const FHitResult &, Hit)
Definition LineOfSight.Build.cs:6
Definition LineOfSightComponent.h:55
bool UseStandardCollision
Definition LineOfSightComponent.h:161