diff --git a/Assets/Resources/Prefabs/Sound.meta b/Assets/Resources/Prefabs/Sound.meta new file mode 100644 index 0000000..b1b7ab6 --- /dev/null +++ b/Assets/Resources/Prefabs/Sound.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 48dcd50c6eacab640bcf38649d7f3a7d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Prefabs/Sound/Audio Source.prefab b/Assets/Resources/Prefabs/Sound/Audio Source.prefab new file mode 100644 index 0000000..c4b8172 --- /dev/null +++ b/Assets/Resources/Prefabs/Sound/Audio Source.prefab @@ -0,0 +1,131 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &7070934177775682985 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 944501444550833281} + - component: {fileID: 3317408524915037535} + m_Layer: 0 + m_Name: Audio Source + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &944501444550833281 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7070934177775682985} + 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: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!82 &3317408524915037535 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7070934177775682985} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 0} + m_Resource: {fileID: 0} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 1 + Loop: 0 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 0 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 diff --git a/Assets/Resources/Prefabs/Sound/Audio Source.prefab.meta b/Assets/Resources/Prefabs/Sound/Audio Source.prefab.meta new file mode 100644 index 0000000..8ba84c9 --- /dev/null +++ b/Assets/Resources/Prefabs/Sound/Audio Source.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3758df6f658743a458b1e3406342e7de +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Sounds/Test-bruit-court.wav b/Assets/Resources/Sounds/Test-bruit-court.wav new file mode 100644 index 0000000..6b29e0e Binary files /dev/null and b/Assets/Resources/Sounds/Test-bruit-court.wav differ diff --git a/Assets/Resources/Sounds/Test-bruit-court.wav.meta b/Assets/Resources/Sounds/Test-bruit-court.wav.meta new file mode 100644 index 0000000..10e2351 --- /dev/null +++ b/Assets/Resources/Sounds/Test-bruit-court.wav.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 2e41a111eebf71843a1cbf93be5a9e1c +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 0cb206a..95948f7 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -311,6 +311,96 @@ Rigidbody: m_Interpolate: 0 m_Constraints: 112 m_CollisionDetection: 0 +--- !u!1 &169666004 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 169666005} + - component: {fileID: 169666006} + m_Layer: 0 + m_Name: MusicManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &169666005 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 169666004} + 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: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &169666006 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 169666004} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4f4c60501663689458019872e34e9c48, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!1 &266152666 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 266152667} + - component: {fileID: 266152668} + m_Layer: 0 + m_Name: SoundManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &266152667 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 266152666} + 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: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &266152668 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 266152666} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: cc230848cf9fffe40aed130aeee564f8, type: 3} + m_Name: + m_EditorClassIdentifier: + initialPoolSize: 10 + audioSourcePrefab: {fileID: 7070934177775682985, guid: 3758df6f658743a458b1e3406342e7de, type: 3} --- !u!1 &272243392 GameObject: m_ObjectHideFlags: 0 @@ -669,6 +759,52 @@ MonoBehaviour: m_LightCookieSize: {x: 1, y: 1} m_LightCookieOffset: {x: 0, y: 0} m_SoftShadowQuality: 1 +--- !u!1 &432444065 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 432444066} + - component: {fileID: 432444067} + m_Layer: 0 + m_Name: Triggerable music + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &432444066 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 432444065} + 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: + - {fileID: 1512154480} + m_Father: {fileID: 621578838} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &432444067 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 432444065} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0c3454cc62eba27469e9581fb0fb8703, type: 3} + m_Name: + m_EditorClassIdentifier: + music: {fileID: 1512154481} --- !u!1 &493760349 GameObject: m_ObjectHideFlags: 0 @@ -724,6 +860,130 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5a895e8a798ee0b4a9a5ea33d6b07f4b, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!1 &621578834 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 621578838} + - component: {fileID: 621578837} + - component: {fileID: 621578836} + - component: {fileID: 621578835} + - component: {fileID: 621578839} + m_Layer: 0 + m_Name: TriggerZone + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!65 &621578835 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 621578834} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 1 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &621578836 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 621578834} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RayTracingAccelStructBuildFlagsOverride: 0 + m_RayTracingAccelStructBuildFlags: 1 + m_SmallMeshCulling: 1 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &621578837 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 621578834} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &621578838 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 621578834} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 4.22, y: 0.71, z: -7.71} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 432444066} + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &621578839 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 621578834} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: eb3300468ed86d74d9fce3c293a89442, type: 3} + m_Name: + m_EditorClassIdentifier: + activableTriggers: + - {fileID: 432444067} --- !u!1 &990919146 GameObject: m_ObjectHideFlags: 0 @@ -767,6 +1027,7 @@ GameObject: - component: {fileID: 1192843595} - component: {fileID: 1192843594} - component: {fileID: 1192843593} + - component: {fileID: 1192843596} m_Layer: 0 m_Name: Slope m_TagString: Untagged @@ -786,7 +1047,8 @@ Transform: m_LocalPosition: {x: -5.5, y: 1.13, z: -6.62} m_LocalScale: {x: 0.5, y: 1, z: 0.5} m_ConstrainProportionsScale: 0 - m_Children: [] + m_Children: + - {fileID: 1646350200} m_Father: {fileID: 90518572} m_LocalEulerAnglesHint: {x: 0, y: 0, z: -28.7} --- !u!64 &1192843593 @@ -864,6 +1126,110 @@ MeshFilter: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1192843591} m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} +--- !u!114 &1192843596 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1192843591} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ce02cde7ea924d943a1cae7e8fa23c97, type: 3} + m_Name: + m_EditorClassIdentifier: + triggerables: + - {fileID: 1646350201} +--- !u!1 &1512154479 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1512154480} + - component: {fileID: 1512154481} + m_Layer: 0 + m_Name: Music + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1512154480 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1512154479} + 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: 432444066} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1512154481 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1512154479} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 287885c28387db147b2ed37b247e9fc2, type: 3} + m_Name: + m_EditorClassIdentifier: + sound: {fileID: 8300000, guid: 2e41a111eebf71843a1cbf93be5a9e1c, type: 3} +--- !u!1 &1646350199 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1646350200} + - component: {fileID: 1646350201} + m_Layer: 0 + m_Name: Triggerable sound + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1646350200 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1646350199} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -12.26, y: -0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1192843592} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1646350201 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1646350199} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f05e67e6db6841f45b446a26d1d0d31d, type: 3} + m_Name: + m_EditorClassIdentifier: + audioSource: {fileID: 8300000, guid: 2e41a111eebf71843a1cbf93be5a9e1c, type: 3} --- !u!1 &1697224667 GameObject: m_ObjectHideFlags: 0 @@ -1015,7 +1381,7 @@ AudioSource: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1883178833} - m_Enabled: 1 + m_Enabled: 0 serializedVersion: 4 OutputAudioMixerGroup: {fileID: 0} m_audioClip: {fileID: 0} @@ -1187,3 +1553,6 @@ SceneRoots: - {fileID: 99782795} - {fileID: 1697224671} - {fileID: 90518572} + - {fileID: 266152667} + - {fileID: 169666005} + - {fileID: 621578838} diff --git a/Assets/Scripts/Sound.meta b/Assets/Scripts/Sound.meta new file mode 100644 index 0000000..6dafa36 --- /dev/null +++ b/Assets/Scripts/Sound.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7f85cfcdf276f164e886755fa9ee019e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Sound/ILoopableSound.cs b/Assets/Scripts/Sound/ILoopableSound.cs new file mode 100644 index 0000000..da7e36e --- /dev/null +++ b/Assets/Scripts/Sound/ILoopableSound.cs @@ -0,0 +1,50 @@ +using NUnit.Framework; +using UnityEngine; + +public abstract class ILoopableSound : MonoBehaviour +{ + protected AudioSource source; + + protected void CreateSource() + { + source = Instantiate(SoundManager.Instance.audioSourcePrefab).GetComponent(); + source.loop = true; + } + + protected void DestroySource() + { + if (source != null) + { + Destroy(source.gameObject); + } + } + + protected void OnDestroy() + { + DestroySource(); + } + + public void PlayLoopableSound(Vector3 position) + { + CreateSource(); + source.transform.position = position; + PlayLoopableSound(); + } + + public void PlayLoopableSound(Transform parent, bool spatial) + { + CreateSource(); + source.transform.SetParent(parent, false); + source.spatialBlend = spatial ? 1 : 0; + PlayLoopableSound(); + } + + public virtual void PlayLoopableSound() { } + + public virtual void StopLoopableSound() + { + DestroySource(); + } + + public bool IsPlaying { get { return source != null; } } +} \ No newline at end of file diff --git a/Assets/Scripts/Sound/ILoopableSound.cs.meta b/Assets/Scripts/Sound/ILoopableSound.cs.meta new file mode 100644 index 0000000..a19064c --- /dev/null +++ b/Assets/Scripts/Sound/ILoopableSound.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: a71883758609f8342858a3b5c4c641d8 \ No newline at end of file diff --git a/Assets/Scripts/Sound/LoopablePlaylist.cs b/Assets/Scripts/Sound/LoopablePlaylist.cs new file mode 100644 index 0000000..7515140 --- /dev/null +++ b/Assets/Scripts/Sound/LoopablePlaylist.cs @@ -0,0 +1,43 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LoopablePlaylist : ILoopableSound +{ + [SerializeField] List playlist; + Coroutine playlistCoroutine = null; + + public override void PlayLoopableSound() + { + base.PlayLoopableSound(); + + if (playlist.Count == 0) + { + Debug.LogWarning("Playlist is empty"); + return; + } + source.loop = false; + playlistCoroutine = StartCoroutine(PlaylistCoroutine()); + source.clip = playlist[0]; + source.Play(); + } + + public override void StopLoopableSound() + { + StopCoroutine(playlistCoroutine); + source.Stop(); + base.StopLoopableSound(); + } + + protected IEnumerator PlaylistCoroutine() + { + int playlistIndex = 0; + while (true) + { + source.clip = playlist[playlistIndex]; + source.Play(); + yield return new WaitForSeconds(playlist[playlistIndex].length); + playlistIndex = (playlistIndex + 1) % playlist.Count; + } + } +} diff --git a/Assets/Scripts/Sound/LoopablePlaylist.cs.meta b/Assets/Scripts/Sound/LoopablePlaylist.cs.meta new file mode 100644 index 0000000..c7feb2c --- /dev/null +++ b/Assets/Scripts/Sound/LoopablePlaylist.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 914bb056e791dc74491ef6034c2a70dd \ No newline at end of file diff --git a/Assets/Scripts/Sound/LoopableSound.cs b/Assets/Scripts/Sound/LoopableSound.cs new file mode 100644 index 0000000..ffa9dcb --- /dev/null +++ b/Assets/Scripts/Sound/LoopableSound.cs @@ -0,0 +1,19 @@ +using UnityEngine; + +public class LoopableSound : ILoopableSound +{ + [SerializeField] AudioClip sound; + + public override void PlayLoopableSound() + { + base.PlayLoopableSound(); + source.clip = sound; + source.Play(); + } + + public override void StopLoopableSound() + { + source.Stop(); + base.StopLoopableSound(); + } +} diff --git a/Assets/Scripts/Sound/LoopableSound.cs.meta b/Assets/Scripts/Sound/LoopableSound.cs.meta new file mode 100644 index 0000000..9fcb427 --- /dev/null +++ b/Assets/Scripts/Sound/LoopableSound.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 287885c28387db147b2ed37b247e9fc2 \ No newline at end of file diff --git a/Assets/Scripts/Sound/MusicManager.cs b/Assets/Scripts/Sound/MusicManager.cs new file mode 100644 index 0000000..ce46fed --- /dev/null +++ b/Assets/Scripts/Sound/MusicManager.cs @@ -0,0 +1,45 @@ +using UnityEngine; + +/// +/// The music manager is responsible for handling loopable sounds. +/// If you want to manage a non-looped sound, use the SoundManager. +/// +public class MusicManager : MonoBehaviour +{ + // Singleton pattern + [System.NonSerialized] public static MusicManager Instance = null; + + private void Awake() + { + // Singleton pattern + if (Instance != null && Instance != this) + { + Destroy(gameObject); + } + else + { + Instance = this; + DontDestroyOnLoad(gameObject); + } + } + + public void StartMusic(ILoopableSound music) + { + music.PlayLoopableSound(transform, false); + } + + public void StartMusic(ILoopableSound music, Vector3 position) + { + music.PlayLoopableSound(position); + } + + public void StartMusic(ILoopableSound music, Transform parent) + { + music.PlayLoopableSound(parent, true); + } + + public void StopMusic(ILoopableSound music) + { + music.StopLoopableSound(); + } +} diff --git a/Assets/Scripts/Sound/MusicManager.cs.meta b/Assets/Scripts/Sound/MusicManager.cs.meta new file mode 100644 index 0000000..b90cba0 --- /dev/null +++ b/Assets/Scripts/Sound/MusicManager.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 4f4c60501663689458019872e34e9c48 \ No newline at end of file diff --git a/Assets/Scripts/Sound/SoundManager.cs b/Assets/Scripts/Sound/SoundManager.cs new file mode 100644 index 0000000..35ade3a --- /dev/null +++ b/Assets/Scripts/Sound/SoundManager.cs @@ -0,0 +1,83 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// +/// The sound manager is responsible for handling short lived sounds. +/// Those are sounds that should not loop. +/// If you want to manage a looped sound, use the MusicManager or place +/// it in the scene "as-is" instead. +/// +public class SoundManager : MonoBehaviour +{ + [SerializeField] private int initialPoolSize = 10; + [SerializeField] public GameObject audioSourcePrefab; + + private List audioPool; + private Queue availableAudios; + + // Singleton pattern + [System.NonSerialized] // Do not show it in editor and do not save its value + public static SoundManager Instance = null; + + private void Awake() + { + // Singleton pattern + if (Instance != null && Instance != this) + { + Destroy(gameObject); + return; + } + + Instance = this; + DontDestroyOnLoad(gameObject); + } + + private void Start() + { + if (audioSourcePrefab == null) + { + Debug.LogWarning("Cannot create a pool of audio sources: audio source prefab not set"); + } + + audioPool = new List(initialPoolSize); + availableAudios = new Queue(initialPoolSize); + + // For each initially pooled audio + for (int i=0; i(); + audioPool.Add(source); + return source; + } + + private IEnumerator DelayedBackToPoolCoroutine(AudioSource source) + { + yield return new WaitForSeconds(source.clip.length); + availableAudios.Enqueue(source); + } + + public void PlaySoundAt(Vector3 position, AudioClip sound) + { + // Take audio from pool if possible, extend pool otherwise + AudioSource source = Instance.availableAudios.Count == 0 ? + Instance.ExtendPool() : + Instance.availableAudios.Dequeue(); + + source.transform.position = position; + source.clip = sound; + source.loop = false; + source.Play(); + StartCoroutine(Instance.DelayedBackToPoolCoroutine(source)); + } +} diff --git a/Assets/Scripts/Sound/SoundManager.cs.meta b/Assets/Scripts/Sound/SoundManager.cs.meta new file mode 100644 index 0000000..b92b5e4 --- /dev/null +++ b/Assets/Scripts/Sound/SoundManager.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: cc230848cf9fffe40aed130aeee564f8 \ No newline at end of file diff --git a/Assets/Scripts/Trigger.meta b/Assets/Scripts/Trigger.meta new file mode 100644 index 0000000..4512752 --- /dev/null +++ b/Assets/Scripts/Trigger.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ff2572641226ba24f8e06342e11d6dc6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Trigger/Trigger.meta b/Assets/Scripts/Trigger/Trigger.meta new file mode 100644 index 0000000..58713e0 --- /dev/null +++ b/Assets/Scripts/Trigger/Trigger.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b7081abff2504cd488ce34e2964895f5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Trigger/Trigger/IActivableTrigger.cs b/Assets/Scripts/Trigger/Trigger/IActivableTrigger.cs new file mode 100644 index 0000000..b876c90 --- /dev/null +++ b/Assets/Scripts/Trigger/Trigger/IActivableTrigger.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using UnityEngine; + +/// +/// An abstract class for anything that needs to trigger activable events (on/off state) +/// +public abstract class IActivableTrigger : MonoBehaviour +{ + [SerializeField] List activableTriggers; + + protected void OnTriggerActivate() + { + foreach (IActivableTriggerable activableTrigger in activableTriggers) + { + activableTrigger.OnTriggerActivate(); + } + } + + protected void OnTriggerDeactivate() + { + foreach (IActivableTriggerable activableTrigger in activableTriggers) + { + activableTrigger.OnTriggerDeactivate(); + } + } +} diff --git a/Assets/Scripts/Trigger/Trigger/IActivableTrigger.cs.meta b/Assets/Scripts/Trigger/Trigger/IActivableTrigger.cs.meta new file mode 100644 index 0000000..208683b --- /dev/null +++ b/Assets/Scripts/Trigger/Trigger/IActivableTrigger.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: a01a8874461ebab4fb27d80b3864597a \ No newline at end of file diff --git a/Assets/Scripts/Trigger/Trigger/ITrigger.cs b/Assets/Scripts/Trigger/Trigger/ITrigger.cs new file mode 100644 index 0000000..7865ae3 --- /dev/null +++ b/Assets/Scripts/Trigger/Trigger/ITrigger.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using UnityEngine; + +/// +/// An abstract class for anything that needs to trigger one-shot events +/// +public abstract class ITrigger : MonoBehaviour +{ + [SerializeField] List triggerables; + + protected void OnTrigger(Vector3 position) + { + foreach (ITriggerable triggerable in triggerables) + { + triggerable.Trigger(position); + } + } + + protected void OnTrigger() + { + foreach (var triggerable in triggerables) + { + triggerable.Trigger(); + } + } +} diff --git a/Assets/Scripts/Trigger/Trigger/ITrigger.cs.meta b/Assets/Scripts/Trigger/Trigger/ITrigger.cs.meta new file mode 100644 index 0000000..c82933b --- /dev/null +++ b/Assets/Scripts/Trigger/Trigger/ITrigger.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 5b27634977cf89f4897128f2bfc9c40e \ No newline at end of file diff --git a/Assets/Scripts/Trigger/Trigger/TriggerArea.cs b/Assets/Scripts/Trigger/Trigger/TriggerArea.cs new file mode 100644 index 0000000..db4a046 --- /dev/null +++ b/Assets/Scripts/Trigger/Trigger/TriggerArea.cs @@ -0,0 +1,18 @@ +using UnityEngine; + +/// +/// An area that triggers when colliding (triggers once when entering, once when exiting) +/// +[RequireComponent(typeof(Collider))] +public class TriggerArea : IActivableTrigger +{ + private void OnTriggerEnter(Collider other) + { + OnTriggerActivate(); + } + + private void OnTriggerExit(Collider other) + { + OnTriggerDeactivate(); + } +} diff --git a/Assets/Scripts/Trigger/Trigger/TriggerArea.cs.meta b/Assets/Scripts/Trigger/Trigger/TriggerArea.cs.meta new file mode 100644 index 0000000..cde8289 --- /dev/null +++ b/Assets/Scripts/Trigger/Trigger/TriggerArea.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: eb3300468ed86d74d9fce3c293a89442 \ No newline at end of file diff --git a/Assets/Scripts/Trigger/Trigger/TriggerCollision.cs b/Assets/Scripts/Trigger/Trigger/TriggerCollision.cs new file mode 100644 index 0000000..facf06c --- /dev/null +++ b/Assets/Scripts/Trigger/Trigger/TriggerCollision.cs @@ -0,0 +1,17 @@ +using UnityEngine; + +/// +/// A collision trigger that triggers one-shot event when colliding with an object +/// +[RequireComponent(typeof(Collider))] +public class TriggerCollision : ITrigger +{ + private void OnCollisionEnter(Collision collision) + { + if (collision.contactCount > 0) + { + Vector3 contactPoint = collision.GetContact(0).point; + OnTrigger(contactPoint); + } + } +} diff --git a/Assets/Scripts/Trigger/Trigger/TriggerCollision.cs.meta b/Assets/Scripts/Trigger/Trigger/TriggerCollision.cs.meta new file mode 100644 index 0000000..069c057 --- /dev/null +++ b/Assets/Scripts/Trigger/Trigger/TriggerCollision.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: ce02cde7ea924d943a1cae7e8fa23c97 \ No newline at end of file diff --git a/Assets/Scripts/Trigger/Triggerable.meta b/Assets/Scripts/Trigger/Triggerable.meta new file mode 100644 index 0000000..dddacce --- /dev/null +++ b/Assets/Scripts/Trigger/Triggerable.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 923b6e673582c4b4487ef8daea9b0bd2 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Trigger/Triggerable/IActivableTriggerable.cs b/Assets/Scripts/Trigger/Triggerable/IActivableTriggerable.cs new file mode 100644 index 0000000..f788fca --- /dev/null +++ b/Assets/Scripts/Trigger/Triggerable/IActivableTriggerable.cs @@ -0,0 +1,10 @@ +using UnityEngine; + +/// +/// An abstract class for any triggerable object that has an on/off state +/// +public abstract class IActivableTriggerable : MonoBehaviour +{ + public abstract void OnTriggerActivate(); + public abstract void OnTriggerDeactivate(); +} diff --git a/Assets/Scripts/Trigger/Triggerable/IActivableTriggerable.cs.meta b/Assets/Scripts/Trigger/Triggerable/IActivableTriggerable.cs.meta new file mode 100644 index 0000000..b8b992f --- /dev/null +++ b/Assets/Scripts/Trigger/Triggerable/IActivableTriggerable.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 64b9105c3da058a4698864040a90a844 \ No newline at end of file diff --git a/Assets/Scripts/Trigger/Triggerable/ITriggerable.cs b/Assets/Scripts/Trigger/Triggerable/ITriggerable.cs new file mode 100644 index 0000000..aece3dc --- /dev/null +++ b/Assets/Scripts/Trigger/Triggerable/ITriggerable.cs @@ -0,0 +1,10 @@ +using UnityEngine; + +/// +/// An abstract class for any triggerable object +/// +public abstract class ITriggerable : MonoBehaviour +{ + public abstract void Trigger(); + public abstract void Trigger(Vector3 position); +} diff --git a/Assets/Scripts/Trigger/Triggerable/ITriggerable.cs.meta b/Assets/Scripts/Trigger/Triggerable/ITriggerable.cs.meta new file mode 100644 index 0000000..677c4f2 --- /dev/null +++ b/Assets/Scripts/Trigger/Triggerable/ITriggerable.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: db3db78b9c1317d42abe3ef387daea90 \ No newline at end of file diff --git a/Assets/Scripts/Trigger/Triggerable/TriggerableMusic.cs b/Assets/Scripts/Trigger/Triggerable/TriggerableMusic.cs new file mode 100644 index 0000000..4a4fc18 --- /dev/null +++ b/Assets/Scripts/Trigger/Triggerable/TriggerableMusic.cs @@ -0,0 +1,25 @@ +using UnityEngine; + +/// +/// A triggerable music. Trigger can activate and deactivate the music. +/// +public class TriggerableMusic : IActivableTriggerable +{ + [SerializeField] ILoopableSound music; + + public override void OnTriggerActivate() + { + if (music != null) + { + MusicManager.Instance.StartMusic(music); + } + } + + public override void OnTriggerDeactivate() + { + if (music != null) + { + MusicManager.Instance.StopMusic(music); + } + } +} diff --git a/Assets/Scripts/Trigger/Triggerable/TriggerableMusic.cs.meta b/Assets/Scripts/Trigger/Triggerable/TriggerableMusic.cs.meta new file mode 100644 index 0000000..30caf82 --- /dev/null +++ b/Assets/Scripts/Trigger/Triggerable/TriggerableMusic.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 0c3454cc62eba27469e9581fb0fb8703 \ No newline at end of file diff --git a/Assets/Scripts/Trigger/Triggerable/TriggerableSound.cs b/Assets/Scripts/Trigger/Triggerable/TriggerableSound.cs new file mode 100644 index 0000000..f042a81 --- /dev/null +++ b/Assets/Scripts/Trigger/Triggerable/TriggerableSound.cs @@ -0,0 +1,25 @@ +using UnityEngine; + +/// +/// A triggerable sound. Trigger plays the sound. +/// +public class TriggerableSound : ITriggerable +{ + [SerializeField] AudioClip audioSource; + + public override void Trigger() + { + if (audioSource != null) + { + SoundManager.Instance.PlaySoundAt(transform.position, audioSource); + } + } + + public override void Trigger(Vector3 position) + { + if (audioSource != null) + { + SoundManager.Instance.PlaySoundAt(position, audioSource); + } + } +} diff --git a/Assets/Scripts/Trigger/Triggerable/TriggerableSound.cs.meta b/Assets/Scripts/Trigger/Triggerable/TriggerableSound.cs.meta new file mode 100644 index 0000000..059967f --- /dev/null +++ b/Assets/Scripts/Trigger/Triggerable/TriggerableSound.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: f05e67e6db6841f45b446a26d1d0d31d \ No newline at end of file diff --git a/ProjectSettings/TimelineSettings.asset b/ProjectSettings/TimelineSettings.asset new file mode 100644 index 0000000..b21943a --- /dev/null +++ b/ProjectSettings/TimelineSettings.asset @@ -0,0 +1,16 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &1 +MonoBehaviour: + m_ObjectHideFlags: 53 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a287be6c49135cd4f9b2b8666c39d999, type: 3} + m_Name: + m_EditorClassIdentifier: + assetDefaultFramerate: 60 + m_DefaultFrameRate: 60