Agrarsense
SensorManager.cpp
Go to the documentation of this file.
1// Copyright (c) 2024 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#include "SensorManager.h"
7#include "Sensor.h"
8
10
12{
13 if (!Instance)
14 {
15 // If Instance doesn't exists, create it.
16 USensorManager* Manager = NewObject<USensorManager>();
17 Manager->AddToRoot();
18 }
19
20 return Instance;
21}
22
24{
25 if (Instance)
26 {
27 // If Instance exists, destroy this manager.
28 this->ConditionalBeginDestroy();
29 }
30 else
31 {
32 // Set Instance to this
33 Instance = this;
34 }
35}
36
38{
39 if (Instance == this)
40 {
41 Instance = nullptr;
42 }
43}
44
46{
48 if (Manager && SensorPtr)
49 {
50 Manager->Sensors.Add(SensorPtr);
51 Manager->OnSensorSpawned.Broadcast(SensorPtr);
52 }
53}
54
56{
58 if (Manager && SensorPtr)
59 {
60 Manager->Sensors.Remove(SensorPtr);
61 Manager->OnSensorDestroyed.Broadcast(SensorPtr);
62 }
63}
64
66{
67 return Sensors;
68}
69
71{
72 TArray<ASensor*> SensorsOfType;
73
74 for (ASensor* Sensor : Sensors)
75 {
76 if (Sensor && Sensor->GetSensorType() == SensorType)
77 {
78 SensorsOfType.Add(Sensor);
79 }
80 }
81
82 return SensorsOfType;
83}
ESensorTypes
Definition: SensorTypes.h:15
Definition: Sensor.h:44
static USensorManager * Instance
Definition: SensorManager.h:73
static USensorManager * Get()
FSensorDestroyedDelegate OnSensorDestroyed
Definition: SensorManager.h:58
static void AddSensor(ASensor *SensorPtr)
TArray< ASensor * > GetAllSensors()
TArray< ASensor * > Sensors
Definition: SensorManager.h:76
TArray< ASensor * > GetAllSensorsOfType(ESensorTypes SensorType)
FSensorSpawnedDelegate OnSensorSpawned
Definition: SensorManager.h:51
static void RemoveSensor(ASensor *SensorPtr)