diff --git a/Assets/Jokes/test.txt b/Assets/Jokes/test.txt deleted file mode 100644 index 9ddf938..0000000 --- a/Assets/Jokes/test.txt +++ /dev/null @@ -1 +0,0 @@ -aaaccc|van 2:1234|y se cae el del medio \ No newline at end of file diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 6b57d65..c110018 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -1438,6 +1438,81 @@ RectTransform: m_CorrespondingSourceObject: {fileID: 5783143251392024687, guid: 5430324ec74b5f04581d090658d90b3e, type: 3} m_PrefabInstance: {fileID: 804374705} m_PrefabAsset: {fileID: 0} +--- !u!1 &843204719 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 843204720} + - component: {fileID: 843204722} + - component: {fileID: 843204721} + m_Layer: 5 + m_Name: Progress + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &843204720 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 843204719} + 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: 1540972244} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 344, y: -69.000015} + m_SizeDelta: {x: 15, y: 177} + m_Pivot: {x: 0, y: 1} +--- !u!114 &843204721 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 843204719} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: -791923143, guid: 05014e62dbe8d3e41800f5cf0f739c9e, type: 3} + m_Type: 3 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 1 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 6.25 +--- !u!222 &843204722 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 843204719} + m_CullTransparentMesh: 1 --- !u!1 &861656303 GameObject: m_ObjectHideFlags: 0 @@ -2103,7 +2178,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!225 &1198578935 CanvasGroup: m_ObjectHideFlags: 0 @@ -2387,6 +2462,183 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!1 &1352489076 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1352489080} + - component: {fileID: 1352489079} + - component: {fileID: 1352489078} + - component: {fileID: 1352489077} + m_Layer: 5 + m_Name: ProgressCanvas + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1352489077 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1352489076} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3} + m_Name: + m_EditorClassIdentifier: + m_IgnoreReversedGraphics: 1 + m_BlockingObjects: 0 + m_BlockingMask: + serializedVersion: 2 + m_Bits: 4294967295 +--- !u!114 &1352489078 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1352489076} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3} + m_Name: + m_EditorClassIdentifier: + m_UiScaleMode: 1 + m_ReferencePixelsPerUnit: 100 + m_ScaleFactor: 1 + m_ReferenceResolution: {x: 480, y: 270} + m_ScreenMatchMode: 0 + m_MatchWidthOrHeight: 1 + m_PhysicalUnit: 3 + m_FallbackScreenDPI: 96 + m_DefaultSpriteDPI: 96 + m_DynamicPixelsPerUnit: 1 + m_PresetInfoIsWorld: 0 +--- !u!223 &1352489079 +Canvas: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1352489076} + m_Enabled: 1 + serializedVersion: 3 + m_RenderMode: 0 + m_Camera: {fileID: 0} + m_PlaneDistance: 100 + m_PixelPerfect: 0 + m_ReceivesEvents: 1 + m_OverrideSorting: 0 + m_OverridePixelPerfect: 0 + m_SortingBucketNormalizedSize: 0 + m_VertexColorAlwaysGammaSpace: 0 + m_AdditionalShaderChannelsFlag: 0 + m_UpdateRectTransformForStandalone: 0 + m_SortingLayerID: 0 + m_SortingOrder: 1 + m_TargetDisplay: 0 +--- !u!224 &1352489080 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1352489076} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 0, y: 0, z: 0} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 1540972244} + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0, y: 0} +--- !u!1 &1488949019 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1488949020} + - component: {fileID: 1488949022} + - component: {fileID: 1488949021} + m_Layer: 5 + m_Name: Border + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1488949020 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1488949019} + 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: 1540972244} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 343, y: -68} + m_SizeDelta: {x: 17, y: 180} + m_Pivot: {x: 0, y: 1} +--- !u!114 &1488949021 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1488949019} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 21300000, guid: b09081262d17c3044b0775a2be56d51d, type: 3} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 6.25 +--- !u!222 &1488949022 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1488949019} + m_CullTransparentMesh: 1 --- !u!1 &1539763154 GameObject: m_ObjectHideFlags: 0 @@ -2521,6 +2773,44 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1539763154} m_CullTransparentMesh: 1 +--- !u!1 &1540972243 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1540972244} + m_Layer: 5 + m_Name: Container + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1540972244 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1540972243} + 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: + - {fileID: 1639838825} + - {fileID: 843204720} + - {fileID: 1488949020} + m_Father: {fileID: 1352489080} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0} + m_AnchorMax: {x: 0.5, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 480, y: 0} + m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1620770958 stripped MonoBehaviour: m_CorrespondingSourceObject: {fileID: 5596010678248324506, guid: 5430324ec74b5f04581d090658d90b3e, type: 3} @@ -2653,6 +2943,81 @@ MonoBehaviour: - {fileID: 590262795} correctLive: {fileID: -773788709396254583, guid: 128ff2869c2580344a74d2dc6b9d9e6a, type: 3} wrongLive: {fileID: -8337258921713572487, guid: 128ff2869c2580344a74d2dc6b9d9e6a, type: 3} +--- !u!1 &1639838824 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1639838825} + - component: {fileID: 1639838827} + - component: {fileID: 1639838826} + m_Layer: 5 + m_Name: Background + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1639838825 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1639838824} + 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: 1540972244} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 343, y: -68} + m_SizeDelta: {x: 17, y: 180} + m_Pivot: {x: 0, y: 1} +--- !u!114 &1639838826 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1639838824} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 21300000, guid: 444382c0ca76cb04abc6852587ee6fb0, type: 3} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 6.25 +--- !u!222 &1639838827 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1639838824} + m_CullTransparentMesh: 1 --- !u!1 &1717907689 GameObject: m_ObjectHideFlags: 0 @@ -3645,4 +4010,5 @@ SceneRoots: - {fileID: 1741129169} - {fileID: 23275630} - {fileID: 1637937848} + - {fileID: 1352489080} - {fileID: 1198578939} diff --git a/Assets/Jokes/test.txt.meta b/Assets/Scripts/Audio.meta similarity index 57% rename from Assets/Jokes/test.txt.meta rename to Assets/Scripts/Audio.meta index ac94a98..ce68fc1 100644 --- a/Assets/Jokes/test.txt.meta +++ b/Assets/Scripts/Audio.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 -guid: 709db39fbdad6d64d913304ea83d7f85 -TextScriptImporter: +guid: 1f323de77930b4a45a85c388886626ee +folderAsset: yes +DefaultImporter: externalObjects: {} userData: assetBundleName: diff --git a/Assets/Scripts/Audio/AudioManager.cs b/Assets/Scripts/Audio/AudioManager.cs new file mode 100644 index 0000000..c24606b --- /dev/null +++ b/Assets/Scripts/Audio/AudioManager.cs @@ -0,0 +1,294 @@ +using System; +using System.Collections; +using UnityEngine; + +namespace Audio { + public class AudioManager : MonoBehaviour { + + public static AudioManager instance; + + [SerializeField] private Sounds soundList; + + private void Awake() { + if (instance == null) { + instance = this; + } else { + Destroy(gameObject); + return; + } + DontDestroyOnLoad(gameObject); + + foreach (Sounds.List s in soundList.sounds) { + if (string.IsNullOrEmpty(s.name) || string.IsNullOrWhiteSpace(s.name)) { + Debug.LogWarning("The name one sound is empty"); + continue; + } + + GameObject sound = new(s.name) { + transform = { + parent = transform + } + }; + s.source = sound.AddComponent(); + + if (soundList.mainMixer && soundList.sfxMixer) { + s.source.outputAudioMixerGroup = s.type == Sounds.List.Type.Music ? soundList.mainMixer : soundList.sfxMixer; + } + + s.source.clip = s.clip; + + s.source.volume = s.volume; + s.source.pitch = s.pitch; + s.source.loop = s.loop; + } + } + + #region Play + /// Use this to play a sound with a specific name + /// It has to be in the Sound asset referenced in the AudioManager instance + /// + /// The name of the sound + public void Play(string name) { + Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); + if (s == null) { + Debug.LogWarning("Sound: " + name + " not found!"); + return; + } + s.source.pitch = s.RandomPitch; + s.source.volume = s.RandomVolume; + s.source.Play(); + } + /// Use this to play a sound with a specific name and with a certain delay + /// It has to be in the Sound asset referenced in the AudioManager instance + /// + /// The name of the sound + /// The delay in seconds + public void Play(string name, float delay) { + Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); + if (s == null) { + Debug.LogWarning("Sound: " + name + " not found!"); + return; + } + s.source.pitch = s.RandomPitch; + s.source.volume = s.RandomVolume; + s.source.PlayDelayed(delay); + } + /// Use this to play one shot of a sound with a specific name + /// It has to be in the Sound asset referenced in the AudioManager instance + /// + /// The name of the sound + public void PlayOneShot(string name) { + Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); + if (s == null) { + Debug.LogWarning("Sound: " + name + " not found!"); + return; + } + s.source.pitch = s.RandomPitch; + s.source.volume = s.RandomVolume; + s.source.PlayOneShot(s.clip); + } + /// Use this to play an intro song and then start playing the song loop + /// It has to be in the Sound asset referenced in the AudioManager instance + /// + /// The name of the intro song + /// The name of the song loop + public void PlayWithIntro(string intro, string song) { + Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == intro); + if (s == null) { + Debug.LogWarning("Sound: " + intro + " not found!"); + return; + } + s.source.pitch = s.RandomPitch; + s.source.volume = s.RandomVolume; + s.source.Play(); + + float introDuration = s.clip.length; + Play(song, introDuration); + } + /// Use this to play one shot of a random sound within a list + /// They have to be in the Sound asset referenced in the AudioManager instance + /// + /// The names of the sounds + public void PlayRandomSound(params string[] names) { + int random = UnityEngine.Random.Range(0, names.Length); + PlayOneShot(names[random]); + } + #endregion + #region Pause + /// Use this to pause a sound with a specific name + /// It has to be in the Sound asset referenced in the AudioManager instance + /// + /// The name of the sound + public void Pause(string name) { + Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); + if (s == null) { + Debug.LogWarning("Sound: " + name + " not found!"); + return; + } + s.source.pitch = s.RandomPitch; + s.source.volume = s.RandomVolume; + s.source.Pause(); + } + /// Use this to unpause a sound with a specific name + /// It has to be in the Sound asset referenced in the AudioManager instance + /// + /// The name of the sound + public void UnPause(string name) { + Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); + if (s == null) { + Debug.LogWarning("Sound: " + name + " not found!"); + return; + } + s.source.pitch = s.RandomPitch; + s.source.volume = s.RandomVolume; + s.source.UnPause(); + } + #endregion + #region Stop + /// Use this to stop a sound with a specific name + /// It has to be in the Sound asset referenced in the AudioManager instance + /// + /// The name of the sound + public void Stop(string name) { + Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); + if (s == null) { + Debug.LogWarning("Sound: " + name + " not found!"); + return; + } + s.source.pitch = s.RandomPitch; + s.source.volume = s.RandomVolume; + s.source.Stop(); + } + /// Use this to stop all the sounds + /// It has to be in the Sound asset referenced in the AudioManager instance + /// + public void StopAll() { + foreach (Sounds.List s in soundList.sounds) { + if (s.source) { + s.source.Stop(); + } + } + } + #endregion + /// This function returns the AudioSource that contains a specific sound + /// It has to be in the Sound asset referenced in the AudioManager instance + /// + /// The name of the sound + /// The AudioSource in the scene + public AudioSource GetSource(string name) { + Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); + if (s == null) { + Debug.LogWarning("Sound: " + name + " not found!"); + return null; + } + return s.source; + } + #region Fades + /// Use this to start playing a sound with a fade in + /// It has to be in the Sound asset referenced in the AudioManager instance + /// + /// The name of the sound + /// The duration of the fade in + public void FadeIn(string name, float duration) { + StartCoroutine(FadeInCoroutine(name, duration)); + } + IEnumerator FadeInCoroutine(string name, float fadeTime) { + AudioSource audioSource = GetSource(name); + if (audioSource != null && !audioSource.isPlaying) { + float volume = audioSource.volume; + audioSource.volume = 0; + audioSource.Play(); + while (audioSource.volume < volume) { + audioSource.volume += Time.deltaTime / fadeTime; + yield return null; + } + + audioSource.volume = volume; + } + } + /// Use this to stop playing a sound with a fade out + /// It has to be in the Sound asset referenced in the AudioManager instance + /// + /// The name of the sound + /// The duration of the fade out + public void FadeOut(string name, float duration) { + StartCoroutine(FadeOutCoroutine(name, duration)); + } + + private IEnumerator FadeOutCoroutine(string name, float fadeTime) { + AudioSource audioSource = GetSource(name); + + if (!audioSource || !audioSource.isPlaying) yield break; + float startVolume = audioSource.volume; + + while (audioSource.volume > 0) { + audioSource.volume -= startVolume * Time.deltaTime / fadeTime; + yield return null; + } + + audioSource.Stop(); + audioSource.volume = startVolume; + } + + /// Use this to start playing a sound muted + /// It has to be in the Sound asset referenced in the AudioManager instance + /// + /// The name of the sound + public void PlayMuted(string name) { + Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); + if (s == null) { + Debug.LogWarning("Sound: " + name + " not found!"); + return; + } + s.source.pitch = s.RandomPitch; + s.source.volume = 0f; + s.source.Play(); + } + /// Use this to fade in a sound that is currently muted + /// It has to be in the Sound asset referenced in the AudioManager instance + /// WARNING: If the PlayMuted hasn't been called before, this function won't work + /// + /// The name of the sound + /// The duration of the fade in + public void FadeMutedIn(string name, float duration) { + StartCoroutine(FadeMutedInCoroutine(name, duration)); + } + + private IEnumerator FadeMutedInCoroutine(string name, float fadeTime) { + Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); + if (s == null) { + Debug.LogWarning("Sound: " + name + " not found!"); + yield break; + } + + while (s.source.volume < s.volume) { + s.source.volume += Time.deltaTime / fadeTime; + yield return null; + } + s.source.volume = s.volume; + } + /// Use this to fade out a sound and keep playing that muted + /// It has to be in the Sound asset referenced in the AudioManager instance + /// + /// The name of the sound + /// The duration of the fade out + public void FadeMutedOut(string name, float duration) { + StartCoroutine(FadeMutedOutCoroutine(name, duration)); + } + + private IEnumerator FadeMutedOutCoroutine(string name, float fadeTime) { + Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); + if (s == null) { + Debug.LogWarning("Sound: " + name + " not found!"); + yield break; + } + + while (s.source.volume > 0) { + s.source.volume -= Time.deltaTime / fadeTime; + yield return null; + } + s.source.volume = 0; + } + #endregion + } +} \ No newline at end of file diff --git a/Assets/Scripts/Audio/AudioManager.cs.meta b/Assets/Scripts/Audio/AudioManager.cs.meta new file mode 100644 index 0000000..9753039 --- /dev/null +++ b/Assets/Scripts/Audio/AudioManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b824c4cae81b29e41acd7881949b2789 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Audio/Sounds.cs b/Assets/Scripts/Audio/Sounds.cs new file mode 100644 index 0000000..82420d7 --- /dev/null +++ b/Assets/Scripts/Audio/Sounds.cs @@ -0,0 +1,53 @@ +using UnityEngine; +using UnityEngine.Audio; + +namespace Audio { + [CreateAssetMenu(fileName = "Sounds", menuName = "Simple Tools/Sounds", order = 11)] + public class Sounds : ScriptableObject { + + [Tooltip("The music mixer.")] + public AudioMixerGroup mainMixer; + [Tooltip("The SFX mixer.")] + public AudioMixerGroup sfxMixer; + + public List[] sounds; + + [System.Serializable] + public class List { + [Tooltip("Name of the sound. Each name has to be different between each other.")] + public string name; + + public AudioClip clip; + + [System.Serializable] public enum Type { Music, SFX } + [Space] + [Tooltip("Is it part of the music or the SFX?")] public Type type; + + [Space] + [Tooltip("Default volume of the sound."), Range(0f, 1f)] public float volume; + [Tooltip("Variance percentage of the volume"), Range(0f, 1f)] public float volumeVariance; + [Tooltip("Default pitch of the sound."), Range(.1f, 3f)] public float pitch; + [Tooltip("Variance percentage of the pitch"), Range(0f, 1f)] public float pitchVariance; + + public bool loop; + + [HideInInspector] public AudioSource source; + + private float _randomVolume; + public float RandomVolume { + get { + _randomVolume = volume * (1f + Random.Range(-volumeVariance / 2f, volumeVariance / 2f)); + return _randomVolume; + } + } + + private float _randomPitch; + public float RandomPitch { + get { + _randomPitch = pitch * (1f + Random.Range(-pitchVariance / 2f, pitchVariance / 2f)); + return _randomPitch; + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Audio/Sounds.cs.meta b/Assets/Scripts/Audio/Sounds.cs.meta new file mode 100644 index 0000000..10d435c --- /dev/null +++ b/Assets/Scripts/Audio/Sounds.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c4ed92ae62204888802bcdb9f4ea768c +timeCreated: 1706432143 \ No newline at end of file diff --git a/Assets/Scripts/Messaging/Typer/Message.cs b/Assets/Scripts/Messaging/Typer/Message.cs index a6bfc89..2a32eb8 100644 --- a/Assets/Scripts/Messaging/Typer/Message.cs +++ b/Assets/Scripts/Messaging/Typer/Message.cs @@ -23,7 +23,7 @@ namespace Messaging { answerContainer.InitializeTypers(); } - public void SetMessageText(string text, bool animate, bool isAnswer) { + public Coroutine SetMessageText(string text, bool animate, bool isAnswer) { Text = text; IsAnswer = isAnswer; IsReal = false; @@ -32,17 +32,19 @@ namespace Messaging { SetText(ref answerContainer.TypingCoroutine, answerContainer.messageText, answerContainer.TextTyper, text, animate); - if(string.IsNullOrEmpty(text)) return; + if(string.IsNullOrEmpty(text)) return null; answerContainer.container.SetActive(true); questionContainer.container.SetActive(false); - } else { - SetText(ref questionContainer.TypingCoroutine, questionContainer.messageText, - questionContainer.TextTyper, text, animate); - - if(string.IsNullOrEmpty(text)) return; - questionContainer.container.SetActive(true); - answerContainer.container.SetActive(false); + return answerContainer.TypingCoroutine; } + + SetText(ref questionContainer.TypingCoroutine, questionContainer.messageText, + questionContainer.TextTyper, text, animate); + + if(string.IsNullOrEmpty(text)) return null; + questionContainer.container.SetActive(true); + answerContainer.container.SetActive(false); + return questionContainer.TypingCoroutine; } public Coroutine SetMessageRealText(string text, bool animate, bool isAnswer) { diff --git a/Assets/Scripts/Messaging/Typer/MessageManager.cs b/Assets/Scripts/Messaging/Typer/MessageManager.cs index a1cf144..f446ce8 100644 --- a/Assets/Scripts/Messaging/Typer/MessageManager.cs +++ b/Assets/Scripts/Messaging/Typer/MessageManager.cs @@ -56,11 +56,12 @@ namespace Messaging { } public void CreateMessage(string message, bool isAnswer) { - ModifyMessageText(message, _messages.Length - 1, isAnswer); + ModifyMessageText(message, _messages.Length - 1, isAnswer, true); if (isAnswer) { _currentJokeIndex--; _currentJokeIndex = Mathf.Max(_currentJokeIndex, 0); if (message == _currentJoke.AnswerMessage.Key) { + _sendButton.Lock(); StartCoroutine(ShowRealTexts()); if(_currentJokeIndex == 0) SendRandomJoke(sendJokeLongDelay); @@ -69,6 +70,7 @@ namespace Messaging { } else { _lives.Wrong(); if (_lives.CurrentLives == 0) { + _sendButton.Lock(); StartCoroutine(ShowRealTexts()); SendRandomJoke(sendJokeLongDelay); _lives.ResetLives(); @@ -81,6 +83,7 @@ namespace Messaging { private IEnumerator ShowRealTexts() { yield return ModifyRealMessageText(_currentJoke.QuestionMessage.Value, _currentJokeIndex, false); + yield return ModifyMessageText(_currentJoke.AnswerMessage.Key, _messages.Length - 1, true, false); yield return ModifyRealMessageText(_currentJoke.AnswerMessage.Value, _messages.Length - 1, true); } @@ -111,9 +114,11 @@ namespace Messaging { return emojiStrings; } - private void ModifyMessageText(string message, int index, bool isAnswer) { - ModifyPreviousMessage(index); - _messages[index].SetMessageText(message, true, isAnswer); + private Coroutine ModifyMessageText(string message, int index, bool isAnswer, bool createNew) { + if(createNew) + ModifyPreviousMessage(index); + + return _messages[index].SetMessageText(message, true, isAnswer); } private Coroutine ModifyRealMessageText(string message, int index, bool isAnswer) { diff --git a/Assets/Sprites/Rellenobarra.png.meta b/Assets/Sprites/Rellenobarra.png.meta index b80f5d8..a1a769b 100644 --- a/Assets/Sprites/Rellenobarra.png.meta +++ b/Assets/Sprites/Rellenobarra.png.meta @@ -43,13 +43,13 @@ TextureImporter: nPOTScale: 0 lightmap: 0 compressionQuality: 50 - spriteMode: 1 + spriteMode: 2 spriteExtrude: 1 spriteMeshType: 1 alignment: 0 spritePivot: {x: 0.5, y: 0.5} spritePixelsToUnits: 16 - spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteBorder: {x: 1, y: 2, z: 1, w: 1} spriteGenerateFallbackPhysicsShape: 1 alphaUsage: 1 alphaIsTransparency: 1 @@ -108,18 +108,40 @@ TextureImporter: forceMaximumCompressionQuality_BC6H_BC7: 0 spriteSheet: serializedVersion: 2 - sprites: [] + sprites: + - serializedVersion: 2 + name: Rellenobarra_0 + rect: + serializedVersion: 2 + x: 1 + y: 2 + width: 15 + height: 41 + alignment: 0 + pivot: {x: 0, y: 0} + border: {x: 0, y: 0, z: 0, w: 0} + outline: [] + physicsShape: [] + tessellationDetail: 0 + bones: [] + spriteID: d15e3ebc0f05eac4b987b314fa62ad21 + internalID: -791923143 + vertices: [] + indices: + edges: [] + weights: [] outline: [] physicsShape: [] bones: [] spriteID: 5e97eb03825dee720800000000000000 - internalID: 0 + internalID: 1537655665 vertices: [] indices: edges: [] weights: [] secondaryTextures: [] - nameFileIdTable: {} + nameFileIdTable: + Rellenobarra_0: -791923143 mipmapLimitGroupName: pSDRemoveMatte: 0 userData: