From 5865b402c7d9717373b28f82d9fbbe12b4505c50 Mon Sep 17 00:00:00 2001 From: cailean Date: Tue, 19 Mar 2024 12:54:10 +0000 Subject: [PATCH] audio obj fixed to check null --- Assets/4_Audio/Audio Script/AudioManager.cs | 31 ++++++++++----------- Assets/6_Scenes/Beep.unity | 18 ++++++------ Assets/ML-Agents/Timers/Beep_timers.json | 2 +- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/Assets/4_Audio/Audio Script/AudioManager.cs b/Assets/4_Audio/Audio Script/AudioManager.cs index 3cb362c..b89229d 100644 --- a/Assets/4_Audio/Audio Script/AudioManager.cs +++ b/Assets/4_Audio/Audio Script/AudioManager.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using System.Text.RegularExpressions; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UIElements; @@ -25,36 +26,32 @@ public class AudioManager : MonoBehaviour public void FootStepAudio( Vector3 bp_Position, float magnitude, PhysicMaterial groundType) { - AudioObject match = FindAudioObjectByType(groundType); - if (magnitude > match.m_VelcoityMin && match != null) - { - - Debug.Log($"{match.m_AudioClip.Count}"); - int randomClip = (int) Random.Range(0, match.m_AudioClip.Count - 1); - AudioClip randomPick = match.m_AudioClip[randomClip]; - // Play sound - if (randomPick != null) - { - float volume = Mathf.Lerp(0f, match.m_Volume, ( magnitude - match.m_VelcoityMin) / (match.m_VelcoityMax - match.m_VelcoityMin) ); - CustomAudioOneShot(bp_Position, randomPick, volume, match.m_PitchMin, match.m_PitchMax); - } - } + FindAudioObjectByType(groundType, magnitude, bp_Position); } - private AudioObject FindAudioObjectByType(PhysicMaterial groundType) + private AudioObject FindAudioObjectByType(PhysicMaterial groundType, float mag, Vector3 pos) { // Check for PM match foreach(AudioObject obj in m_AudioObjects) { if(obj.m_GroundType.name == groundType.name) { - return obj; + if (mag > obj.m_VelcoityMin ) + { + int randomClip = (int)Random.Range(0, obj.m_AudioClip.Count - 1); + AudioClip randomPick = obj.m_AudioClip[randomClip]; + // Play sound + if (randomPick != null) + { + float volume = Mathf.Lerp(0f, obj.m_Volume, (mag - obj.m_VelcoityMin) / (obj.m_VelcoityMax - obj.m_VelcoityMin)); + CustomAudioOneShot(pos, randomPick, volume, obj.m_PitchMin, obj.m_PitchMax); + } + } } } return null; } - void CustomAudioOneShot(Vector3 position, AudioClip clip, float volume, float pitchMin, float pitchMax) { diff --git a/Assets/6_Scenes/Beep.unity b/Assets/6_Scenes/Beep.unity index 7008d3a..1da5879 100644 --- a/Assets/6_Scenes/Beep.unity +++ b/Assets/6_Scenes/Beep.unity @@ -234,7 +234,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 83569712} serializedVersion: 2 - m_LocalRotation: {x: 0.020231629, y: 0.9743378, z: -0.097696625, w: 0.20177199} + m_LocalRotation: {x: 0.020231633, y: 0.9743378, z: -0.097696625, w: 0.20177202} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 @@ -392,7 +392,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 155411616} serializedVersion: 2 - m_LocalRotation: {x: 0.032237124, y: 0.96677077, z: -0.15566997, w: 0.200205} + m_LocalRotation: {x: 0.03223712, y: 0.96677077, z: -0.15566999, w: 0.20020498} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 @@ -516,7 +516,7 @@ Transform: m_GameObject: {fileID: 163243333} serializedVersion: 2 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 1.98, y: -31.69, z: 83.24} + m_LocalPosition: {x: -0.91, y: -32.51, z: 83.67} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -1097,7 +1097,7 @@ MonoBehaviour: LensShift: {x: 0, y: 0} GateFit: 1 FocusDistance: 8.93528 - m_SensorSize: {x: 1, y: 1} + m_SensorSize: {x: 36, y: 24} Iso: 50 ShutterSpeed: 0.0005 Aperture: 2.2 @@ -1250,7 +1250,7 @@ MonoBehaviour: LensShift: {x: 0, y: 0} GateFit: 1 FocusDistance: 0.01 - m_SensorSize: {x: 1, y: 1} + m_SensorSize: {x: 36, y: 24} Iso: 50 ShutterSpeed: 0.0005 Aperture: 1.9 @@ -1838,7 +1838,7 @@ MonoBehaviour: LensShift: {x: 0, y: 0} GateFit: 1 FocusDistance: 8.93528 - m_SensorSize: {x: 1, y: 1} + m_SensorSize: {x: 36, y: 24} Iso: 50 ShutterSpeed: 0.0005 Aperture: 2.2 @@ -1919,7 +1919,7 @@ MonoBehaviour: LensShift: {x: -0.21, y: 0.15} GateFit: 1 FocusDistance: 10 - m_SensorSize: {x: 1, y: 1} + m_SensorSize: {x: 36, y: 24} Iso: 50 ShutterSpeed: 0.0005 Aperture: 2.2 @@ -2141,7 +2141,7 @@ MonoBehaviour: LensShift: {x: 0, y: 0} GateFit: 1 FocusDistance: 8.93528 - m_SensorSize: {x: 1, y: 1} + m_SensorSize: {x: 36, y: 24} Iso: 50 ShutterSpeed: 0.0005 Aperture: 2.2 @@ -3001,7 +3001,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1178814724} serializedVersion: 2 - m_LocalRotation: {x: 0.020202018, y: 0.9790844, z: -0.16078894, w: 0.123015165} + m_LocalRotation: {x: 0.020202018, y: 0.9790844, z: -0.16078894, w: 0.12301517} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 diff --git a/Assets/ML-Agents/Timers/Beep_timers.json b/Assets/ML-Agents/Timers/Beep_timers.json index 6636590..0fe89f9 100644 --- a/Assets/ML-Agents/Timers/Beep_timers.json +++ b/Assets/ML-Agents/Timers/Beep_timers.json @@ -1 +1 @@ -{"count":1,"self":14.552531199999999,"total":14.7433307,"children":{"InitializeActuators":{"count":1,"self":0.0010002,"total":0.0010002,"children":null},"InitializeSensors":{"count":1,"self":0.0015033,"total":0.0015033,"children":null},"AgentSendState":{"count":438,"self":0.0095424999999999989,"total":0.0308739,"children":{"CollectObservations":{"count":88,"self":0.0050368,"total":0.0050368,"children":null},"WriteActionMask":{"count":88,"self":0,"total":0,"children":null},"RequestDecision":{"count":88,"self":0.0162946,"total":0.0162946,"children":null}}},"DecideAction":{"count":438,"self":0.1468667,"total":0.1468667,"children":{"RayPerceptionSensor.Perceive":{"count":88,"self":0,"total":0,"children":null}}},"AgentAct":{"count":438,"self":0.0090435999999999989,"total":0.0090435999999999989,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1710851850","unity_version":"2023.2.8f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2023.2.8f1\\Editor\\Unity.exe -projectpath C:\\Users\\caile\\Desktop\\Projects\\24_02-Beep\\4_Unity\\Beep Final Git\\beep-final -useHub -hubIPC -cloudEnvironment production","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.3.0-exp.3","scene_name":"Beep","end_time_seconds":"1710851865"}} \ No newline at end of file +{"count":1,"self":85.4708864,"total":86.2944977,"children":{"InitializeActuators":{"count":1,"self":0.0010007,"total":0.0010007,"children":null},"InitializeSensors":{"count":1,"self":0.0020039,"total":0.0020039,"children":null},"AgentSendState":{"count":4017,"self":0.0392186,"total":0.10328069999999999,"children":{"CollectObservations":{"count":804,"self":0.0306712,"total":0.0306712,"children":null},"WriteActionMask":{"count":804,"self":0.0019992,"total":0.0019992,"children":null},"RequestDecision":{"count":804,"self":0.0313917,"total":0.0313917,"children":null}}},"DecideAction":{"count":4017,"self":0.6761115,"total":0.6836808,"children":{"RayPerceptionSensor.Perceive":{"count":804,"self":0.0075692999999999993,"total":0.0075692999999999993,"children":null}}},"AgentAct":{"count":4017,"self":0.0336451,"total":0.0336451,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1710852750","unity_version":"2023.2.8f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2023.2.8f1\\Editor\\Unity.exe -projectpath C:\\Users\\caile\\Desktop\\Projects\\24_02-Beep\\4_Unity\\Beep Final Git\\beep-final -useHub -hubIPC -cloudEnvironment production","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.3.0-exp.3","scene_name":"Beep","end_time_seconds":"1710852836"}} \ No newline at end of file