diff --git a/AVVR/Assets/Prefabs/InteractableAudioSource.prefab b/AVVR/Assets/Prefabs/InteractableAudioSource.prefab index 2c719084d78d5cb5da24b85c6cfd3b0df4bc28a2..dd733ad4bdea2777def6f399d0a35f9d40e02682 100644 --- a/AVVR/Assets/Prefabs/InteractableAudioSource.prefab +++ b/AVVR/Assets/Prefabs/InteractableAudioSource.prefab @@ -46,8 +46,8 @@ AudioSource: m_GameObject: {fileID: 1342686809196105485} m_Enabled: 1 serializedVersion: 4 - OutputAudioMixerGroup: {fileID: -591816330462743613, guid: 73cd42cb6edc7ea469c14aaec3bdf65a, type: 2} - m_audioClip: {fileID: 8300000, guid: cf23dd16f3fb8fb4f8c1eefd386a17c4, type: 3} + OutputAudioMixerGroup: {fileID: 24300002, guid: 73cd42cb6edc7ea469c14aaec3bdf65a, type: 2} + m_audioClip: {fileID: 0} m_PlayOnAwake: 1 m_Volume: 0.5 m_Pitch: 1 diff --git a/AVVR/Assets/Prefabs/VR Menu.prefab b/AVVR/Assets/Prefabs/VR Menu.prefab index 73eb5fb605765f7e9153da4602de79289ccd4da1..1a00694ae948d4bb1408c618401943f53d50c1c8 100644 --- a/AVVR/Assets/Prefabs/VR Menu.prefab +++ b/AVVR/Assets/Prefabs/VR Menu.prefab @@ -773,7 +773,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 6477512983158778462, guid: 085ce58b196caa446a8545c9dd388793, type: 3} propertyPath: m_Size - value: 1 + value: 0.99999994 objectReference: {fileID: 0} - target: {fileID: 6477512983158778462, guid: 085ce58b196caa446a8545c9dd388793, type: 3} propertyPath: m_Value @@ -1304,9 +1304,6 @@ MonoBehaviour: continuousTurnProvider: {fileID: 0} snapTurnProvider: {fileID: 0} interactableAudioSource: {fileID: 0} - musicClip: {fileID: 8300000, guid: cf23dd16f3fb8fb4f8c1eefd386a17c4, type: 3} - singingClip: {fileID: 8300000, guid: 0e78dc9e29e82594b8b4e8644cd68717, type: 3} - speakingClip: {fileID: 8300000, guid: 0d91549d8854aff46bcbeb294b8bc658, type: 3} menuSceneName: MenuInterface --- !u!4 &2202784744584957300 stripped Transform: @@ -1587,9 +1584,13 @@ PrefabInstance: propertyPath: m_text value: Change Audio objectReference: {fileID: 0} + - target: {fileID: 6507499350661501903, guid: f47ad6ac315a3ea428b59e2cac6f2a2e, type: 3} + propertyPath: m_Enabled + value: 1 + objectReference: {fileID: 0} - target: {fileID: 6507499350661501903, guid: f47ad6ac315a3ea428b59e2cac6f2a2e, type: 3} propertyPath: m_Options.m_Options.Array.size - value: 4 + value: 5 objectReference: {fileID: 0} - target: {fileID: 6507499350661501903, guid: f47ad6ac315a3ea428b59e2cac6f2a2e, type: 3} propertyPath: m_Options.m_Options.Array.data[0].m_Text @@ -1601,11 +1602,31 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 6507499350661501903, guid: f47ad6ac315a3ea428b59e2cac6f2a2e, type: 3} propertyPath: m_Options.m_Options.Array.data[2].m_Text - value: Speaking (Quiet) + value: Speaking (Loud) objectReference: {fileID: 0} - target: {fileID: 6507499350661501903, guid: f47ad6ac315a3ea428b59e2cac6f2a2e, type: 3} propertyPath: m_Options.m_Options.Array.data[3].m_Text - value: Speaking (Loud) + value: Speaking (Quiet) + objectReference: {fileID: 0} + - target: {fileID: 6507499350661501903, guid: f47ad6ac315a3ea428b59e2cac6f2a2e, type: 3} + propertyPath: m_Options.m_Options.Array.data[4].m_Text + value: Singing (Ringtone) + objectReference: {fileID: 0} + - target: {fileID: 6507499350661501903, guid: f47ad6ac315a3ea428b59e2cac6f2a2e, type: 3} + propertyPath: m_OnValueChanged.m_PersistentCalls.m_Calls.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6507499350661501903, guid: f47ad6ac315a3ea428b59e2cac6f2a2e, type: 3} + propertyPath: m_OnValueChanged.m_PersistentCalls.m_Calls.Array.data[0].m_Mode + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 6507499350661501903, guid: f47ad6ac315a3ea428b59e2cac6f2a2e, type: 3} + propertyPath: m_OnValueChanged.m_PersistentCalls.m_Calls.Array.data[0].m_CallState + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 6599802745008049902, guid: f47ad6ac315a3ea428b59e2cac6f2a2e, type: 3} + propertyPath: m_SizeDelta.y + value: 300 objectReference: {fileID: 0} - target: {fileID: 6599802745974732893, guid: f47ad6ac315a3ea428b59e2cac6f2a2e, type: 3} propertyPath: m_text diff --git a/AVVR/Assets/Resources/Sounds/Ringtone_diy.wav b/AVVR/Assets/Resources/Sounds/Ringtone_diy.wav new file mode 100644 index 0000000000000000000000000000000000000000..27cb4844264cfe30b98ef8f2ccfd1b8c48a21701 Binary files /dev/null and b/AVVR/Assets/Resources/Sounds/Ringtone_diy.wav differ diff --git a/AVVR/Assets/Resources/Sounds/Ringtone_diy.wav.meta b/AVVR/Assets/Resources/Sounds/Ringtone_diy.wav.meta new file mode 100644 index 0000000000000000000000000000000000000000..70184b7f1178a871a2681f310139f7ab37d6a8ae --- /dev/null +++ b/AVVR/Assets/Resources/Sounds/Ringtone_diy.wav.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: a57306c7467bced4a93a3e1edffef347 +AudioImporter: + externalObjects: {} + serializedVersion: 7 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 1 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/AVVR/Assets/_Scripts/VRMenu.cs b/AVVR/Assets/_Scripts/VRMenu.cs index 2aaefe8e77829410bec62fa13b977163f00474e4..5f81404a1ecf1e5e27fc031c3c0fd781edd5269c 100644 --- a/AVVR/Assets/_Scripts/VRMenu.cs +++ b/AVVR/Assets/_Scripts/VRMenu.cs @@ -15,7 +15,13 @@ public class VRMenu : MonoBehaviour private readonly Vector3 defaultPosition = new Vector3(0f, 1f, 1.5f); private List<InputDevice> gameControllers = new List<InputDevice>(); private Canvas menuCanvas; - + + private AudioClip musicClip; + private AudioClip singingClip; + private AudioClip speakingClipLoud; + private AudioClip speakingClipQuiet; + private AudioClip singingClip2; + [Header("UI Components")] [SerializeField] private Slider volumeSlider; [SerializeField] private TMP_Text volumeValueText; // Add reference for volume text @@ -30,10 +36,6 @@ public class VRMenu : MonoBehaviour [Header("Audio Configuration")] [SerializeField] private AudioSource interactableAudioSource; // Reference to your InteractableAudioSource - [SerializeField] private AudioClip musicClip; // Will hold Music_long.wav - [SerializeField] private AudioClip singingClip; // Will hold Joao-Anthem1.mp3 - [SerializeField] private AudioClip speakingClipQuiet; // Will hold Rachel.mp3 - [SerializeField] private AudioClip speakingClipLoud; // Will hold Speech-Org.mp3 [Header("Scene Management")] [SerializeField] private string menuSceneName = "MenuInterface"; @@ -64,35 +66,68 @@ public class VRMenu : MonoBehaviour InputDevices.GetDevicesWithCharacteristics(desiredCharacteristics, gameControllers); } - private void Update() +private float debounceTime = 0.3f; // Time required between button presses +private float lastSecondaryButtonPress = 0f; + +private void Update() +{ + if (gameControllers.Count == 0) { - if (gameControllers.Count == 0) - { - InitializeControllers(); - return; - } + InitializeControllers(); + return; + } - bool primaryButtonPressed = false; + bool primaryButtonPressed = false; + bool secondaryButtonPressed = false; - foreach (var device in gameControllers) + foreach (var device in gameControllers) + { + if (device.TryGetFeatureValue(CommonUsages.primaryButton, out bool primaryPressed)) { - if (device.TryGetFeatureValue(CommonUsages.primaryButton, out bool pressed)) + if (primaryPressed) { - if (pressed) - { - primaryButtonPressed = true; - break; - } + primaryButtonPressed = true; } } - if (primaryButtonPressed && !wasPressed) + if (device.TryGetFeatureValue(CommonUsages.secondaryButton, out bool secondaryPressed)) { - ToggleMenuVisibility(); + if (secondaryPressed && !wasPressed && Time.time - lastSecondaryButtonPress >= debounceTime) + { + ToggleAudioPlayback(); + lastSecondaryButtonPress = Time.time; + } + secondaryButtonPressed = secondaryPressed; } - wasPressed = primaryButtonPressed; } + if (primaryButtonPressed && !wasPressed) + { + ToggleMenuVisibility(); + } + wasPressed = primaryButtonPressed || secondaryButtonPressed; +} + +private void ToggleAudioPlayback() +{ + if (interactableAudioSource == null) + { + Debug.LogError("VRMenu: InteractableAudioSource is not assigned or found in scene"); + return; + } + + if (interactableAudioSource.isPlaying) + { + interactableAudioSource.Pause(); + Debug.Log("VRMenu: Audio paused"); + } + else + { + interactableAudioSource.Play(); + Debug.Log("VRMenu: Audio playing"); + } +} + private void ToggleMenuVisibility() { isMenuVisible = !isMenuVisible; @@ -213,6 +248,7 @@ public class VRMenu : MonoBehaviour if (audioDropdown != null) { audioDropdown.value = savedAudioOption; + HandleAudioChange(savedAudioOption); Debug.Log($"VRMenu: Loaded audio option: {savedAudioOption}"); } } @@ -296,13 +332,17 @@ public class VRMenu : MonoBehaviour interactableAudioSource.clip = singingClip; Debug.Log("VRMenu: Switched to Singing clip"); break; - case 2: // Speaking (Quiet) + case 2: // Speaking (Loud) + interactableAudioSource.clip = speakingClipLoud; + Debug.Log("VRMenu: Switched to Speaking clip (Loud)"); + break; + case 3: // Speaking (Quiet) interactableAudioSource.clip = speakingClipQuiet; Debug.Log("VRMenu: Switched to Speaking clip (Quiet)"); break; - case 3: // Speaking (Loud) - interactableAudioSource.clip = speakingClipLoud; - Debug.Log("VRMenu: Switched to Speaking clip (Loud)"); + case 4: // Singing 2 + interactableAudioSource.clip = singingClip2; + Debug.Log("VRMenu: Switched to Singing 2 clip"); break; default: Debug.LogWarning($"VRMenu: Unknown audio option selected: {option}"); @@ -322,19 +362,20 @@ public class VRMenu : MonoBehaviour } private void LoadAudioClips() -{ - // Load all audio clips - musicClip = Resources.Load<AudioClip>("Sounds/Music_long"); - singingClip = Resources.Load<AudioClip>("Sounds/Joao-Anthem1"); - speakingClipQuiet = Resources.Load<AudioClip>("Sounds/Rachel"); - speakingClipLoud = Resources.Load<AudioClip>("Sounds/Speech-Org"); - - if (musicClip == null) Debug.LogError("VRMenu: Failed to load Music_long.wav"); - if (singingClip == null) Debug.LogError("VRMenu: Failed to load Joao-Anthem1.mp3"); - if (speakingClipQuiet == null) Debug.LogError("VRMenu: Failed to load Rachel.mp3"); - if (speakingClipLoud == null) Debug.LogError("VRMenu: Failed to load Speech-Org.mp3"); -} - + { + // Load all audio clips from Resources folder + musicClip = Resources.Load<AudioClip>("Sounds/Music_long"); + singingClip = Resources.Load<AudioClip>("Sounds/Joao-Anthem1"); + speakingClipLoud = Resources.Load<AudioClip>("Sounds/Speech-Org"); + speakingClipQuiet = Resources.Load<AudioClip>("Sounds/Rachel"); + singingClip2 = Resources.Load<AudioClip>("Sounds/Ringtone_diy"); + + if (musicClip == null) Debug.LogError("VRMenu: Failed to load Music_long.wav"); + if (singingClip == null) Debug.LogError("VRMenu: Failed to load Joao-Anthem1.mp3"); + if (speakingClipLoud == null) Debug.LogError("VRMenu: Failed to load Speech-Org.mp3"); + if (speakingClipQuiet == null) Debug.LogError("VRMenu: Failed to load Rachel.mp3"); + if (singingClip2 == null) Debug.LogError("VRMenu: Failed to load Ringtone_diy.mp3"); + } public void ExitToMenu() { Debug.Log("VRMenu: Exiting to menu");