diff --git a/Assets/JustSign/Scenes/Game.unity b/Assets/JustSign/Scenes/Game.unity index b96c34e..02cc14e 100644 --- a/Assets/JustSign/Scenes/Game.unity +++ b/Assets/JustSign/Scenes/Game.unity @@ -2425,14 +2425,14 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 1, g: 1, b: 1, a: 0.392} + m_Color: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 0.39215687} 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: 10907, guid: 0000000000000000f000000000000000, type: 0} + m_Sprite: {fileID: 0} m_Type: 1 m_PreserveAspect: 0 m_FillCenter: 1 @@ -5178,6 +5178,7 @@ MonoBehaviour: feedBack: {fileID: 128049076} scoreDisplay: {fileID: 1627575593} minigame: {fileID: 11400000, guid: e726e0b93ea88465db7ee27605deb83f, type: 2} + songList: {fileID: 11400000, guid: 4f0ce70309bb901feb28199a82a7d195, type: 2} hitZone: {fileID: 2012531007} symbolPrefab: {fileID: 4639383499500021565, guid: f3117b0203a1342a48a95904347b03c8, type: 3} symbolContainer: {fileID: 1768150806} @@ -5502,7 +5503,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 1, g: 1, b: 0, a: 1} + m_Color: {r: 0.0627451, g: 0.0627451, b: 0.0627451, a: 1} m_RaycastTarget: 1 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 diff --git a/Assets/JustSign/ScriptableObjects/Graceland.asset b/Assets/JustSign/ScriptableObjects/Graceland.asset new file mode 100644 index 0000000..2469490 --- /dev/null +++ b/Assets/JustSign/ScriptableObjects/Graceland.asset @@ -0,0 +1,18 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: cd3d1c3a6cf7ef07abb343f8862a7435, type: 3} + m_Name: Graceland + m_EditorClassIdentifier: + firstSymbolTime: 0.5 + spawnPeriod: 2 + duration: 127 + song: {fileID: 8300000, guid: e01ded5e221494bdbaab8674c0354f64, type: 3} diff --git a/Assets/JustSign/ScriptableObjects/Graceland.asset.meta b/Assets/JustSign/ScriptableObjects/Graceland.asset.meta new file mode 100644 index 0000000..7994bfc --- /dev/null +++ b/Assets/JustSign/ScriptableObjects/Graceland.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7a55c88547b9345fe87aecd1398550c9 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/JustSign/ScriptableObjects/SongList.asset b/Assets/JustSign/ScriptableObjects/SongList.asset new file mode 100644 index 0000000..a7136fd --- /dev/null +++ b/Assets/JustSign/ScriptableObjects/SongList.asset @@ -0,0 +1,18 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ceeae47a3efc2206299ddf1cc31043c2, type: 3} + m_Name: SongList + m_EditorClassIdentifier: + currentSongIndex: 0 + songs: + - {fileID: 11400000, guid: 0f5b5e156c628bf189df5723ad2aab96, type: 2} + - {fileID: 11400000, guid: 7a55c88547b9345fe87aecd1398550c9, type: 2} diff --git a/Assets/JustSign/ScriptableObjects/SongList.asset.meta b/Assets/JustSign/ScriptableObjects/SongList.asset.meta new file mode 100644 index 0000000..6ea237a --- /dev/null +++ b/Assets/JustSign/ScriptableObjects/SongList.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4f0ce70309bb901feb28199a82a7d195 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/JustSign/ScriptableObjects/SunnySafari.asset b/Assets/JustSign/ScriptableObjects/SunnySafari.asset new file mode 100644 index 0000000..44c2df0 --- /dev/null +++ b/Assets/JustSign/ScriptableObjects/SunnySafari.asset @@ -0,0 +1,18 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: cd3d1c3a6cf7ef07abb343f8862a7435, type: 3} + m_Name: SunnySafari + m_EditorClassIdentifier: + firstSymbolTime: 1.3 + spawnPeriod: 1.99 + duration: 164 + song: {fileID: 8300000, guid: d7ca1b558b7b064cdb6f9d6c951b1522, type: 3} diff --git a/Assets/JustSign/ScriptableObjects/SunnySafari.asset.meta b/Assets/JustSign/ScriptableObjects/SunnySafari.asset.meta new file mode 100644 index 0000000..09c3345 --- /dev/null +++ b/Assets/JustSign/ScriptableObjects/SunnySafari.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0f5b5e156c628bf189df5723ad2aab96 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/JustSign/Scripts/JustSignController.cs b/Assets/JustSign/Scripts/JustSignController.cs index 4a9a5ec..652012d 100644 --- a/Assets/JustSign/Scripts/JustSignController.cs +++ b/Assets/JustSign/Scripts/JustSignController.cs @@ -40,6 +40,16 @@ public class JustSignController : MonoBehaviour /// public Minigame minigame; + /// + /// Reference to the list of available songs + /// + public SongList songList; + + /// + /// Reference to the currently used song + /// + private Song currentSong; + /// /// The zone that the player should be hitting with his or her inputs /// @@ -80,6 +90,11 @@ public class JustSignController : MonoBehaviour /// private int score; + /// + /// Have the symbols started spawning or not + /// + private bool gameIsActive = false; + /// /// Width and height of the symbols /// @@ -146,9 +161,14 @@ public class JustSignController : MonoBehaviour private float lastSpawn; /// - /// Determines every how many seconds a symbol should spawn (will become music-dependent later on) + /// Time at which the game started, needed to know when to stop /// - private float spawnPeriod = 3.0f; + private float beginTime; + + /// + /// Time at which the last symbol should spawn + /// + private float lastSymbolTime; /// /// Start is called before the first frame update @@ -158,10 +178,22 @@ public class JustSignController : MonoBehaviour scoreDisplay.text = "Score: " + score.ToString(); currentTheme = minigame.themeList.themes[minigame.themeList.currentThemeIndex]; words.AddRange(currentTheme.learnables); - //currentTheme = FindThemeByName(PlayerPrefs.GetString("themeName")); - //words = currentTheme.words; - lastSpawn = Time.time; - SpawnNewSymbol(); + currentSong = songList.songs[songList.currentSongIndex]; + AudioSource.PlayClipAtPoint(currentSong.song, Vector3.zero, 1.0f); + beginTime = Time.time; + lastSymbolTime = beginTime + currentSong.duration - 1920.0f / moveSpeed; + + StartCoroutine(WaitThenStart(currentSong.firstSymbolTime)); + } + + /// + /// Wait for a given amount of time (specified in song) before spawning symbols + /// + IEnumerator WaitThenStart(float nrOfSeconds) + { + //yield on a new YieldInstruction that waits for nrOfSeconds seconds + yield return new WaitForSeconds(nrOfSeconds); + gameIsActive = true; } /// @@ -169,56 +201,68 @@ public class JustSignController : MonoBehaviour /// void Update() { - int matchedSymbolIndex = -1; - for (int i = 0; i < activeWords.Count; i++) { - if (activeWords[i].ToLower() == answerField.text.ToLower()) { - matchedSymbolIndex = i; - } - } - - // Destroy the oldest symbol if the current input matches it - if (matchedSymbolIndex >= 0) { - int difference = Math.Abs((int) (activeSymbols[matchedSymbolIndex].transform.position.x - hitZone.transform.position.x)); - if (difference < perfectBoundary) { - feedBack.text = "Perfect!"; - score += perfectScore; - } else if (difference < goodBoundary) { - feedBack.text = "Good!"; - score += goodScore; - } else if (difference < mehBoundary) { - feedBack.text = "Meh..."; - score += mehScore; - } else { - feedBack.text = "Terrible!"; - score += terribleScore; + if (gameIsActive) { + int matchedSymbolIndex = -1; + for (int i = 0; i < activeWords.Count; i++) { + if (activeWords[i].ToLower() == answerField.text.ToLower()) { + matchedSymbolIndex = i; + } } - DestroySymbolAt(matchedSymbolIndex); - answerField.text = ""; - } + // Destroy the oldest symbol if the current input matches it + if (matchedSymbolIndex >= 0) { + int difference = Math.Abs((int) (activeSymbols[matchedSymbolIndex].transform.position.x - hitZone.transform.position.x)); + if (difference < perfectBoundary) { + feedBack.text = "Perfect!"; + score += perfectScore; + } else if (difference < goodBoundary) { + feedBack.text = "Good!"; + score += goodScore; + } else if (difference < mehBoundary) { + feedBack.text = "Meh..."; + score += mehScore; + } else { + feedBack.text = "Terrible!"; + score += terribleScore; + } - // Destroy the oldest symbol if it leaves the screen - if (activeSymbols.Count > 0) { - if (activeSymbols[0].GetComponent().localPosition.x > -trackX) { - DestroySymbolAt(0); - score += offscreenScore; + DestroySymbolAt(matchedSymbolIndex); + answerField.text = ""; } - } - // Spawn new symbol every spawn period - float currentTime = Time.time; - if (currentTime - lastSpawn > spawnPeriod) { - lastSpawn = currentTime; - SpawnNewSymbol(); - } + // Destroy the oldest symbol if it leaves the screen + if (activeSymbols.Count > 0) { + if (activeSymbols[0].GetComponent().localPosition.x > -trackX) { + DestroySymbolAt(0); + feedBack.text = "Terrible!"; + score += offscreenScore; + } + } - // Move all active symbols to the right - foreach (GameObject symbol in activeSymbols) { - RectTransform rectTransform = symbol.GetComponent(); - rectTransform.localPosition = new Vector3(rectTransform.localPosition.x + Time.deltaTime * moveSpeed, trackY, 0); - } + // Spawn new symbol every spawn period + float currentTime = Time.time; + if (currentTime - lastSpawn > currentSong.spawnPeriod && lastSymbolTime > currentTime) { + lastSpawn = currentTime; + SpawnNewSymbol(); + } - scoreDisplay.text = "Score: " + score.ToString(); + // Check if the song has ended and activate scorescreen if it has + if (currentTime - beginTime > currentSong.duration) { + gameIsActive = false; + while (activeSymbols.Count > 0) { + DestroySymbolAt(0); + } + // TODO: Scoreboard + } + + // Move all active symbols to the right + foreach (GameObject symbol in activeSymbols) { + RectTransform rectTransform = symbol.GetComponent(); + rectTransform.localPosition = new Vector3(rectTransform.localPosition.x + Time.deltaTime * moveSpeed, trackY, 0); + } + + scoreDisplay.text = "Score: " + score.ToString(); + } } /// diff --git a/Assets/JustSign/Scripts/JustSignController.cs.meta b/Assets/JustSign/Scripts/JustSignController.cs.meta index 6afc28f..a4dbffe 100644 --- a/Assets/JustSign/Scripts/JustSignController.cs.meta +++ b/Assets/JustSign/Scripts/JustSignController.cs.meta @@ -1,13 +1,18 @@ fileFormatVersion: 2 -<<<<<<<< HEAD:Assets/JustSign/Scripts/JustSignController.cs.meta guid: 9ede962218eda88668cd8032b921aada -======== -guid: 40ff941e1b34847bdb160c6950f35aec ->>>>>>>> development:Assets/MediaPipeUnity/Common/Scripts/KeypointManager.cs.meta MonoImporter: externalObjects: {} serializedVersion: 2 - defaultReferences: [] + defaultReferences: + - canvas: {instanceID: 0} + - answerField: {instanceID: 0} + - feedBack: {instanceID: 0} + - scoreDisplay: {instanceID: 0} + - minigame: {instanceID: 0} + - songList: {fileID: 11400000, guid: 4f0ce70309bb901feb28199a82a7d195, type: 2} + - hitZone: {instanceID: 0} + - symbolPrefab: {instanceID: 0} + - symbolContainer: {instanceID: 0} executionOrder: 0 icon: {instanceID: 0} userData: diff --git a/Assets/JustSign/Scripts/Song.cs b/Assets/JustSign/Scripts/Song.cs new file mode 100644 index 0000000..3467bc7 --- /dev/null +++ b/Assets/JustSign/Scripts/Song.cs @@ -0,0 +1,29 @@ +using UnityEngine; +using UnityEngine.Audio; + +/// +/// Class for holding all (static) data about a certain song +/// +[CreateAssetMenu(menuName = "Create new Scriptable/Song")] +public class Song : ScriptableObject +{ + /// + /// Time at which the first symbol should enter the hit zone + /// + public float firstSymbolTime; + + /// + /// Determines every how many seconds a symbol should enter the hit zone + /// + public float spawnPeriod; + + /// + /// Duration of the song in seconds + /// + public int duration; + + /// + /// The actual audio source + /// + public AudioClip song; +} diff --git a/Assets/JustSign/Scripts/Song.cs.meta b/Assets/JustSign/Scripts/Song.cs.meta new file mode 100644 index 0000000..fa76e2e --- /dev/null +++ b/Assets/JustSign/Scripts/Song.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cd3d1c3a6cf7ef07abb343f8862a7435 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/JustSign/Scripts/SongList.cs b/Assets/JustSign/Scripts/SongList.cs new file mode 100644 index 0000000..43fdf91 --- /dev/null +++ b/Assets/JustSign/Scripts/SongList.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using UnityEngine; + +/// +/// Keep track of all songs +/// +[CreateAssetMenu(menuName = "Create new Scriptable/SongList")] +public class SongList : ScriptableObject +{ + /// + /// Index of the active/to be loaded/current song + /// + public int currentSongIndex = 0; + + /// + /// List of all installed songs + /// + public List songs = new List(); +} diff --git a/Assets/JustSign/Scripts/SongList.cs.meta b/Assets/JustSign/Scripts/SongList.cs.meta new file mode 100644 index 0000000..22fa1a6 --- /dev/null +++ b/Assets/JustSign/Scripts/SongList.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ceeae47a3efc2206299ddf1cc31043c2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/JustSign/Songs.meta b/Assets/JustSign/Songs.meta new file mode 100644 index 0000000..9ed9f01 --- /dev/null +++ b/Assets/JustSign/Songs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a92b9838d20352bb8b984c2e361c7fba +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/JustSign/Songs/graceland.mp3 b/Assets/JustSign/Songs/graceland.mp3 new file mode 100644 index 0000000..d9970ad Binary files /dev/null and b/Assets/JustSign/Songs/graceland.mp3 differ diff --git a/Assets/JustSign/Songs/graceland.mp3.meta b/Assets/JustSign/Songs/graceland.mp3.meta new file mode 100644 index 0000000..902507d --- /dev/null +++ b/Assets/JustSign/Songs/graceland.mp3.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: e01ded5e221494bdbaab8674c0354f64 +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/JustSign/Songs/sunny_safari_120bpm.mp3 b/Assets/JustSign/Songs/sunny_safari_120bpm.mp3 new file mode 100644 index 0000000..1e3be36 Binary files /dev/null and b/Assets/JustSign/Songs/sunny_safari_120bpm.mp3 differ diff --git a/Assets/JustSign/Songs/sunny_safari_120bpm.mp3.meta b/Assets/JustSign/Songs/sunny_safari_120bpm.mp3.meta new file mode 100644 index 0000000..ae6534f --- /dev/null +++ b/Assets/JustSign/Songs/sunny_safari_120bpm.mp3.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: d7ca1b558b7b064cdb6f9d6c951b1522 +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: