Browse Source

sound component added + fixed dining room colliders

main
cailean 10 months ago
parent
commit
24116f4646
  1. 60
      Assets/15_Prefabs/Environment.prefab
  2. 67
      Assets/4_Audio/AudioManager.cs
  3. 2
      Assets/4_Audio/AudioManager.cs.meta
  4. 92
      Assets/6_Scenes/Beep.unity
  5. 4
      Assets/9_ML-Agents/Shared Assets MLA/SharedAssets/Scripts/GroundContact.cs
  6. 2
      Assets/ML-Agents/Timers/Beep_timers.json

60
Assets/15_Prefabs/Environment.prefab

@ -2103,7 +2103,7 @@ Transform:
m_GameObject: {fileID: 1659251163970791857} m_GameObject: {fileID: 1659251163970791857}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: 0.58692074, y: 0.3943656, z: 0.39436546, w: 0.5869205} m_LocalRotation: {x: 0.58692074, y: 0.3943656, z: 0.39436546, w: 0.5869205}
m_LocalPosition: {x: -5.4703593, y: 2.9263215, z: -0.00000015497207} m_LocalPosition: {x: -5.4703593, y: 2.926, z: 0.031}
m_LocalScale: {x: 0.021017924, y: 0.021017924, z: 0.021017924} m_LocalScale: {x: 0.021017924, y: 0.021017924, z: 0.021017924}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
@ -7236,7 +7236,7 @@ Transform:
m_GameObject: {fileID: 5566058129359696478} m_GameObject: {fileID: 5566058129359696478}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 1.25} m_LocalPosition: {x: -0, y: -1.04, z: 1.19}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
@ -13346,11 +13346,61 @@ PrefabInstance:
serializedVersion: 3 serializedVersion: 3
m_TransformParent: {fileID: 3654837400929340511} m_TransformParent: {fileID: 3654837400929340511}
m_Modifications: m_Modifications:
- target: {fileID: 337960273187071008, guid: f852e5215ffc0594285d58b5bcb2d126,
type: 3}
propertyPath: m_LocalPosition.y
value: 2.378
objectReference: {fileID: 0}
- target: {fileID: 337960273187071008, guid: f852e5215ffc0594285d58b5bcb2d126,
type: 3}
propertyPath: m_LocalPosition.z
value: 0.773
objectReference: {fileID: 0}
- target: {fileID: 1252051785957965868, guid: f852e5215ffc0594285d58b5bcb2d126,
type: 3}
propertyPath: m_LocalPosition.y
value: 3.767
objectReference: {fileID: 0}
- target: {fileID: 1252051785957965868, guid: f852e5215ffc0594285d58b5bcb2d126,
type: 3}
propertyPath: m_LocalPosition.z
value: 0.775
objectReference: {fileID: 0}
- target: {fileID: 2304576965709822919, guid: f852e5215ffc0594285d58b5bcb2d126, - target: {fileID: 2304576965709822919, guid: f852e5215ffc0594285d58b5bcb2d126,
type: 3} type: 3}
propertyPath: m_Name propertyPath: m_Name
value: Dining Table value: Dining Table
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4260752997967315586, guid: f852e5215ffc0594285d58b5bcb2d126,
type: 3}
propertyPath: m_LocalPosition.y
value: 2.369
objectReference: {fileID: 0}
- target: {fileID: 4260752997967315586, guid: f852e5215ffc0594285d58b5bcb2d126,
type: 3}
propertyPath: m_LocalPosition.z
value: 0.773
objectReference: {fileID: 0}
- target: {fileID: 5476141641756825752, guid: f852e5215ffc0594285d58b5bcb2d126,
type: 3}
propertyPath: m_LocalPosition.y
value: 3.804
objectReference: {fileID: 0}
- target: {fileID: 5476141641756825752, guid: f852e5215ffc0594285d58b5bcb2d126,
type: 3}
propertyPath: m_LocalPosition.z
value: 0.787
objectReference: {fileID: 0}
- target: {fileID: 5551979329418801648, guid: f852e5215ffc0594285d58b5bcb2d126,
type: 3}
propertyPath: m_LocalPosition.y
value: 3.179
objectReference: {fileID: 0}
- target: {fileID: 5551979329418801648, guid: f852e5215ffc0594285d58b5bcb2d126,
type: 3}
propertyPath: m_LocalPosition.z
value: 0.677
objectReference: {fileID: 0}
- target: {fileID: 8661213834174352756, guid: f852e5215ffc0594285d58b5bcb2d126, - target: {fileID: 8661213834174352756, guid: f852e5215ffc0594285d58b5bcb2d126,
type: 3} type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
@ -13547,7 +13597,7 @@ PrefabInstance:
- target: {fileID: 5280690637785505442, guid: a675ba6e3554386459dabb984271bfab, - target: {fileID: 5280690637785505442, guid: a675ba6e3554386459dabb984271bfab,
type: 3} type: 3}
propertyPath: m_Layer propertyPath: m_Layer
value: 7 value: 3
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5499488596631623843, guid: a675ba6e3554386459dabb984271bfab, - target: {fileID: 5499488596631623843, guid: a675ba6e3554386459dabb984271bfab,
type: 3} type: 3}
@ -13557,12 +13607,12 @@ PrefabInstance:
- target: {fileID: 6409585968859697487, guid: a675ba6e3554386459dabb984271bfab, - target: {fileID: 6409585968859697487, guid: a675ba6e3554386459dabb984271bfab,
type: 3} type: 3}
propertyPath: m_Layer propertyPath: m_Layer
value: 7 value: 3
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7719826384157559048, guid: a675ba6e3554386459dabb984271bfab, - target: {fileID: 7719826384157559048, guid: a675ba6e3554386459dabb984271bfab,
type: 3} type: 3}
propertyPath: m_Layer propertyPath: m_Layer
value: 7 value: 3
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8830648566165926502, guid: a675ba6e3554386459dabb984271bfab, - target: {fileID: 8830648566165926502, guid: a675ba6e3554386459dabb984271bfab,
type: 3} type: 3}

