-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathSoundEntry_Manager.cs
More file actions
136 lines (113 loc) · 4.12 KB
/
SoundEntry_Manager.cs
File metadata and controls
136 lines (113 loc) · 4.12 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright (c) Meta Platforms, Inc. and affiliates.
using Meta.XR.Samples;
using System;
using System.Collections.Generic;
using TheWorldBeyond.Environment.RoomEnvironment;
using TheWorldBeyond.GameManagement;
using UnityEngine;
using UnityEngine.Audio;
using Color = UnityEngine.Color;
namespace TheWorldBeyond.Audio
{
[MetaCodeSample("TheWorldBeyond")]
public class SoundEntry_Manager : MonoBehaviour
{
public AudioMixer AudioMixer => AudioManager.Instance.AudioMixer;
public static SoundEntry_Manager Instance = null;
[NonSerialized]
public static List<SoundEntry> SoundEntryList = null;
public static float AmbDuckVolume = -9f;
public static float AmbFilterCutoff = 1000f;
private bool m_isPlaying;
private float m_audioTimer;
private AudioListener m_audioListener;
private Vector3 m_position = default;
public Vector3 Position
{
get
{
if (m_position == default)
{
m_position = GetComponent<Transform>().position;
}
return m_position;
}
}
private void Awake()
{
if (!Instance)
{
Instance = this;
}
}
// Start is called before the first frame update
private void Start()
{
SoundEntryList = new List<SoundEntry>();
m_audioListener = FindFirstObjectByType<AudioListener>();
}
// Update is called once per frame
public void DoLateUpdate()
{
if (WorldBeyondManager.Instance.CurrentChapter == WorldBeyondManager.GameChapter.OppyExploresReality)
{
HandleObstructed();
}
if (WorldBeyondManager.Instance.CurrentChapter == WorldBeyondManager.GameChapter.TheGreatBeyond)
{
HandleObstructed();
}
if (WorldBeyondManager.Instance.CurrentChapter == WorldBeyondManager.GameChapter.Ending)
{
HandleObstructed();
}
}
#region OBSTRUCTION_MANAGER
private static Plane s_plane;
private static Ray s_ray;
public void HandleObstructed()
{
if (SoundEntryList is null) return;
// Handle Ambient SFX Emitters and Walls
foreach (var sfxSoundEntry in SoundEntryList)
{
if (sfxSoundEntry is null) continue;
if (!sfxSoundEntry.IsPlaying) continue;
if (!sfxSoundEntry.UsesWallOcclusion) continue;
var heading = sfxSoundEntry.transform.position - m_audioListener.transform.position;
var distance = heading.magnitude;
var direction = heading / distance;
if (m_audioListener is not null)
{
s_ray.origin = m_audioListener.transform.position;
s_ray.direction = direction;
if (!VirtualRoom.Instance.IsBlockedByWall(s_ray, distance))
{
Debug.DrawRay(s_ray.origin, s_ray.direction * distance, Color.yellow);
sfxSoundEntry.SetOccluded(false);
}
else
{
Debug.DrawRay(s_ray.origin, s_ray.direction * distance, Color.red);
sfxSoundEntry.SetOccluded(true);
}
}
}
}
public static void RegisterEntry(SoundEntry soundEntryIn)
{
if (soundEntryIn is null) return;
if (SoundEntryList is null) return;
if (!soundEntryIn.UsesWallOcclusion) return;
SoundEntryList.Add(soundEntryIn);
}
public static void DeregisterEntry(SoundEntry soundEntryIn)
{
if (soundEntryIn is null) return;
if (SoundEntryList is null) return;
if (!soundEntryIn.UsesWallOcclusion) return;
_ = SoundEntryList.Remove(soundEntryIn);
}
#endregion
}
}