cailean
10 months ago
6 changed files with 184 additions and 43 deletions
@ -0,0 +1,67 @@ |
|||||
|
using System.Collections; |
||||
|
using System.Collections.Generic; |
||||
|
using Unity.VisualScripting; |
||||
|
using UnityEngine; |
||||
|
using UnityEngine.UIElements; |
||||
|
using static Unity.Barracuda.TextureAsTensorData; |
||||
|
using static UnityEditor.PlayerSettings; |
||||
|
|
||||
|
public class AudioManager : MonoBehaviour |
||||
|
{ |
||||
|
public static AudioManager instance { get; private set; } |
||||
|
|
||||
|
public float m_FootStepMinVelocity = 5; |
||||
|
|
||||
|
public float m_FootStepMaxVelocity = 40; |
||||
|
|
||||
|
public AudioClip m_FootStep; |
||||
|
|
||||
|
private void Awake() |
||||
|
{ |
||||
|
if(instance != null && instance != this) |
||||
|
{ |
||||
|
Destroy(this); |
||||
|
} else |
||||
|
{ |
||||
|
instance = this; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void FootStepAudio( Vector3 bp_Position, float magnitude, string groundType ) |
||||
|
{ |
||||
|
|
||||
|
if (magnitude > m_FootStepMinVelocity) |
||||
|
{ |
||||
|
// Play sound
|
||||
|
if (m_FootStep != null) |
||||
|
{ |
||||
|
float volume = Mathf.Lerp(0f, 1f, ( magnitude - m_FootStepMinVelocity) / (m_FootStepMaxVelocity - m_FootStepMinVelocity) ); |
||||
|
Debug.Log($"{magnitude}, {groundType}, {volume}"); |
||||
|
CustomAudioOneShot(bp_Position, m_FootStep, volume); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
void CustomAudioOneShot(Vector3 position, AudioClip clip, float volume) |
||||
|
{ |
||||
|
|
||||
|
GameObject audioObject = new GameObject("FootstepAudio"); |
||||
|
audioObject.transform.position = position; |
||||
|
|
||||
|
// Add an AudioSource component to the GameObject
|
||||
|
AudioSource audioSource = audioObject.AddComponent<AudioSource>(); |
||||
|
|
||||
|
// Set the AudioClip to play
|
||||
|
audioSource.clip = clip; |
||||
|
|
||||
|
// Adjust sound properties
|
||||
|
audioSource.volume = Mathf.Pow((volume), 2); // Adjust the volume (0.0f to 1.0f)
|
||||
|
audioSource.pitch = Random.Range(0.7f, 1.3f); // Randomize the pitch within a range (e.g., 0.9 to 1.1)
|
||||
|
// You can adjust other properties here such as spatial blend, loop, etc.
|
||||
|
|
||||
|
// Play the sound
|
||||
|
audioSource.Play(); |
||||
|
|
||||
|
// Clean up the GameObject after the sound finishes playing
|
||||
|
Destroy(audioObject, m_FootStep.length); |
||||
|
} |
||||
|
} |
@ -0,0 +1,2 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 953a08eddf4c70249933c26b006dbb7b |
@ -1 +1 @@ |
|||||
{"count":1,"self":28.310783999999998,"total":28.555429699999998,"children":{"InitializeActuators":{"count":1,"self":0.0020306,"total":0.0020306,"children":null},"InitializeSensors":{"count":1,"self":0.0015023999999999999,"total":0.0015023999999999999,"children":null},"AgentSendState":{"count":1133,"self":0.0085603,"total":0.026192999999999998,"children":{"CollectObservations":{"count":227,"self":0.0075509999999999996,"total":0.0075509999999999996,"children":null},"WriteActionMask":{"count":227,"self":0,"total":0,"children":null},"RequestDecision":{"count":227,"self":0.010081699999999999,"total":0.010081699999999999,"children":null}}},"DecideAction":{"count":1133,"self":0.2013495,"total":0.20385799999999998,"children":{"RayPerceptionSensor.Perceive":{"count":227,"self":0.0025085,"total":0.0025085,"children":null}}},"AgentAct":{"count":1133,"self":0.010551399999999999,"total":0.010551399999999999,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1709911558","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":"1709911587"}} |
{"count":1,"self":20.3646688,"total":20.5420171,"children":{"InitializeActuators":{"count":1,"self":0.0015050999999999999,"total":0.0015050999999999999,"children":null},"InitializeSensors":{"count":1,"self":0.0025031999999999997,"total":0.0025031999999999997,"children":null},"AgentSendState":{"count":701,"self":0.0060109,"total":0.018592499999999998,"children":{"CollectObservations":{"count":141,"self":0.002516,"total":0.002516,"children":null},"WriteActionMask":{"count":141,"self":0.00099969999999999985,"total":0.00099969999999999985,"children":null},"RequestDecision":{"count":141,"self":0.0090659,"total":0.0090659,"children":null}}},"DecideAction":{"count":701,"self":0.1466916,"total":0.1502067,"children":{"RayPerceptionSensor.Perceive":{"count":141,"self":0.0035150999999999997,"total":0.0035150999999999997,"children":null}}},"AgentAct":{"count":701,"self":0.0045416,"total":0.0045416,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1709914489","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":"1709914510"}} |
Loading…
Reference in new issue