diff --git a/Assets/Resources/Data/Cutscene/Tutorial1.asset b/Assets/Resources/Data/Cutscene/Tutorial1.asset index 63fab5b69eb8a3477a753fa3ea3cf8b8b8a71e67..02f1285587ba0b20c15e8a38070697e139c1cd0d 100644 --- a/Assets/Resources/Data/Cutscene/Tutorial1.asset +++ b/Assets/Resources/Data/Cutscene/Tutorial1.asset @@ -259,10 +259,10 @@ MonoBehaviour: animation: 2 audio: source: {fileID: 0} - name: - clip: {fileID: 0} - volume: 0 - pitch: 0 + name: swipe + clip: {fileID: 8300000, guid: fb9422424cdecad4196e684e4852c918, type: 3} + volume: 1 + pitch: 1 loop: 0 spatialize: 0 - Text: Gih sono cobain ke dummy di tengah map diff --git a/Assets/Resources/Data/Cutscene/Tutorial2.asset b/Assets/Resources/Data/Cutscene/Tutorial2.asset index e9dfbdbfb4467cb80f65b23d1a7ef527acd0f55a..319fbc628c94e61ad78bb5792387794db58d4bdf 100644 --- a/Assets/Resources/Data/Cutscene/Tutorial2.asset +++ b/Assets/Resources/Data/Cutscene/Tutorial2.asset @@ -151,10 +151,10 @@ MonoBehaviour: animation: 2 audio: source: {fileID: 0} - name: - clip: {fileID: 0} - volume: 0 - pitch: 0 + name: swipe + clip: {fileID: 8300000, guid: fb9422424cdecad4196e684e4852c918, type: 3} + volume: 1 + pitch: 1 loop: 0 spatialize: 0 - Text: Gih sono cobain ke dummy di tengah map diff --git a/Assets/UI/InGame/Dialog/DialogController.cs b/Assets/UI/InGame/Dialog/DialogController.cs index adbfa5eb3a623d3b5de06caeabb62769150b9328..73f482a73b92b68e6a5b20ffb5276d8bbfe1c92d 100644 --- a/Assets/UI/InGame/Dialog/DialogController.cs +++ b/Assets/UI/InGame/Dialog/DialogController.cs @@ -19,6 +19,7 @@ public class DialogController : ScreenController private float endY = -50f; private Coroutine currentAnimationLeft; private Coroutine currentAnimationRight; + private static Audio currentAudio; // Events private event Action OnCutsceneFinished; @@ -60,11 +61,11 @@ public class DialogController : ScreenController public void ProgressCutscene() { StopAnimation(); - if(cutsceneProgress < currentCutscene.dialogs.Count) + if (cutsceneProgress < currentCutscene.dialogs.Count) { cutsceneProgress++; - if(cutsceneProgress == currentCutscene.dialogs.Count) + if (cutsceneProgress == currentCutscene.dialogs.Count) { GameController.Instance.stateController.PopState(); OnCutsceneFinished?.Invoke(); @@ -72,9 +73,16 @@ public class DialogController : ScreenController else { LoadData(currentCutscene.dialogs[cutsceneProgress]); - if(currentCutscene.dialogs[cutsceneProgress].audio.source != null) + if (GameAudioController.IsValidAudio(currentCutscene.dialogs[cutsceneProgress].audio)) { - GameAudioController.Instance.PlayOnce(currentCutscene.dialogs[cutsceneProgress].audio); + Debug.Log("Cutscene: Playing audio"); + currentAudio = currentCutscene.dialogs[cutsceneProgress].audio; + GameAudioController.Instance.PlayOnce(currentAudio); + } + else + { + Debug.Log("Cutscene: No audio"); + currentAudio = null; } } } @@ -108,7 +116,7 @@ public class DialogController : ScreenController dialogOverlay.m_PersonRImage.visible = data.PersonRActive; dialogOverlay.m_PersonRImage.style.backgroundImage = new StyleBackground(data.PersonRImage); dialogOverlay.m_PersonRLabelText.text = data.PersonRName; - + dialogOverlay.m_MainText.text = data.Text; Animate(data.animation); @@ -164,7 +172,7 @@ public class DialogController : ScreenController yield return new WaitForSecondsRealtime(0.001f); } dialogOverlay.m_PersonLImage.style.top = targetY; - + targetY = initialY; newY = endY; @@ -187,7 +195,7 @@ public class DialogController : ScreenController yield return new WaitForSecondsRealtime(0.001f); } dialogOverlay.m_PersonRImage.style.top = targetY; - + targetY = initialY; newY = endY; @@ -200,17 +208,24 @@ public class DialogController : ScreenController } dialogOverlay.m_PersonRImage.style.top = targetY; break; - + default: yield return null; break; - } + } } private void KeyPress(InputAction.CallbackContext context) { - if(InCutscene) + if (InCutscene) { + Debug.Log("Cutscene: In cutscene"); + if (currentAudio != null) + { + Debug.Log("Cutscene: Stopping current audio"); + Destroy(currentAudio.source); + GameAudioController.Instance.StopAllCoroutines(); + } ProgressCutscene(); } } diff --git a/Assets/_Scripts/Core/Game/GameAudioController.cs b/Assets/_Scripts/Core/Game/GameAudioController.cs index fee2206b3e304288229984d3d53e360ffdb80cc7..f4c475df2fb527eabaa39cba74d9b850cb74bd2c 100644 --- a/Assets/_Scripts/Core/Game/GameAudioController.cs +++ b/Assets/_Scripts/Core/Game/GameAudioController.cs @@ -8,7 +8,7 @@ public class GameAudioController : MonoBehaviour protected void Awake() { - if(Instance != null) + if (Instance != null) { Destroy(gameObject); return; @@ -19,6 +19,11 @@ public class GameAudioController : MonoBehaviour audioController.Init(this); } + public static bool IsValidAudio(Audio audio) + { + return audio != null && audio.clip != null; + } + public void PlayOnce(Audio audio, float volume = 1) { audio.source = gameObject.AddComponent<AudioSource>(); @@ -44,7 +49,7 @@ public class GameAudioController : MonoBehaviour audio.spatialize = false; audio.Play(); - + StartCoroutine(DeleteClipWhenComplete(audio)); }