Browse Source

audio obj fixed to check null

main
cailean 7 months ago
parent
commit
5865b402c7
  1. 31
      Assets/4_Audio/Audio Script/AudioManager.cs
  2. 18
      Assets/6_Scenes/Beep.unity
  3. 2
      Assets/ML-Agents/Timers/Beep_timers.json

31
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)
{

18
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

2
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"}}
{"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"}}
Loading…
Cancel
Save