Resolve WES-89 "Justsign music"
This commit is contained in:
@@ -40,6 +40,16 @@ public class JustSignController : MonoBehaviour
|
||||
/// </summary>
|
||||
public Minigame minigame;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the list of available songs
|
||||
/// </summary>
|
||||
public SongList songList;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the currently used song
|
||||
/// </summary>
|
||||
private Song currentSong;
|
||||
|
||||
/// <summary>
|
||||
/// The zone that the player should be hitting with his or her inputs
|
||||
/// </summary>
|
||||
@@ -80,6 +90,11 @@ public class JustSignController : MonoBehaviour
|
||||
/// </summary>
|
||||
private int score;
|
||||
|
||||
/// <summary>
|
||||
/// Have the symbols started spawning or not
|
||||
/// </summary>
|
||||
private bool gameIsActive = false;
|
||||
|
||||
/// <summary>
|
||||
/// Width and height of the symbols
|
||||
/// </summary>
|
||||
@@ -146,9 +161,14 @@ public class JustSignController : MonoBehaviour
|
||||
private float lastSpawn;
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
private float spawnPeriod = 3.0f;
|
||||
private float beginTime;
|
||||
|
||||
/// <summary>
|
||||
/// Time at which the last symbol should spawn
|
||||
/// </summary>
|
||||
private float lastSymbolTime;
|
||||
|
||||
/// <summary>
|
||||
/// 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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wait for a given amount of time (specified in song) before spawning symbols
|
||||
/// </summary>
|
||||
IEnumerator WaitThenStart(float nrOfSeconds)
|
||||
{
|
||||
//yield on a new YieldInstruction that waits for nrOfSeconds seconds
|
||||
yield return new WaitForSeconds(nrOfSeconds);
|
||||
gameIsActive = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -169,56 +201,68 @@ public class JustSignController : MonoBehaviour
|
||||
/// </summary>
|
||||
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<RectTransform>().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<RectTransform>().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>();
|
||||
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>();
|
||||
rectTransform.localPosition = new Vector3(rectTransform.localPosition.x + Time.deltaTime * moveSpeed, trackY, 0);
|
||||
}
|
||||
|
||||
scoreDisplay.text = "Score: " + score.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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:
|
||||
|
||||
29
Assets/JustSign/Scripts/Song.cs
Normal file
29
Assets/JustSign/Scripts/Song.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
/// <summary>
|
||||
/// Class for holding all (static) data about a certain song
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/Song")]
|
||||
public class Song : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Time at which the first symbol should enter the hit zone
|
||||
/// </summary>
|
||||
public float firstSymbolTime;
|
||||
|
||||
/// <summary>
|
||||
/// Determines every how many seconds a symbol should enter the hit zone
|
||||
/// </summary>
|
||||
public float spawnPeriod;
|
||||
|
||||
/// <summary>
|
||||
/// Duration of the song in seconds
|
||||
/// </summary>
|
||||
public int duration;
|
||||
|
||||
/// <summary>
|
||||
/// The actual audio source
|
||||
/// </summary>
|
||||
public AudioClip song;
|
||||
}
|
||||
11
Assets/JustSign/Scripts/Song.cs.meta
Normal file
11
Assets/JustSign/Scripts/Song.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd3d1c3a6cf7ef07abb343f8862a7435
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/JustSign/Scripts/SongList.cs
Normal file
19
Assets/JustSign/Scripts/SongList.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Keep track of all songs
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/SongList")]
|
||||
public class SongList : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Index of the active/to be loaded/current song
|
||||
/// </summary>
|
||||
public int currentSongIndex = 0;
|
||||
|
||||
/// <summary>
|
||||
/// List of all installed songs
|
||||
/// </summary>
|
||||
public List<Song> songs = new List<Song>();
|
||||
}
|
||||
11
Assets/JustSign/Scripts/SongList.cs.meta
Normal file
11
Assets/JustSign/Scripts/SongList.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ceeae47a3efc2206299ddf1cc31043c2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user