diff --git a/Assets/Audio/@AudioTemplates/Sound_BuildingHammer.asset b/Assets/Audio/@AudioTemplates/Sound_BuildingHammer.asset new file mode 100644 index 0000000..082020f --- /dev/null +++ b/Assets/Audio/@AudioTemplates/Sound_BuildingHammer.asset @@ -0,0 +1,20 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + 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: 46e39f8c4a739ab43b87fda726289008, type: 3} + m_Name: Sound_BuildingHammer + m_EditorClassIdentifier: + name: BuildingHammer + clips: + - {fileID: 8300000, guid: 2b12de4511b150c4295a0e463162b845, type: 3} + volume: 0.25 + maxRandomPitchChange: 0.06 + maxRandomVolumeReducedPercentage: 0.7 diff --git a/Assets/Audio/@AudioTemplates/Sound_BuildingHammer.asset.meta b/Assets/Audio/@AudioTemplates/Sound_BuildingHammer.asset.meta new file mode 100644 index 0000000..bad777b --- /dev/null +++ b/Assets/Audio/@AudioTemplates/Sound_BuildingHammer.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1a78bf25d8d1cd347aa372d6099f8407 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Audio/Building.meta b/Assets/Audio/Building.meta new file mode 100644 index 0000000..d5c8d7d --- /dev/null +++ b/Assets/Audio/Building.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 720842e78d82f9146a64e729b4d86a52 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Audio/Building/build_hammer.mp3 b/Assets/Audio/Building/build_hammer.mp3 new file mode 100644 index 0000000..86d2a4f Binary files /dev/null and b/Assets/Audio/Building/build_hammer.mp3 differ diff --git a/Assets/Audio/Building/build_hammer.mp3.meta b/Assets/Audio/Building/build_hammer.mp3.meta new file mode 100644 index 0000000..6312d9b --- /dev/null +++ b/Assets/Audio/Building/build_hammer.mp3.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: 2b12de4511b150c4295a0e463162b845 +AudioImporter: + externalObjects: {} + serializedVersion: 6 + defaultSettings: + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + preloadAudioData: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Buildings/House.prefab b/Assets/Prefabs/Buildings/House.prefab index 642effd..38c54c7 100644 --- a/Assets/Prefabs/Buildings/House.prefab +++ b/Assets/Prefabs/Buildings/House.prefab @@ -156,6 +156,8 @@ GameObject: - component: {fileID: 2188414223676668191} - component: {fileID: 6208366596957312445} - component: {fileID: 6252103591577139412} + - component: {fileID: 8272767042902196346} + - component: {fileID: 7154238355284907042} m_Layer: 0 m_Name: House m_TagString: Ally @@ -264,6 +266,7 @@ MonoBehaviour: _attack_damage: 0 _attack_interval: 0 _enemy: {fileID: 0} + SoundPlayerWhenPlaced: {fileID: 11400000, guid: 1a78bf25d8d1cd347aa372d6099f8407, type: 2} rangeOutline: {fileID: 8496940952803090096} --- !u!114 &6252103591577139412 MonoBehaviour: @@ -277,6 +280,116 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 52b5039c6ed892a42b71ae16566ae511, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!82 &8272767042902196346 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6208366596957312446} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {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: 0 + 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 +--- !u!114 &7154238355284907042 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6208366596957312446} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c6ec072b3afbe0f498514990c948b7e6, type: 3} + m_Name: + m_EditorClassIdentifier: + playableSounds: + - {fileID: 11400000, guid: 1a78bf25d8d1cd347aa372d6099f8407, type: 2} --- !u!1001 &1746988449102172640 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/Buildings/StoneHouse.prefab b/Assets/Prefabs/Buildings/StoneHouse.prefab index d8cda6d..dd817d1 100644 --- a/Assets/Prefabs/Buildings/StoneHouse.prefab +++ b/Assets/Prefabs/Buildings/StoneHouse.prefab @@ -261,6 +261,7 @@ MonoBehaviour: _attack_damage: 0 _attack_interval: 0 _enemy: {fileID: 0} + SoundPlayerWhenPlaced: {fileID: 11400000, guid: 1a78bf25d8d1cd347aa372d6099f8407, type: 2} rangeOutline: {fileID: 8496940952803090096} --- !u!114 &6252103591577139412 MonoBehaviour: diff --git a/Assets/Scripts/Ally/Ally.cs b/Assets/Scripts/Ally/Ally.cs index a29a110..a93eda0 100644 --- a/Assets/Scripts/Ally/Ally.cs +++ b/Assets/Scripts/Ally/Ally.cs @@ -1,3 +1,4 @@ +using GatherAndDefend; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -11,6 +12,18 @@ public class Ally : Entity public override float SpeedMultiplier => GlobalConfig.Instance.Current.allySpeedMultiplier; public float PopulationCost => GlobalConfig.Instance.Current.populationCostPerUnit; + public AudioTemplate SoundPlayerWhenPlaced; + + public override void Start() + { + base.Start(); + + if (SoundPlayerWhenPlaced != null) + { + PlaySound(SoundPlayerWhenPlaced); + } + } + public override void Update() { base.Update(); diff --git a/Assets/Scripts/Audio/AudioPlayerComponent.cs b/Assets/Scripts/Audio/AudioPlayerComponent.cs index 66ba406..0670a4c 100644 --- a/Assets/Scripts/Audio/AudioPlayerComponent.cs +++ b/Assets/Scripts/Audio/AudioPlayerComponent.cs @@ -17,6 +17,8 @@ namespace GatherAndDefend _audioSource = GetComponent(); _playableSounds = new Dictionary(); + if (playableSounds == null || playableSounds.Length == 0) return; + foreach (var sound in playableSounds) { _playableSounds.Add(sound.name, sound); @@ -27,11 +29,16 @@ namespace GatherAndDefend { if (_playableSounds.TryGetValue(soundName, out AudioTemplate sound)) { - _audioSource.clip = sound.GetRandomClip(); - _audioSource.pitch = sound.GetRandomPitch(); - _audioSource.volume = ((overrideVolume != -1f) ? overrideVolume : sound.GetVolumeToUse()) * volumeMultiplier; - _audioSource.Play(); + PlaySound(sound, volumeMultiplier, overrideVolume); } } + + public void PlaySound(AudioTemplate sound, float volumeMultiplier = 1f, float overrideVolume = -1f) + { + _audioSource.clip = sound.GetRandomClip(); + _audioSource.pitch = sound.GetRandomPitch(); + _audioSource.volume = ((overrideVolume != -1f) ? overrideVolume : sound.GetVolumeToUse()) * volumeMultiplier; + _audioSource.Play(); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index a1f2f25..f290afe 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -1,6 +1,7 @@ using GatherAndDefend; using System.Collections; using System.Collections.Generic; +using UnityEditor.SceneManagement; using UnityEngine; public abstract class Entity : LevelObject @@ -41,6 +42,11 @@ public abstract class Entity : LevelObject _audioPlayerComponent = GetComponent(); Animation = gameObject.AddComponent(); _statusHandler = gameObject.AddComponent(); + + if (_audioPlayerComponent == null) + { + _audioPlayerComponent = gameObject.AddComponent(); + } } public virtual void Update() { @@ -116,6 +122,11 @@ public abstract class Entity : LevelObject _audioPlayerComponent.PlaySound(soundName, volumeMultiplier, overrideVolume); } + public void PlaySound(AudioTemplate sound, float volumeMultiplier = 1f, float overrideVolume = -1f) + { + _audioPlayerComponent.PlaySound(sound, volumeMultiplier, overrideVolume); + } + //GETTERS AND SETTERS public abstract Vector2 RangeMultiplier { get; }