16 [Header(
"Assign AudioSources for each speaker")]
17 [SerializeField]
private AudioSource speaker0_FrontLeft;
18 [SerializeField]
private AudioSource speaker1_FrontRight;
19 [SerializeField]
private AudioSource speaker2_Center;
20 [SerializeField]
private AudioSource speaker4_RearLeft;
21 [SerializeField]
private AudioSource speaker5_RearRight;
22 [SerializeField]
private AudioSource speaker6_SideLeft;
23 [SerializeField]
private AudioSource speaker7_SideRight;
25 [Header(
"Select which speaker to play")]
30 AudioSource selectedSource = GetSelectedSource();
32 if (selectedSource ==
null)
35 if (selectedSource.isPlaying)
37 selectedSource.Stop();
42 selectedSource.Play();
46 private void StopAll()
48 speaker0_FrontLeft?.Stop();
49 speaker1_FrontRight?.Stop();
50 speaker2_Center?.Stop();
51 speaker4_RearLeft?.Stop();
52 speaker5_RearRight?.Stop();
53 speaker6_SideLeft?.Stop();
54 speaker7_SideRight?.Stop();
57 private AudioSource GetSelectedSource()
59 return speakerToPlay
switch
61 SpeakerPosition.Speaker_0_FrontLeft => speaker0_FrontLeft,
62 SpeakerPosition.Speaker_1_FrontRight => speaker1_FrontRight,
63 SpeakerPosition.Speaker_2_Center => speaker2_Center,
64 SpeakerPosition.Speaker_4_RearLeft => speaker4_RearLeft,
65 SpeakerPosition.Speaker_5_RearRight => speaker5_RearRight,
66 SpeakerPosition.Speaker_6_SideLeft => speaker6_SideLeft,
67 SpeakerPosition.Speaker_7_SideRight => speaker7_SideRight,
74 private class SoundControllerEditor : UnityEditor.Editor
76 public override void OnInspectorGUI()
78 DrawDefaultInspector();
82 if (GUILayout.Button(
"▶ Play/Stop Selected Speaker"))
87 if (GUILayout.Button(
"⏹ Stop All"))
89 controller.SendMessage(
"StopAll", SendMessageOptions.DontRequireReceiver);