Add basic background music behavior
This commit is contained in:
parent
3bc7c9c7ee
commit
03f1bbc599
7 changed files with 395 additions and 11 deletions
BIN
Assets/Audio/Tavern_Fun.mp3
Normal file
BIN
Assets/Audio/Tavern_Fun.mp3
Normal file
Binary file not shown.
22
Assets/Audio/Tavern_Fun.mp3.meta
Normal file
22
Assets/Audio/Tavern_Fun.mp3.meta
Normal file
|
@ -0,0 +1,22 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 849452323efae574d8141c82f7b28f55
|
||||
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:
|
|
@ -29,7 +29,7 @@ Transform:
|
|||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2157073180203202247}
|
||||
m_RootOrder: 1
|
||||
m_RootOrder: 2
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &7408334756516261553
|
||||
MonoBehaviour:
|
||||
|
@ -45,12 +45,44 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
ready: 0
|
||||
SpawnRange: 1
|
||||
spawnChance: 100
|
||||
spawnChanceSoft: 100
|
||||
spawnChanceHard: 100
|
||||
maxSoftObs: 1
|
||||
maxHardObs: 1
|
||||
SoftObsRessourceFolder: Events/SoftObstacles
|
||||
HardObsRessourceFolder: Events/HardObstacles
|
||||
coroutineRefreshRate: 1
|
||||
--- !u!1 &422892530533236511
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1361501530690105541}
|
||||
m_Layer: 0
|
||||
m_Name: Audio
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &1361501530690105541
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 422892530533236511}
|
||||
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_Children:
|
||||
- {fileID: 5023819249935670292}
|
||||
m_Father: {fileID: 2157073180203202247}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &2157073178696562865
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -80,7 +112,7 @@ Transform:
|
|||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2157073180203202247}
|
||||
m_RootOrder: 0
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &2157073178696562867
|
||||
MonoBehaviour:
|
||||
|
@ -124,7 +156,7 @@ Transform:
|
|||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2157073180203202247}
|
||||
m_RootOrder: 3
|
||||
m_RootOrder: 4
|
||||
m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0}
|
||||
--- !u!114 &2157073178828809470
|
||||
MonoBehaviour:
|
||||
|
@ -188,7 +220,7 @@ Transform:
|
|||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2157073180203202247}
|
||||
m_RootOrder: 2
|
||||
m_RootOrder: 3
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &2157073179154264261
|
||||
MonoBehaviour:
|
||||
|
@ -266,7 +298,7 @@ Transform:
|
|||
m_Children:
|
||||
- {fileID: 2157073179686492908}
|
||||
m_Father: {fileID: 2157073180203202247}
|
||||
m_RootOrder: 4
|
||||
m_RootOrder: 5
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &2157073180013227982
|
||||
GameObject:
|
||||
|
@ -296,7 +328,7 @@ Transform:
|
|||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2157073180203202247}
|
||||
m_RootOrder: 5
|
||||
m_RootOrder: 6
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &2157073180203202245
|
||||
GameObject:
|
||||
|
@ -326,6 +358,7 @@ Transform:
|
|||
m_LocalPosition: {x: -0.21348187, y: 4.0925093, z: -2.1510859}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 1361501530690105541}
|
||||
- {fileID: 2157073178696562864}
|
||||
- {fileID: 183449879215217602}
|
||||
- {fileID: 2157073179154264258}
|
||||
|
@ -351,3 +384,242 @@ MonoBehaviour:
|
|||
serviceOpen: 0
|
||||
serviceTime: 60
|
||||
slowScale: 0.5
|
||||
--- !u!1 &6575613771290711696
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 5023819249935670292}
|
||||
- component: {fileID: 4688376570334067842}
|
||||
- component: {fileID: 3569788005944565417}
|
||||
- component: {fileID: 6898396145254654029}
|
||||
m_Layer: 0
|
||||
m_Name: BackgroundMusic
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &5023819249935670292
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6575613771290711696}
|
||||
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_Children: []
|
||||
m_Father: {fileID: 1361501530690105541}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!82 &4688376570334067842
|
||||
AudioSource:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6575613771290711696}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 4
|
||||
OutputAudioMixerGroup: {fileID: 0}
|
||||
m_audioClip: {fileID: 0}
|
||||
m_PlayOnAwake: 1
|
||||
m_Volume: 1
|
||||
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!82 &3569788005944565417
|
||||
AudioSource:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6575613771290711696}
|
||||
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 &6898396145254654029
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6575613771290711696}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: e845a10d8c5009048af900f3e22daa91, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
AudioIntensity0: {fileID: 0}
|
||||
AudioIntensity1: {fileID: 8300000, guid: 849452323efae574d8141c82f7b28f55, type: 3}
|
||||
|
|
|
@ -32568,6 +32568,11 @@ PrefabInstance:
|
|||
m_Modification:
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 422892530533236511, guid: dfb09d229e85c1446bee2e4f9357610e,
|
||||
type: 3}
|
||||
propertyPath: m_Name
|
||||
value: AudioManager
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 2157073178828809470, guid: dfb09d229e85c1446bee2e4f9357610e,
|
||||
type: 3}
|
||||
propertyPath: m_NavMeshData
|
||||
|
|
60
Assets/Scripts/GameSystems/BGMusic.cs
Normal file
60
Assets/Scripts/GameSystems/BGMusic.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//Define the background music behavior.
|
||||
public class BGMusic : MonoBehaviour
|
||||
{
|
||||
public int intensity =0; //Current intensity level
|
||||
int intensityLevels = 2; //Number of intensity levels (differents tracks)
|
||||
[SerializeField]
|
||||
AudioClip AudioIntensity0, AudioIntensity1; //Must have enough clip foreach intensity levels
|
||||
|
||||
List<AudioSource> audioSources; //Sources used for each intensity clips
|
||||
|
||||
//Change the intensity level of the music
|
||||
//TODO: Smooth transition
|
||||
public void changeIntensity(int level)
|
||||
{
|
||||
if(level>=intensityLevels)
|
||||
{
|
||||
Debug.LogWarning(gameObject.name+" doesn't have such high intensity available :"+ level+ " /"+intensityLevels);
|
||||
level = intensityLevels-1; //Max level
|
||||
}
|
||||
|
||||
for(int i=0; i<intensityLevels; i++)
|
||||
{
|
||||
if(i!=level)
|
||||
audioSources[i].volume=0.0f;
|
||||
else
|
||||
audioSources[i].volume=1.0f;
|
||||
}
|
||||
|
||||
intensity = level;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
audioSources = new List<AudioSource>(GetComponents<AudioSource>());
|
||||
if(audioSources.Count != intensityLevels )
|
||||
Debug.LogWarning(gameObject.name+" missing audio sources too play all intensity levels : "+ intensityLevels);
|
||||
|
||||
//Load clip
|
||||
audioSources[0].clip = AudioIntensity0;
|
||||
audioSources[1].clip = AudioIntensity1;
|
||||
|
||||
//Set initial intensity
|
||||
changeIntensity(intensity);
|
||||
|
||||
//Start sources
|
||||
foreach(AudioSource s in audioSources)
|
||||
s.Play();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/GameSystems/BGMusic.cs.meta
Normal file
11
Assets/Scripts/GameSystems/BGMusic.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e845a10d8c5009048af900f3e22daa91
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -30,6 +30,9 @@ public sealed class GameSystem : MonoBehaviour
|
|||
float slowScale = 0.5f; //Default scale for slow mode
|
||||
private float fixedDeltaTime;
|
||||
|
||||
//Sound
|
||||
BGMusic BGmusic=null; //Background Music
|
||||
|
||||
//TODO : Effect on gold change
|
||||
//Money
|
||||
private int gold;
|
||||
|
@ -101,6 +104,15 @@ public sealed class GameSystem : MonoBehaviour
|
|||
{
|
||||
// Make a copy of the fixedDeltaTime, it defaults to 0.02f, but it can be changed in the editor
|
||||
this.fixedDeltaTime = Time.fixedDeltaTime;
|
||||
|
||||
//Get BG music
|
||||
GameObject musicObj = GameObject.Find("/GameSystem/AudioManager/BackgroundMusic");
|
||||
if(musicObj != null)
|
||||
BGmusic = musicObj.GetComponent<BGMusic>();
|
||||
if(BGmusic is null)
|
||||
Debug.LogWarning("No background music found");
|
||||
|
||||
//Get UI Service Timer
|
||||
GameObject timerObj = GameObject.Find("/UI/Canvas/ServiceTimer");
|
||||
if(timerObj is null)
|
||||
{
|
||||
|
@ -108,11 +120,10 @@ public sealed class GameSystem : MonoBehaviour
|
|||
UIServiceTimer=null;
|
||||
}
|
||||
else
|
||||
{
|
||||
UIServiceTimer=timerObj.GetComponent<UITimer>();
|
||||
}
|
||||
|
||||
if(ClientManager.Instance.ready && StockManager.Instance.ready)
|
||||
//Check that all systems are ready
|
||||
if(ClientManager.Instance.ready && StockManager.Instance.ready && EventManager.Instance.ready)
|
||||
{
|
||||
ready=true;
|
||||
Debug.Log("All GameSystems are ready");
|
||||
|
@ -151,7 +162,10 @@ public sealed class GameSystem : MonoBehaviour
|
|||
toggleSlowMode(2.0f);
|
||||
Debug.Log("Time scale: "+Time.timeScale);
|
||||
}
|
||||
// Debug.Log("Service timer : "+(int)serviceTimer);
|
||||
|
||||
//Basic background music modification
|
||||
if(ClientManager.Instance.clientList.Count>2 && BGmusic.intensity<1)
|
||||
BGmusic.changeIntensity(1);
|
||||
}
|
||||
|
||||
// simple Singleton implementation
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue