mirror of
https://github.com/ryzij/Cube-Tower-Defense.git
synced 2026-07-14 01:56:57 +00:00
Добавил музыку
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,23 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 12a913a054576d14581bfce71dbf4512
|
||||||
|
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:
|
||||||
@@ -11343,6 +11343,9 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier: '::'
|
m_EditorClassIdentifier: '::'
|
||||||
_wallet: {fileID: 1030979928}
|
_wallet: {fileID: 1030979928}
|
||||||
|
_gameManager: {fileID: 1875710079}
|
||||||
|
_levelBackgroundMusic: {fileID: 1897118789}
|
||||||
|
_buildBackgroundMusic: {fileID: 0}
|
||||||
_grassBlockDestroySound:
|
_grassBlockDestroySound:
|
||||||
- {fileID: 1641086313}
|
- {fileID: 1641086313}
|
||||||
- {fileID: 1127156137}
|
- {fileID: 1127156137}
|
||||||
@@ -11368,6 +11371,7 @@ Transform:
|
|||||||
- {fileID: 1128613021}
|
- {fileID: 1128613021}
|
||||||
- {fileID: 1573731473}
|
- {fileID: 1573731473}
|
||||||
- {fileID: 1087951941}
|
- {fileID: 1087951941}
|
||||||
|
- {fileID: 1897118788}
|
||||||
m_Father: {fileID: 481586150}
|
m_Father: {fileID: 481586150}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1001 &1439091071
|
--- !u!1001 &1439091071
|
||||||
@@ -14385,6 +14389,135 @@ Transform:
|
|||||||
m_CorrespondingSourceObject: {fileID: 5368672011475721328, guid: 8dd20c91f0d7a7b419f6bedcd1870cba, type: 3}
|
m_CorrespondingSourceObject: {fileID: 5368672011475721328, guid: 8dd20c91f0d7a7b419f6bedcd1870cba, type: 3}
|
||||||
m_PrefabInstance: {fileID: 1894735328}
|
m_PrefabInstance: {fileID: 1894735328}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
--- !u!1 &1897118787
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1897118788}
|
||||||
|
- component: {fileID: 1897118789}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: WaveBgMusic
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &1897118788
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1897118787}
|
||||||
|
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: 1431145624}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!82 &1897118789
|
||||||
|
AudioSource:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1897118787}
|
||||||
|
m_Enabled: 1
|
||||||
|
serializedVersion: 4
|
||||||
|
OutputAudioMixerGroup: {fileID: 0}
|
||||||
|
m_audioClip: {fileID: 0}
|
||||||
|
m_Resource: {fileID: 8300000, guid: 12a913a054576d14581bfce71dbf4512, type: 3}
|
||||||
|
m_PlayOnAwake: 0
|
||||||
|
m_Volume: 0.703
|
||||||
|
m_Pitch: 1
|
||||||
|
Loop: 1
|
||||||
|
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!1001 &1897891005
|
--- !u!1001 &1897891005
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ using UnityEngine;
|
|||||||
public class AudioManager : MonoBehaviour
|
public class AudioManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private Wallet _wallet;
|
[SerializeField] private Wallet _wallet;
|
||||||
|
[SerializeField] private GameManager _gameManager;
|
||||||
|
[SerializeField] private AudioSource _levelBackgroundMusic;
|
||||||
|
[SerializeField] private AudioSource _buildBackgroundMusic;
|
||||||
[SerializeField] private AudioSource[] _grassBlockDestroySound;
|
[SerializeField] private AudioSource[] _grassBlockDestroySound;
|
||||||
[SerializeField] private AudioSource[] _moneyChangeSound;
|
[SerializeField] private AudioSource[] _moneyChangeSound;
|
||||||
|
|
||||||
@@ -10,17 +13,21 @@ public class AudioManager : MonoBehaviour
|
|||||||
private int _moneyChangeSoundIndex = 0;
|
private int _moneyChangeSoundIndex = 0;
|
||||||
|
|
||||||
private int _money;
|
private int _money;
|
||||||
|
private GameManager.GameState _state;
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
_money = _wallet.Money;
|
_money = _wallet.Money;
|
||||||
|
_state = _gameManager.CurrentState;
|
||||||
|
|
||||||
_wallet.OnMoneyChanged += OnMoneyChanged;
|
_wallet.OnMoneyChanged += OnMoneyChanged;
|
||||||
|
_gameManager.OnStateChanged += OnStateChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDisable()
|
private void OnDisable()
|
||||||
{
|
{
|
||||||
_wallet.OnMoneyChanged -= OnMoneyChanged;
|
_wallet.OnMoneyChanged -= OnMoneyChanged;
|
||||||
|
_gameManager.OnStateChanged -= OnStateChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayBlockDestroySound(BlockScript block)
|
public void PlayBlockDestroySound(BlockScript block)
|
||||||
@@ -29,11 +36,7 @@ public class AudioManager : MonoBehaviour
|
|||||||
{
|
{
|
||||||
case BlockScript.BlockType.Grass:
|
case BlockScript.BlockType.Grass:
|
||||||
case BlockScript.BlockType.PathFinish:
|
case BlockScript.BlockType.PathFinish:
|
||||||
if (_grassBlockDestroySound == null)
|
Play(_grassBlockDestroySound, ref _grassSoundIndex);
|
||||||
return;
|
|
||||||
|
|
||||||
_grassBlockDestroySound[_grassSoundIndex].Play();
|
|
||||||
_grassSoundIndex = (_grassSoundIndex + 1) % _grassBlockDestroySound.Length;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,7 +49,48 @@ public class AudioManager : MonoBehaviour
|
|||||||
if (_moneyChangeSound.Length == 0 || oldMoney <= money)
|
if (_moneyChangeSound.Length == 0 || oldMoney <= money)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_moneyChangeSound[_moneyChangeSoundIndex].Play();
|
Play(_moneyChangeSound, ref _moneyChangeSoundIndex);
|
||||||
_moneyChangeSoundIndex = (_moneyChangeSoundIndex + 1) % _moneyChangeSound.Length;
|
}
|
||||||
|
|
||||||
|
private void OnStateChanged(GameManager.GameState newState)
|
||||||
|
{
|
||||||
|
if (newState == _state ||
|
||||||
|
_state == GameManager.GameState.BuildingPath && newState == GameManager.GameState.BuildingTurrets)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_state = newState;
|
||||||
|
switch (newState)
|
||||||
|
{
|
||||||
|
case GameManager.GameState.Level:
|
||||||
|
Stop(_buildBackgroundMusic);
|
||||||
|
Play(_levelBackgroundMusic);
|
||||||
|
break;
|
||||||
|
case GameManager.GameState.BuildingPath:
|
||||||
|
case GameManager.GameState.BuildingTurrets:
|
||||||
|
Stop(_levelBackgroundMusic);
|
||||||
|
Play(_buildBackgroundMusic);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Play(AudioSource audioSource)
|
||||||
|
{
|
||||||
|
if (audioSource != null)
|
||||||
|
audioSource.Play();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Play(AudioSource[] audioSources, ref int index)
|
||||||
|
{
|
||||||
|
if (audioSources == null || index >= audioSources.Length)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Play(audioSources[index]);
|
||||||
|
index = (index + 1) % audioSources.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Stop(AudioSource audioSource)
|
||||||
|
{
|
||||||
|
if (audioSource != null && audioSource.isPlaying)
|
||||||
|
audioSource.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user