death sounds, build sounds, better audio management
This commit is contained in:
parent
a7b2d1854d
commit
9f25844657
26 changed files with 313 additions and 12 deletions
8
Assets/_Project/Audio/buildings.meta
Normal file
8
Assets/_Project/Audio/buildings.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9922143d68d6063e4a08cdeeb509237c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/_Project/Audio/buildings/tesla_tower.meta
Normal file
8
Assets/_Project/Audio/buildings/tesla_tower.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 010b1a2adea9686f09d4ab14690eb26b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/_Project/Audio/buildings/tesla_tower/construction_finished.wav
(Stored with Git LFS)
Normal file
BIN
Assets/_Project/Audio/buildings/tesla_tower/construction_finished.wav
(Stored with Git LFS)
Normal file
Binary file not shown.
|
|
@ -0,0 +1,23 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6ff2e0ba45ef5eb6abeb34bd2c6e2da8
|
||||
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:
|
||||
8
Assets/_Project/Audio/death_sounds.meta
Normal file
8
Assets/_Project/Audio/death_sounds.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0a6f35a8a0b1666d8aeebf2071d63132
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/_Project/Audio/death_sounds/cyclops.meta
Normal file
8
Assets/_Project/Audio/death_sounds/cyclops.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 00e7929e355a29031b42d55d7637e784
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/_Project/Audio/death_sounds/cyclops/cyclops_death_sound_1.wav
(Stored with Git LFS)
Executable file
BIN
Assets/_Project/Audio/death_sounds/cyclops/cyclops_death_sound_1.wav
(Stored with Git LFS)
Executable file
Binary file not shown.
|
|
@ -0,0 +1,23 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e007e19b827137ce395021d825927dcc
|
||||
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:
|
||||
BIN
Assets/_Project/Audio/death_sounds/cyclops/cyclops_death_sound_2.wav
(Stored with Git LFS)
Executable file
BIN
Assets/_Project/Audio/death_sounds/cyclops/cyclops_death_sound_2.wav
(Stored with Git LFS)
Executable file
Binary file not shown.
|
|
@ -0,0 +1,23 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6cea30689732db2f0a8989fe8f1a07a9
|
||||
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:
|
||||
|
|
@ -16,6 +16,7 @@ GameObject:
|
|||
- component: {fileID: 3283904430289710888}
|
||||
- component: {fileID: 3756613737869398948}
|
||||
- component: {fileID: 6036713598566100742}
|
||||
- component: {fileID: -1575784752119152190}
|
||||
m_Layer: 10
|
||||
m_Name: Enemy_CrystalGolem_Blue
|
||||
m_TagString: Untagged
|
||||
|
|
@ -202,6 +203,27 @@ CapsuleCollider:
|
|||
m_Height: 2
|
||||
m_Direction: 1
|
||||
m_Center: {x: 0, y: 1, z: 0}
|
||||
--- !u!114 &-1575784752119152190
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1455822126534880203}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 9df6fea9a86daafae998f8eecc44ee7d, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::TD.Combat.EnemyDeathSound
|
||||
deathSounds:
|
||||
- clip: {fileID: 8300000, guid: e007e19b827137ce395021d825927dcc, type: 3}
|
||||
volume: 0.75
|
||||
minPitch: 0.95
|
||||
maxPitch: 1.05
|
||||
- clip: {fileID: 8300000, guid: 6cea30689732db2f0a8989fe8f1a07a9, type: 3}
|
||||
volume: 0.75
|
||||
minPitch: 0.95
|
||||
maxPitch: 1.05
|
||||
--- !u!1 &5361867751622119598
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ GameObject:
|
|||
- component: {fileID: 3283904430289710888}
|
||||
- component: {fileID: 3756613737869398948}
|
||||
- component: {fileID: 6036713598566100742}
|
||||
- component: {fileID: -4695266156693656620}
|
||||
m_Layer: 10
|
||||
m_Name: Enemy_Cyclops_Green
|
||||
m_TagString: Untagged
|
||||
|
|
@ -202,6 +203,21 @@ CapsuleCollider:
|
|||
m_Height: 2
|
||||
m_Direction: 1
|
||||
m_Center: {x: 0, y: 1, z: 0}
|
||||
--- !u!114 &-4695266156693656620
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1455822126534880203}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 9df6fea9a86daafae998f8eecc44ee7d, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::TD.Combat.EnemyDeathSound
|
||||
deathClips:
|
||||
- {fileID: 8300000, guid: e007e19b827137ce395021d825927dcc, type: 3}
|
||||
- {fileID: 8300000, guid: 6cea30689732db2f0a8989fe8f1a07a9, type: 3}
|
||||
--- !u!1 &5361867751622119598
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ GameObject:
|
|||
- component: {fileID: 8853488620519990682}
|
||||
- component: {fileID: 4524938955752569428}
|
||||
- component: {fileID: -2590971686077483651}
|
||||
- component: {fileID: 1288485127287735786}
|
||||
m_Layer: 0
|
||||
m_Name: Tower_TeslaCoil
|
||||
m_TagString: Untagged
|
||||
|
|
@ -146,7 +147,7 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Unity.Netcode.Runtime::Unity.Netcode.NetworkObject
|
||||
GlobalObjectIdHash: 1363936954
|
||||
GlobalObjectIdHash: 280718094
|
||||
InScenePlacedSourceGlobalObjectIdHash: 0
|
||||
DeferredDespawnTick: 0
|
||||
Ownership: 1
|
||||
|
|
@ -219,10 +220,20 @@ MonoBehaviour:
|
|||
emitter: {fileID: 1088221722203278382}
|
||||
arcMaterial: {fileID: 2100000, guid: 9ba610475fb3d4c4fa1245e15a72aee5, type: 2}
|
||||
arcColor: {r: 0.6, g: 0.85, b: 1, a: 1}
|
||||
emissionIntensity: 4
|
||||
arcWidth: 0.06
|
||||
arcDuration: 0.12
|
||||
segmentsPerArc: 6
|
||||
arcHeight: 0.18
|
||||
jitter: 0.2
|
||||
castLight: 1
|
||||
lightColor: {r: 0.6, g: 0.85, b: 1, a: 1}
|
||||
lightIntensity: 8
|
||||
lightRange: 12
|
||||
castImpactLight: 1
|
||||
impactLightIntensity: 4
|
||||
impactLightRange: 5
|
||||
maxImpactLights: 8
|
||||
--- !u!114 &-2590971686077483651
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -235,9 +246,28 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: db643146344a08a639133638e4746a33, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::TD.Combat.TeslaTowerFireSound
|
||||
fireClip: {fileID: 8300000, guid: a0b5d0b15de667604b825f12d39b05a8, type: 3}
|
||||
minPitch: 0.92
|
||||
maxPitch: 1.07
|
||||
fireSound:
|
||||
clip: {fileID: 8300000, guid: a0b5d0b15de667604b825f12d39b05a8, type: 3}
|
||||
volume: 0.263
|
||||
minPitch: 0.95
|
||||
maxPitch: 1.05
|
||||
--- !u!114 &1288485127287735786
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6482414459531823157}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: ce512ec39eb6a8f079c7b258a4d0ced1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::TD.Combat.TowerBuiltSound
|
||||
builtSound:
|
||||
clip: {fileID: 8300000, guid: 6ff2e0ba45ef5eb6abeb34bd2c6e2da8, type: 3}
|
||||
volume: 0.496
|
||||
minPitch: 1
|
||||
maxPitch: 1
|
||||
--- !u!1 &7101790219931971190
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ namespace TD.Audio
|
|||
}
|
||||
}
|
||||
|
||||
public void Play(AudioClip clip, AudioCategory category, float pitch = 1f)
|
||||
public void Play(AudioClip clip, AudioCategory category, float pitch = 1f, float volume = 1f)
|
||||
{
|
||||
if (clip == null) return;
|
||||
if (!pools.TryGetValue(category, out var pool)) return;
|
||||
|
|
@ -66,6 +66,7 @@ namespace TD.Audio
|
|||
int idx = indices[category];
|
||||
var src = pool[idx % pool.Length];
|
||||
src.pitch = pitch;
|
||||
src.volume = volume;
|
||||
src.clip = clip;
|
||||
src.Play();
|
||||
indices[category] = idx + 1;
|
||||
|
|
|
|||
16
Assets/_Project/Scripts/Audio/SoundConfig.cs
Normal file
16
Assets/_Project/Scripts/Audio/SoundConfig.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Assets/_Project/Scripts/Audio/SoundConfig.cs
|
||||
using UnityEngine;
|
||||
|
||||
namespace TD.Audio
|
||||
{
|
||||
[System.Serializable]
|
||||
public struct SoundConfig
|
||||
{
|
||||
public AudioClip clip;
|
||||
[Range(0f, 1f)] public float volume;
|
||||
[Range(0f, 3f)] public float minPitch;
|
||||
[Range(0f, 3f)] public float maxPitch;
|
||||
|
||||
public float RandomPitch() => Random.Range(minPitch, maxPitch);
|
||||
}
|
||||
}
|
||||
2
Assets/_Project/Scripts/Audio/SoundConfig.cs.meta
Normal file
2
Assets/_Project/Scripts/Audio/SoundConfig.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fce44aba7ccbe4224aeae2faa74b978f
|
||||
42
Assets/_Project/Scripts/Combat/EnemyDeathSound.cs
Normal file
42
Assets/_Project/Scripts/Combat/EnemyDeathSound.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// Assets/_Project/Scripts/Combat/EnemyDeathSound.cs
|
||||
using TD.Audio;
|
||||
using TD.Gameplay;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TD.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// Local-only audio for enemy death. Subscribes to <see cref="EnemyHealth.OnDiedClient"/>
|
||||
/// and plays a randomly chosen clip from <see cref="deathClips"/>.
|
||||
/// Attach to any enemy prefab and assign its clips in the Inspector.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(EnemyHealth))]
|
||||
public class EnemyDeathSound : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private SoundConfig[] deathSounds;
|
||||
|
||||
private EnemyHealth enemyHealth;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
enemyHealth = GetComponent<EnemyHealth>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (enemyHealth != null) enemyHealth.OnDiedClient += HandleDied;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (enemyHealth != null) enemyHealth.OnDiedClient -= HandleDied;
|
||||
}
|
||||
|
||||
private void HandleDied()
|
||||
{
|
||||
if (deathSounds == null || deathSounds.Length == 0) return;
|
||||
var sound = deathSounds[Random.Range(0, deathSounds.Length)];
|
||||
AudioManager.Instance?.Play(sound.clip, AudioCategory.EnemyHitDeath, sound.RandomPitch(), sound.volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/_Project/Scripts/Combat/EnemyDeathSound.cs.meta
Normal file
2
Assets/_Project/Scripts/Combat/EnemyDeathSound.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9df6fea9a86daafae998f8eecc44ee7d
|
||||
|
|
@ -17,12 +17,7 @@ namespace TD.Combat
|
|||
[RequireComponent(typeof(TowerCombat))]
|
||||
public class TeslaTowerFireSound : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Sound played each time the coil discharges.")]
|
||||
[SerializeField] private AudioClip fireClip;
|
||||
|
||||
[Tooltip("Pitch is randomized within this range each shot to avoid a mechanical loop.")]
|
||||
[SerializeField] private float minPitch = 0.93f;
|
||||
[SerializeField] private float maxPitch = 1.07f;
|
||||
[SerializeField] private SoundConfig fireSound;
|
||||
|
||||
private TowerCombat combat;
|
||||
|
||||
|
|
@ -43,7 +38,7 @@ namespace TD.Combat
|
|||
|
||||
private void HandleAreaFired(Vector3[] positions)
|
||||
{
|
||||
AudioManager.Instance?.Play(fireClip, AudioCategory.TowerFire, Random.Range(minPitch, maxPitch));
|
||||
AudioManager.Instance?.Play(fireSound.clip, AudioCategory.TowerFire, fireSound.RandomPitch(), fireSound.volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
41
Assets/_Project/Scripts/Combat/TowerBuiltSound.cs
Normal file
41
Assets/_Project/Scripts/Combat/TowerBuiltSound.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// Assets/_Project/Scripts/Combat/TowerBuiltSound.cs
|
||||
using TD.Audio;
|
||||
using TD.Gameplay;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TD.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// Local-only audio for tower construction completion. Subscribes to
|
||||
/// <see cref="TowerInstance.OnBuiltClient"/> and plays a sound on every peer
|
||||
/// when the tower finishes building.
|
||||
/// Attach to any tower prefab and assign its clip in the Inspector.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(TowerInstance))]
|
||||
public class TowerBuiltSound : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private SoundConfig builtSound;
|
||||
|
||||
private TowerInstance towerInstance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
towerInstance = GetComponent<TowerInstance>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (towerInstance != null) towerInstance.OnBuiltClient += HandleBuilt;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (towerInstance != null) towerInstance.OnBuiltClient -= HandleBuilt;
|
||||
}
|
||||
|
||||
private void HandleBuilt()
|
||||
{
|
||||
AudioManager.Instance?.Play(builtSound.clip, AudioCategory.UI, builtSound.RandomPitch(), builtSound.volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/_Project/Scripts/Combat/TowerBuiltSound.cs.meta
Normal file
2
Assets/_Project/Scripts/Combat/TowerBuiltSound.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ce512ec39eb6a8f079c7b258a4d0ced1
|
||||
|
|
@ -126,6 +126,9 @@ namespace TD.Gameplay
|
|||
/// </summary>
|
||||
public event System.Action<EnemyHealth> OnDied;
|
||||
|
||||
/// <summary>Fired on ALL peers the moment this enemy dies. Use for client-side visuals and audio.</summary>
|
||||
public event System.Action OnDiedClient;
|
||||
|
||||
// ----- Server-only pre-spawn init -------------------------------------
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -240,6 +243,7 @@ namespace TD.Gameplay
|
|||
if (deathAnimator != null)
|
||||
deathAnimator.SetTrigger(DieHash);
|
||||
|
||||
DiedClientRpc();
|
||||
StartCoroutine(DeathSequence());
|
||||
}
|
||||
|
||||
|
|
@ -263,6 +267,12 @@ namespace TD.Gameplay
|
|||
// mesh sizes substantially, derive this from a collider bounds instead.
|
||||
public float SelectionRadius => 0.4f;
|
||||
|
||||
[ClientRpc]
|
||||
private void DiedClientRpc()
|
||||
{
|
||||
OnDiedClient?.Invoke();
|
||||
}
|
||||
|
||||
private IEnumerator DeathSequence()
|
||||
{
|
||||
// Hold while the death animation plays.
|
||||
|
|
|
|||
|
|
@ -166,6 +166,11 @@ namespace TD.Gameplay
|
|||
}
|
||||
}
|
||||
|
||||
// ----- Events ---------------------------------------------------------
|
||||
|
||||
/// <summary>Fired on ALL peers when this tower finishes construction and spawns.</summary>
|
||||
public event System.Action OnBuiltClient;
|
||||
|
||||
// ----- Server-only initialization -------------------------------------
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -262,6 +267,8 @@ namespace TD.Gameplay
|
|||
$"for {ownerSlot.Value} at anchor {anchorTile.Value}. " +
|
||||
$"IsServer={IsServer}");
|
||||
}
|
||||
|
||||
OnBuiltClient?.Invoke();
|
||||
}
|
||||
|
||||
public override void OnNetworkDespawn()
|
||||
|
|
|
|||
|
|
@ -135,6 +135,11 @@
|
|||
"type": "UnityEngine.ProBuilder.RectSelectMode, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "editor.dragSelectRectMode",
|
||||
"value": "{\"m_Value\":0}"
|
||||
},
|
||||
{
|
||||
"type": "UnityEditor.ProBuilder.Actions.ExportAssetOptions, Unity.ProBuilder.Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "export.assetOptions",
|
||||
"value": "{\"m_Value\":{\"makePrefab\":false,\"replaceOriginal\":false}}"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue