diff --git a/Assets/Audio/Tavern Fun Full.wav b/Assets/Audio/Tavern Fun Full.wav new file mode 100644 index 0000000..def4853 Binary files /dev/null and b/Assets/Audio/Tavern Fun Full.wav differ diff --git a/Assets/Audio/Tavern Fun Full.wav.meta b/Assets/Audio/Tavern Fun Full.wav.meta new file mode 100644 index 0000000..04b54fd --- /dev/null +++ b/Assets/Audio/Tavern Fun Full.wav.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: 3274177b211a55c42a0a2ce4a6ae61ba +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/Audio/Tavern Fun Little.wav b/Assets/Audio/Tavern Fun Little.wav new file mode 100644 index 0000000..bd22fb0 Binary files /dev/null and b/Assets/Audio/Tavern Fun Little.wav differ diff --git a/Assets/Audio/Tavern Fun Little.wav.meta b/Assets/Audio/Tavern Fun Little.wav.meta new file mode 100644 index 0000000..4df506d --- /dev/null +++ b/Assets/Audio/Tavern Fun Little.wav.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: 67990e289ee555c4182dabba061eebcd +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/Audio/Tavern Fun Medium.wav b/Assets/Audio/Tavern Fun Medium.wav new file mode 100644 index 0000000..8756b58 Binary files /dev/null and b/Assets/Audio/Tavern Fun Medium.wav differ diff --git a/Assets/Audio/Tavern Fun Medium.wav.meta b/Assets/Audio/Tavern Fun Medium.wav.meta new file mode 100644 index 0000000..b7ac193 --- /dev/null +++ b/Assets/Audio/Tavern Fun Medium.wav.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: 271965f1fde0f9f41933e807059de2be +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/GameSystem.prefab b/Assets/Prefabs/GameSystem.prefab index a51b9cf..d1a50ce 100644 --- a/Assets/Prefabs/GameSystem.prefab +++ b/Assets/Prefabs/GameSystem.prefab @@ -61,8 +61,9 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 1361501530690105541} + - component: {fileID: 5363602638374141029} m_Layer: 0 - m_Name: Audio + m_Name: AudioManager m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -83,6 +84,20 @@ Transform: m_Father: {fileID: 2157073180203202247} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &5363602638374141029 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 422892530533236511} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5e5c517d6d8a28a47969320717cb0627, type: 3} + m_Name: + m_EditorClassIdentifier: + ready: 0 + BGMusic: {fileID: 6898396145254654029} --- !u!1 &2157073178696562865 GameObject: m_ObjectHideFlags: 0 @@ -395,6 +410,7 @@ GameObject: - component: {fileID: 5023819249935670292} - component: {fileID: 4688376570334067842} - component: {fileID: 3569788005944565417} + - component: {fileID: 5441382446788087128} - component: {fileID: 6898396145254654029} m_Layer: 0 m_Name: BackgroundMusic @@ -514,6 +530,102 @@ AudioSource: 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!82 &5441382446788087128 AudioSource: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -621,5 +733,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e845a10d8c5009048af900f3e22daa91, type: 3} m_Name: m_EditorClassIdentifier: - AudioIntensity0: {fileID: 0} - AudioIntensity1: {fileID: 8300000, guid: 849452323efae574d8141c82f7b28f55, type: 3} + intensity: 0 + AudioIntensity0: {fileID: 8300000, guid: 67990e289ee555c4182dabba061eebcd, type: 3} + AudioIntensity1: {fileID: 8300000, guid: 271965f1fde0f9f41933e807059de2be, type: 3} + AudioIntensity2: {fileID: 8300000, guid: 3274177b211a55c42a0a2ce4a6ae61ba, type: 3} diff --git a/Assets/Scenes/Tests/SampleScene.unity b/Assets/Scenes/Tests/SampleScene.unity index fd6e6bd..c44f0a7 100644 --- a/Assets/Scenes/Tests/SampleScene.unity +++ b/Assets/Scenes/Tests/SampleScene.unity @@ -32664,6 +32664,36 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 5363602638374141029, guid: dfb09d229e85c1446bee2e4f9357610e, + type: 3} + propertyPath: clientWeight + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5363602638374141029, guid: dfb09d229e85c1446bee2e4f9357610e, + type: 3} + propertyPath: HardObsWeight + value: 1.5 + objectReference: {fileID: 0} + - target: {fileID: 5363602638374141029, guid: dfb09d229e85c1446bee2e4f9357610e, + type: 3} + propertyPath: SoftObsWeight + value: 0.3 + objectReference: {fileID: 0} + - target: {fileID: 6898396145254654029, guid: dfb09d229e85c1446bee2e4f9357610e, + type: 3} + propertyPath: changeTime + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 6898396145254654029, guid: dfb09d229e85c1446bee2e4f9357610e, + type: 3} + propertyPath: AudioIntensity0 + value: + objectReference: {fileID: 8300000, guid: 67990e289ee555c4182dabba061eebcd, type: 3} + - target: {fileID: 6898396145254654029, guid: dfb09d229e85c1446bee2e4f9357610e, + type: 3} + propertyPath: AudioIntensity1 + value: + objectReference: {fileID: 8300000, guid: 271965f1fde0f9f41933e807059de2be, type: 3} - target: {fileID: 7408334756516261553, guid: dfb09d229e85c1446bee2e4f9357610e, type: 3} propertyPath: range diff --git a/Assets/Scripts/GameSystems/AudioManager.cs b/Assets/Scripts/GameSystems/AudioManager.cs new file mode 100644 index 0000000..ada039d --- /dev/null +++ b/Assets/Scripts/GameSystems/AudioManager.cs @@ -0,0 +1,73 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public sealed class AudioManager : MonoBehaviour +{ + public static string AudioManager_path="/GameSystem/AudioManager"; + //Singleton + private static AudioManager _instance=null; + public static AudioManager Instance { get + { + if(_instance is null) //Force Awakening if needed + GameObject.Find(AudioManager_path).GetComponent().Awake(); + return _instance; + } + } + + [HideInInspector] + public bool ready = false; //Wether the AudioManager is initialized + + [SerializeField] + BGMusic BGMusic = null; //Background music script + + [SerializeField] + float clientWeight=1.0f, HardObsWeight=1.0f, SoftObsWeight=1.0f; //Importance of each entity + + float maxEntity; //Maximum entities (client + events) weighted by importance + float currentNbEntity; //Current number of entities (Client + events) weighted by importance + + //Update audio intensity + void updateIntensity() + { + //Intensity change thresholds + float upThreshold = ((BGMusic.Intensity+1)*maxEntity)/BGMusic.Levels; + float downTreshold = ((BGMusic.Intensity)*maxEntity)/BGMusic.Levels; //add -1 or % to prevent constant change ? + // Debug.Log(gameObject.name+" - treshold : (+)"+upThreshold+"/(-)"+downTreshold); + + //Update intensity + if(BGMusic.Intensity<(BGMusic.Levels-1) && currentNbEntity> upThreshold) //Increase Intensity if needed + BGMusic.Intensity++; + else if(BGMusic.Intensity>0 && currentNbEntity< downTreshold) //Decrease Intensity if needed + BGMusic.Intensity--; + } + + // Start is called before the first frame update + void Awake() + { + //Singleton + if (_instance != null && _instance != this) + Destroy(this.gameObject); + else + _instance = this; + + if(!ready) + { + if(BGMusic is null) + Debug.LogError(gameObject.name+" doesnt have a background music script"); + + //Maximum entity weighted by importance + maxEntity = clientWeight*ClientManager.Instance.MaxClients+HardObsWeight*EventManager.Instance.MaxEvents("Hard")+SoftObsWeight*EventManager.Instance.MaxEvents("Soft"); + + ready = true; + } + } + + // Update is called once per frame + void Update() + { + //Update current number of entity (weighted) + currentNbEntity=clientWeight*ClientManager.Instance.clientList.Count+HardObsWeight*EventManager.Instance.eventCount("Hard")+SoftObsWeight*EventManager.Instance.eventCount("Soft"); + updateIntensity(); + } +} diff --git a/Assets/Scripts/GameSystems/AudioManager.cs.meta b/Assets/Scripts/GameSystems/AudioManager.cs.meta new file mode 100644 index 0000000..3eaab66 --- /dev/null +++ b/Assets/Scripts/GameSystems/AudioManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5e5c517d6d8a28a47969320717cb0627 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/GameSystems/BGMusic.cs b/Assets/Scripts/GameSystems/BGMusic.cs index 0070518..3ceb451 100644 --- a/Assets/Scripts/GameSystems/BGMusic.cs +++ b/Assets/Scripts/GameSystems/BGMusic.cs @@ -5,48 +5,79 @@ 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) + //Intensity levels [SerializeField] - AudioClip AudioIntensity0, AudioIntensity1; //Must have enough clip foreach intensity levels + int intensity= 0; //Current intensity level + public int Intensity{get{return intensity;} set{changeIntensity(value);}} //Accessors intensity + public static int Levels= 3; //Number of intensity levels (differents tracks) + + //Clips + [SerializeField] + AudioClip AudioIntensity0, AudioIntensity1, AudioIntensity2; //Must have enough clip foreach intensity levels List audioSources; //Sources used for each intensity clips + List targetVolumes = new List(Levels); + [SerializeField] + float changeTime = 1.0f; //Time to smoothly change intensity level + List changeVelocity = new List(Levels); //Current velocity for smooth change - //Change the intensity level of the music - //TODO: Smooth transition - public void changeIntensity(int level) + //Change the intensity level of the music. If instantChange is false, do it smoothly. + public void changeIntensity(int level, bool instantChange=false) { - if(level>=intensityLevels) + if(level>=Levels) { - Debug.LogWarning(gameObject.name+" doesn't have such high intensity available :"+ level+ " /"+intensityLevels); - level = intensityLevels-1; //Max level + Debug.LogWarning(gameObject.name+" doesn't have such high intensity available :"+ level+ " /"+Levels); + level = Levels-1; //Max level + } + else if(level<0) + { + Debug.LogWarning(gameObject.name+" doesn't have such low intensity available :"+ level+ " /"+Levels); + level = 0; //Min level } - for(int i=0; i(GetComponents()); - if(audioSources.Count != intensityLevels ) - Debug.LogWarning(gameObject.name+" missing audio sources too play all intensity levels : "+ intensityLevels); + if(audioSources.Count != Levels ) + Debug.LogWarning(gameObject.name+" needs "+Levels+" audio sources. Found : "+audioSources.Count); //Load clip audioSources[0].clip = AudioIntensity0; audioSources[1].clip = AudioIntensity1; + audioSources[2].clip = AudioIntensity2; + + //Initialize target & velocities + for(int i=0; i coroutines= new Dictionary(); //Dict of EventManager coroutines associated to each client ID - //Spawn an event near position with a probability of spawnChance% + //Return the maximum number of events ("Soft"; "Hard") + public int MaxEvents(string types="SoftHard") + { + int res=0; + if(types.Contains("Soft")) + res+=maxSoftObs; + if(types.Contains("Hard")) + res+=maxHardObs; + + return res; + } + //Return the current number of events ("Soft"; "Hard") + public int eventCount(string types="SoftHard") + { + int res=0; + if(types.Contains("Soft")) + res+=softObsList.Count; + if(types.Contains("Hard")) + res+=hardObsList.Count; + + return res; + } + + //Spawn a soft obstacle near position with a probability of spawnChance% public void spawnSoftObs(Vector2 position, float spawnChance = 100.0f) { Vector3 spawnPoint; @@ -63,6 +86,7 @@ public sealed class EventManager : MonoBehaviour // eventSpawnReady=false; } } + //Spawn a hard obstacle near position with a probability of spawnChance%, and assign targetClients to it public void spawnHardObs(List targetClients, Vector2 position, float spawnChance = 100.0f) { //TODO: Orienté client vers event + prefab diff --git a/Assets/Scripts/GameSystems/GameSystem.cs b/Assets/Scripts/GameSystems/GameSystem.cs index cbe6cba..e2af840 100644 --- a/Assets/Scripts/GameSystems/GameSystem.cs +++ b/Assets/Scripts/GameSystems/GameSystem.cs @@ -30,9 +30,6 @@ 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; @@ -105,13 +102,6 @@ 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(); - 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) @@ -123,7 +113,7 @@ public sealed class GameSystem : MonoBehaviour UIServiceTimer=timerObj.GetComponent(); //Check that all systems are ready - if(ClientManager.Instance.ready && StockManager.Instance.ready && EventManager.Instance.ready) + if(ClientManager.Instance.ready && StockManager.Instance.ready && EventManager.Instance.ready && AudioManager.Instance.ready) { ready=true; Debug.Log("All GameSystems are ready"); @@ -162,10 +152,6 @@ public sealed class GameSystem : MonoBehaviour toggleSlowMode(2.0f); Debug.Log("Time scale: "+Time.timeScale); } - - //Basic background music modification - if(ClientManager.Instance.clientList.Count>2 && BGmusic.intensity<1) - BGmusic.changeIntensity(1); } // simple Singleton implementation