diff --git a/Assets/Code/AfterStart.cs b/Assets/Code/AfterStart.cs new file mode 100644 index 0000000..b7c983a --- /dev/null +++ b/Assets/Code/AfterStart.cs @@ -0,0 +1,4 @@ +//From https://answers.unity.com/questions/442342/how-to-make-public-variable-read-only-during-run-t.html +using UnityEngine; + +public class AfterStart : PropertyAttribute {} diff --git a/Assets/Editor/AfterStart.cs.meta b/Assets/Code/AfterStart.cs.meta similarity index 83% rename from Assets/Editor/AfterStart.cs.meta rename to Assets/Code/AfterStart.cs.meta index d25ef57..9a6351d 100644 --- a/Assets/Editor/AfterStart.cs.meta +++ b/Assets/Code/AfterStart.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9903d7c519b2c6849943c4d6b8dab4bf +guid: 9fae7738546fcf6408a8a1e986460fda MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Code/BeforeStart.cs b/Assets/Code/BeforeStart.cs new file mode 100644 index 0000000..2118cda --- /dev/null +++ b/Assets/Code/BeforeStart.cs @@ -0,0 +1,4 @@ +//From https://answers.unity.com/questions/442342/how-to-make-public-variable-read-only-during-run-t.html +using UnityEngine; + +public class BeforeStart : PropertyAttribute {} diff --git a/Assets/Editor/BeforeStart.cs.meta b/Assets/Code/BeforeStart.cs.meta similarity index 83% rename from Assets/Editor/BeforeStart.cs.meta rename to Assets/Code/BeforeStart.cs.meta index 6ff2567..1b63ee2 100644 --- a/Assets/Editor/BeforeStart.cs.meta +++ b/Assets/Code/BeforeStart.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: de6a180c8ef2dbd44ae2fd0f7a040623 +guid: c80c3920999989b4b920fe2953ade20e MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Components/MusicManager.cs b/Assets/Components/MusicManager.cs index a3cbaec..50059bc 100644 --- a/Assets/Components/MusicManager.cs +++ b/Assets/Components/MusicManager.cs @@ -7,7 +7,13 @@ using UnityEngine; public class MusicManager : MonoBehaviour { public AudioSource baseLayer; - public List layers; + public float changeSpeed = 1f; + + [BeforeStart] + public AudioSource[] layers; + + protected float baseLayerTargetVolume; + protected float[] targetVolume; protected bool neverStarted; @@ -16,15 +22,20 @@ public class MusicManager : MonoBehaviour foreach(AudioSource audioSource in layers) { audioSource.volume = 0; } + targetVolume = new float[layers.Length]; + for(int i = 0; i < layers.Length; i++) { + targetVolume[i] = 0f; + } + baseLayerTargetVolume = 1f; neverStarted = true; } public void UpdateLayers(int maxTier) { if(maxTier == -1) { - baseLayer.volume = 1f; + baseLayerTargetVolume = 1f; } else { - baseLayer.volume = 0f; + baseLayerTargetVolume = 0f; } if(neverStarted) { @@ -34,20 +45,39 @@ public class MusicManager : MonoBehaviour neverStarted = false; } - if(maxTier >= layers.Count) { - foreach(AudioSource layer in layers) { - layer.volume = 1f; + if(maxTier >= layers.Length) { + for(int i = 0; i < layers.Length; i++) { + targetVolume[i] = 1f; } } else { - for(int i = 0; i < layers.Count; i++) { + for(int i = 0; i < layers.Length; i++) { if(maxTier >= i) { - layers[i].volume = 1f; + targetVolume[i] = 1f; } else { - layers[i].volume = 0f; + targetVolume[i] = 0f; } } } } + + protected void Update() { + if(baseLayer.volume > baseLayerTargetVolume) { + baseLayer.volume = Mathf.Clamp(baseLayer.volume - Time.deltaTime * changeSpeed, baseLayerTargetVolume, float.PositiveInfinity); + } + else if(baseLayer.volume < baseLayerTargetVolume) { + baseLayer.volume = Mathf.Clamp(baseLayer.volume + Time.deltaTime * changeSpeed, 0f, baseLayerTargetVolume); + } + + for(int i = 0; i < layers.Length; i++) { + if(layers[i].volume > targetVolume[i]) { + layers[i].volume = Mathf.Clamp(layers[i].volume - Time.deltaTime * changeSpeed, targetVolume[i], float.PositiveInfinity); + } + else if(layers[i].volume < targetVolume[i]) { + layers[i].volume = Mathf.Clamp(layers[i].volume + Time.deltaTime * changeSpeed, 0f, targetVolume[i]); + } + } + } + } diff --git a/Assets/Editor/AfterStart.cs b/Assets/Editor/AfterStartAttributeDrawer.cs similarity index 94% rename from Assets/Editor/AfterStart.cs rename to Assets/Editor/AfterStartAttributeDrawer.cs index a9787e3..0be6663 100644 --- a/Assets/Editor/AfterStart.cs +++ b/Assets/Editor/AfterStartAttributeDrawer.cs @@ -19,5 +19,3 @@ public class AfterStartAttributeDrawer : PropertyDrawer GUI.enabled = true; } } - -public class AfterStart : PropertyAttribute {} diff --git a/Assets/Editor/AfterStartAttributeDrawer.cs.meta b/Assets/Editor/AfterStartAttributeDrawer.cs.meta new file mode 100644 index 0000000..347df41 --- /dev/null +++ b/Assets/Editor/AfterStartAttributeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bb6935448ef8afa40b70179ed82526f3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/BeforeStart.cs b/Assets/Editor/BeforeStartAttributeDrawer.cs similarity index 80% rename from Assets/Editor/BeforeStart.cs rename to Assets/Editor/BeforeStartAttributeDrawer.cs index 63ada79..1ef0ab8 100644 --- a/Assets/Editor/BeforeStart.cs +++ b/Assets/Editor/BeforeStartAttributeDrawer.cs @@ -1,4 +1,4 @@ -//From https://answers.unity.com/questions/442342/how-to-make-public-variable-read-only-during-run-t.html +//From https://answers.unity.com/questions/442342/how-to-make-public-variable-read-only-during-run-t.html using UnityEngine; using UnityEditor; @@ -18,6 +18,4 @@ public class BeforeStartAttributeDrawer : PropertyDrawer EditorGUI.PropertyField(position, property, label, true); GUI.enabled = true; } -} - -public class BeforeStart : PropertyAttribute {} +} \ No newline at end of file diff --git a/Assets/Editor/BeforeStartAttributeDrawer.cs.meta b/Assets/Editor/BeforeStartAttributeDrawer.cs.meta new file mode 100644 index 0000000..470f5a0 --- /dev/null +++ b/Assets/Editor/BeforeStartAttributeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0c5fc3bdbfd0b2c4cb8ffcc597e1d884 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/GameController.prefab b/Assets/Prefabs/GameController.prefab index be03dd8..06d7535 100644 --- a/Assets/Prefabs/GameController.prefab +++ b/Assets/Prefabs/GameController.prefab @@ -1,5 +1,132 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!1 &1636788349 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1636788350} + - component: {fileID: 1636788351} + m_Layer: 0 + m_Name: Layer 2 + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1636788350 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1636788349} + 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: 1990625892755510357} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!82 &1636788351 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1636788349} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 8300000, guid: 7f5aa2a2cf682734ba7c9842badb7b84, type: 3} + m_PlayOnAwake: 0 + 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!1 &2840017336573732720 GameObject: m_ObjectHideFlags: 0 @@ -42,7 +169,7 @@ AudioSource: serializedVersion: 4 OutputAudioMixerGroup: {fileID: 0} m_audioClip: {fileID: 8300000, guid: 37e30c686763c1e4ca22b20a356252c0, type: 3} - m_PlayOnAwake: 1 + m_PlayOnAwake: 0 m_Volume: 1 m_Pitch: 1 Loop: 1 @@ -392,8 +519,10 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: baseLayer: {fileID: 787973444833592173} + changeSpeed: 1 layers: - {fileID: 4850948939192426854} + - {fileID: 1636788351} --- !u!1 &7887871963136015922 GameObject: m_ObjectHideFlags: 0 @@ -550,6 +679,7 @@ Transform: m_Children: - {fileID: 2826821897386302087} - {fileID: 576137496605705657} + - {fileID: 1636788350} m_Father: {fileID: 9012813807232547518} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index e8fe65c..0e634fa 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -590,11 +590,6 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 4850948939192426854, guid: bf08d766b6e86cf4a8773489143ab2d5, - type: 3} - propertyPath: m_PlayOnAwake - value: 0 - objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: bf08d766b6e86cf4a8773489143ab2d5, type: 3} --- !u!1001 &9221969453494073200