67
Assets/4_Audio/AudioManager.cs

@ -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);
}
}

2
Assets/4_Audio/AudioManager.cs.meta

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 953a08eddf4c70249933c26b006dbb7b

92
Assets/6_Scenes/Beep.unity

@ -674,7 +674,7 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 377437129} m_GameObject: {fileID: 377437129}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: -0.03783877, y: 0.8817097, z: -0.07178479, w: -0.46476156} m_LocalRotation: {x: -0.037838772, y: 0.8817097, z: -0.071784794, w: -0.46476156}
m_LocalPosition: {x: -128.4, y: 13, z: -248.6} m_LocalPosition: {x: -128.4, y: 13, z: -248.6}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
@ -1063,9 +1063,9 @@ Camera:
m_FOVAxisMode: 0 m_FOVAxisMode: 0
m_Iso: 50 m_Iso: 50
m_ShutterSpeed: 0.0005 m_ShutterSpeed: 0.0005
m_Aperture: 1.9 m_Aperture: 2.2
m_FocusDistance: 67.52423 m_FocusDistance: 8.93528
m_FocalLength: 35 m_FocalLength: 5.9999995
m_BladeCount: 5 m_BladeCount: 5
m_Curvature: {x: 2, y: 11} m_Curvature: {x: 2, y: 11}
m_BarrelClipping: 0.25 m_BarrelClipping: 0.25
@ -1080,7 +1080,7 @@ Camera:
height: 1 height: 1
near clip plane: 0.01 near clip plane: 0.01
far clip plane: 5000 far clip plane: 5000
field of view: 37.84929 field of view: 126.8699
orthographic: 0 orthographic: 0
orthographic size: 10 orthographic size: 10
m_Depth: 0 m_Depth: 0
@ -1106,8 +1106,8 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 470663197} m_GameObject: {fileID: 470663197}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: -0.03783877, y: 0.8817097, z: -0.07178479, w: -0.46476156} m_LocalRotation: {x: 0.29879025, y: -0.6448607, z: 0.2788991, w: 0.64582855}
m_LocalPosition: {x: -128.4, y: 13, z: -248.6} m_LocalPosition: {x: 41.58, y: 5.960001, z: -7.8299866}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
@ -1281,6 +1281,53 @@ Transform:
type: 3} type: 3}
m_PrefabInstance: {fileID: 1412792145} m_PrefabInstance: {fileID: 1412792145}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!1 &699570147
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 699570148}
- component: {fileID: 699570149}
m_Layer: 0
m_Name: Audio Manager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &699570148
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 699570147}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1633830349}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &699570149
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 699570147}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 953a08eddf4c70249933c26b006dbb7b, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FootStepMinVelocity: 10
m_FootStepMaxVelocity: 20
m_FootStep: {fileID: 8300000, guid: 4504e7a182be36a40ab60949991502fd, type: 3}
--- !u!1 &707081198 --- !u!1 &707081198
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2551,6 +2598,7 @@ Transform:
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: m_Children:
- {fileID: 219793650} - {fileID: 219793650}
- {fileID: 699570148}
m_Father: {fileID: 160784038} m_Father: {fileID: 160784038}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1637099438 --- !u!1 &1637099438
@ -3151,36 +3199,6 @@ PrefabInstance:
serializedVersion: 3 serializedVersion: 3
m_TransformParent: {fileID: 0} m_TransformParent: {fileID: 0}
m_Modifications: m_Modifications:
- target: {fileID: 788867738177514625, guid: 14d8283abcefffd4a916b8611ccd49fa,
type: 3}
propertyPath: m_Layer
value: 3
objectReference: {fileID: 0}
- target: {fileID: 1744424756382034348, guid: 14d8283abcefffd4a916b8611ccd49fa,
type: 3}
propertyPath: m_LocalPosition.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1744424756382034348, guid: 14d8283abcefffd4a916b8611ccd49fa,
type: 3}
propertyPath: m_LocalPosition.y
value: -1.04
objectReference: {fileID: 0}
- target: {fileID: 1744424756382034348, guid: 14d8283abcefffd4a916b8611ccd49fa,
type: 3}
propertyPath: m_LocalPosition.z
value: 1.19
objectReference: {fileID: 0}
- target: {fileID: 1966167951569347436, guid: 14d8283abcefffd4a916b8611ccd49fa,
type: 3}
propertyPath: m_Layer
value: 3
objectReference: {fileID: 0}
- target: {fileID: 2925090289982896939, guid: 14d8283abcefffd4a916b8611ccd49fa,
type: 3}
propertyPath: m_Layer
value: 3
objectReference: {fileID: 0}
- target: {fileID: 3006033085249723243, guid: 14d8283abcefffd4a916b8611ccd49fa, - target: {fileID: 3006033085249723243, guid: 14d8283abcefffd4a916b8611ccd49fa,
type: 3} type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x

4
Assets/9_ML-Agents/Shared Assets MLA/SharedAssets/Scripts/GroundContact.cs

@ -49,6 +49,9 @@ namespace Unity.MLAgentsExamples
{ {
agent.EndEpisode(); agent.EndEpisode();
} }
if(isFoot)
AudioManager.instance.FootStepAudio(col.transform.position, col.relativeVelocity.magnitude, k_Ground);
} }
if (col.transform.CompareTag(k_Stairs)) if (col.transform.CompareTag(k_Stairs))
@ -57,6 +60,7 @@ namespace Unity.MLAgentsExamples
if(isFoot) if(isFoot)
{ {
agent.AddReward(0.002f); agent.AddReward(0.002f);
AudioManager.instance.FootStepAudio(col.transform.position, col.relativeVelocity.magnitude, k_Stairs);
} }
if (isBody) if (isBody)
{ {

2
Assets/ML-Agents/Timers/Beep_timers.json

@ -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…
Cancel
Save