-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathComponentAudioListener.cpp
More file actions
92 lines (73 loc) · 2.09 KB
/
ComponentAudioListener.cpp
File metadata and controls
92 lines (73 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "ComponentAudioListener.h"
#include "Application.h"
#include "ModuleAudio.h"
#include "imgui\imgui.h"
#include "GameObject.h"
#include "ComponentCamera.h"
#include <string>
ComponentAudioListener::ComponentAudioListener(ComponentType type, GameObject* game_object) : Component(type, game_object)
{
listener_id = App->audio->AddListener();
}
ComponentAudioListener::~ComponentAudioListener()
{
App->audio->RemoveListener(listener_id);
}
void ComponentAudioListener::Update()
{
ComponentCamera *cam = (ComponentCamera*)game_object->GetComponent(ComponentType::C_CAMERA);
if (cam)
App->audio->UpdateListenerPos(cam, listener_id);
else
LOG("Audio listener requires a Component Camera attached on the same Gameobject");
}
void ComponentAudioListener::OnInspector(bool debug)
{
std::string str = (std::string("Audio Listener") + std::string("##") + std::to_string(uuid));
if (ImGui::CollapsingHeader(str.c_str(), ImGuiTreeNodeFlags_DefaultOpen))
{
if (ImGui::IsItemClicked(1))
{
ImGui::OpenPopup("delete##audiolistener");
}
if (ImGui::BeginPopup("delete##audiolistener"))
{
if (ImGui::MenuItem("Delete"))
{
Remove();
}
ImGui::EndPopup();
}
//Active
bool is_active = IsActive();
if (ImGui::Checkbox("###activeAudioListener", &is_active))
{
SetActive(is_active);
if (is_active) listener_id = App->audio->AddListener();
else App->audio->RemoveListener(listener_id);
}
ImGui::Text("Listener ID: %u", listener_id);
}
}
void ComponentAudioListener::Save(Data & file)const
{
Data data;
data.AppendInt("type", type);
data.AppendUInt("UUID", uuid);
data.AppendBool("active", active);
data.AppendUInt("listener ID", listener_id);
file.AppendArrayValue(data);
}
void ComponentAudioListener::Load(Data & conf)
{
uuid = conf.GetUInt("UUID");
active = conf.GetBool("active");
// Setting listener configuration for saved listener_id
App->audio->RemoveListener(listener_id);
listener_id = conf.GetUInt("listener ID");
if(active) listener_id = App->audio->AddListener();
}
void ComponentAudioListener::Remove()
{
game_object->RemoveComponent(this);
}