Play sound when placing an Ally
This commit is contained in:
parent
853cb246ab
commit
e52063a832
20
Assets/Audio/@AudioTemplates/Sound_BuildingHammer.asset
Normal file
20
Assets/Audio/@AudioTemplates/Sound_BuildingHammer.asset
Normal file
@ -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
|
||||
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a78bf25d8d1cd347aa372d6099f8407
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Audio/Building.meta
Normal file
8
Assets/Audio/Building.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 720842e78d82f9146a64e729b4d86a52
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Audio/Building/build_hammer.mp3
Normal file
BIN
Assets/Audio/Building/build_hammer.mp3
Normal file
Binary file not shown.
22
Assets/Audio/Building/build_hammer.mp3.meta
Normal file
22
Assets/Audio/Building/build_hammer.mp3.meta
Normal file
@ -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:
|
||||
@ -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
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -17,6 +17,8 @@ namespace GatherAndDefend
|
||||
_audioSource = GetComponent<AudioSource>();
|
||||
_playableSounds = new Dictionary<string, AudioTemplate>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<AudioPlayerComponent>();
|
||||
Animation = gameObject.AddComponent<AnimationEntity>();
|
||||
_statusHandler = gameObject.AddComponent<StatusHandler>();
|
||||
|
||||
if (_audioPlayerComponent == null)
|
||||
{
|
||||
_audioPlayerComponent = gameObject.AddComponent<AudioPlayerComponent>();
|
||||
}
|
||||
}
|
||||
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; }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user