Merge branch 'WES-132-Common-Abstract-Minigame' into 'development'
Resolve WES-132-Common-Abstract-Minigame See merge request wesign/unity-application!81
This commit was merged in pull request #81.
This commit is contained in:
@@ -513,10 +513,10 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
|
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
m_UiScaleMode: 0
|
m_UiScaleMode: 1
|
||||||
m_ReferencePixelsPerUnit: 100
|
m_ReferencePixelsPerUnit: 100
|
||||||
m_ScaleFactor: 1
|
m_ScaleFactor: 1
|
||||||
m_ReferenceResolution: {x: 800, y: 600}
|
m_ReferenceResolution: {x: 1920, y: 1080}
|
||||||
m_ScreenMatchMode: 0
|
m_ScreenMatchMode: 0
|
||||||
m_MatchWidthOrHeight: 0
|
m_MatchWidthOrHeight: 0
|
||||||
m_PhysicalUnit: 3
|
m_PhysicalUnit: 3
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ public class CourseActivityScreen : MonoBehaviour
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Image courseImage;
|
public Image courseImage;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Progress bar Display
|
/// Progress bar Display
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using DigitalRuby.Tween;
|
using DigitalRuby.Tween;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -170,10 +171,26 @@ public class CoursesController : AbstractFeedback
|
|||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
StartCourseController();
|
StartCourseController();
|
||||||
|
signPredictor.SetSignsList(GetSignsList());
|
||||||
signPredictor.SetModel(course.theme.modelIndex);
|
signPredictor.SetModel(course.theme.modelIndex);
|
||||||
AddSelfAsListener();
|
AddSelfAsListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fetches all the strings of the signs of the course
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The signsList that needs to be passed to the signPredictor</returns>
|
||||||
|
private List<string> GetSignsList()
|
||||||
|
{
|
||||||
|
List<string> signsList = new List<string>();
|
||||||
|
foreach (Learnable learnable in course.theme.learnables)
|
||||||
|
{
|
||||||
|
signsList.Add(learnable.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return signsList;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Holds the course-specific logic to start the controller, it is seperated to allow the course to be reset (if that would become needed)
|
/// Holds the course-specific logic to start the controller, it is seperated to allow the course to be reset (if that would become needed)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -410,6 +427,7 @@ public class CoursesController : AbstractFeedback
|
|||||||
float accPredictSign = signPredictor.learnableProbabilities[predictedSign];
|
float accPredictSign = signPredictor.learnableProbabilities[predictedSign];
|
||||||
Learnable predSign = course.theme.learnables.Find(l => l.name.ToUpper().Replace(" ", "-") == predictedSign);
|
Learnable predSign = course.theme.learnables.Find(l => l.name.ToUpper().Replace(" ", "-") == predictedSign);
|
||||||
|
|
||||||
|
// If there is a feedback-object, we wil change its appearance
|
||||||
if (feedbackText != null && feedbackProgressImage != null)
|
if (feedbackText != null && feedbackProgressImage != null)
|
||||||
{
|
{
|
||||||
Color col;
|
Color col;
|
||||||
@@ -439,6 +457,7 @@ public class CoursesController : AbstractFeedback
|
|||||||
feedbackText.color = col;
|
feedbackText.color = col;
|
||||||
feedbackProgressImage.color = col;
|
feedbackProgressImage.color = col;
|
||||||
|
|
||||||
|
// Tween the feedback-bar
|
||||||
float oldValue = feedbackProgress.value;
|
float oldValue = feedbackProgress.value;
|
||||||
// use an exponential scale
|
// use an exponential scale
|
||||||
float newValue = Mathf.Exp(4 * (Mathf.Clamp(accCurrentSign / sign.thresholdPercentage, 0.0f, 1.0f) - 1.0f));
|
float newValue = Mathf.Exp(4 * (Mathf.Clamp(accCurrentSign / sign.thresholdPercentage, 0.0f, 1.0f) - 1.0f));
|
||||||
@@ -451,6 +470,7 @@ public class CoursesController : AbstractFeedback
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The internal logic for the courses
|
||||||
if (accPredictSign > sign.thresholdPercentage)
|
if (accPredictSign > sign.thresholdPercentage)
|
||||||
{
|
{
|
||||||
// Correct sign
|
// Correct sign
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ RenderSettings:
|
|||||||
m_ReflectionIntensity: 1
|
m_ReflectionIntensity: 1
|
||||||
m_CustomReflection: {fileID: 0}
|
m_CustomReflection: {fileID: 0}
|
||||||
m_Sun: {fileID: 0}
|
m_Sun: {fileID: 0}
|
||||||
m_IndirectSpecularColor: {r: 0.37311953, g: 0.38074014, b: 0.3587274, a: 1}
|
m_IndirectSpecularColor: {r: 0.37311918, g: 0.3807398, b: 0.35872716, a: 1}
|
||||||
m_UseRadianceAmbientProbe: 0
|
m_UseRadianceAmbientProbe: 0
|
||||||
--- !u!157 &3
|
--- !u!157 &3
|
||||||
LightmapSettings:
|
LightmapSettings:
|
||||||
@@ -2241,7 +2241,9 @@ MonoBehaviour:
|
|||||||
m_text: 'Speler 1 geeft een woord in aan de hand van vingerspelling.
|
m_text: 'Speler 1 geeft een woord in aan de hand van vingerspelling.
|
||||||
|
|
||||||
Het woord
|
Het woord
|
||||||
moet tussen 3 en 17 letters zijn.'
|
moet tussen 3 en 17 letters zijn.
|
||||||
|
|
||||||
|
Je kan letters verwijderen met backspace.'
|
||||||
m_isRightToLeft: 0
|
m_isRightToLeft: 0
|
||||||
m_fontAsset: {fileID: 11400000, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
|
m_fontAsset: {fileID: 11400000, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
|
||||||
m_sharedMaterial: {fileID: -2577534979213189211, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
|
m_sharedMaterial: {fileID: -2577534979213189211, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
|
||||||
@@ -3276,7 +3278,7 @@ MonoBehaviour:
|
|||||||
m_OnCullStateChanged:
|
m_OnCullStateChanged:
|
||||||
m_PersistentCalls:
|
m_PersistentCalls:
|
||||||
m_Calls: []
|
m_Calls: []
|
||||||
m_text:
|
m_text: AZERTY
|
||||||
m_isRightToLeft: 0
|
m_isRightToLeft: 0
|
||||||
m_fontAsset: {fileID: 11400000, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
|
m_fontAsset: {fileID: 11400000, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
|
||||||
m_sharedMaterial: {fileID: -2577534979213189211, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
|
m_sharedMaterial: {fileID: -2577534979213189211, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
|
||||||
@@ -4540,6 +4542,8 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 3576f66af2a0eea42ae06ac73d9779e6, type: 3}
|
m_Script: {fileID: 11500000, guid: 3576f66af2a0eea42ae06ac73d9779e6, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
scoreboardEntriesContainer: {fileID: 2082181368}
|
||||||
|
scoreboardEntry: {fileID: 9154151134820372555, guid: d4a3a228b08d61847acc6da35b44e52c, type: 3}
|
||||||
endText: {fileID: 1205429732}
|
endText: {fileID: 1205429732}
|
||||||
lettersRightText: {fileID: 815411823}
|
lettersRightText: {fileID: 815411823}
|
||||||
lettersWrongText: {fileID: 1606437998}
|
lettersWrongText: {fileID: 1606437998}
|
||||||
@@ -4547,19 +4551,7 @@ MonoBehaviour:
|
|||||||
accuracyText: {fileID: 1341392955}
|
accuracyText: {fileID: 1341392955}
|
||||||
wordText: {fileID: 328407984}
|
wordText: {fileID: 328407984}
|
||||||
scoreText: {fileID: 941310846}
|
scoreText: {fileID: 941310846}
|
||||||
scoreboardEntriesContainer: {fileID: 2082181368}
|
|
||||||
scoreboardEntry: {fileID: 9154151134820372555, guid: d4a3a228b08d61847acc6da35b44e52c, type: 3}
|
|
||||||
image: {fileID: 1503788513}
|
image: {fileID: 1503788513}
|
||||||
sprites:
|
|
||||||
- {fileID: 21300000, guid: 46b9ec93c5782294f93be12a7c7bc3f0, type: 3}
|
|
||||||
- {fileID: 21300000, guid: 0a2c6671fa08a1249ba97ddd3432ac60, type: 3}
|
|
||||||
- {fileID: 21300000, guid: e5b621bb42e52654d88ad633777004a8, type: 3}
|
|
||||||
- {fileID: 21300000, guid: 42b25d40421cfce4684bad733747c2e3, type: 3}
|
|
||||||
- {fileID: 21300000, guid: 76120f6b7a0251949a56f73d49985d3a, type: 3}
|
|
||||||
- {fileID: 21300000, guid: c9b599bbbe306584a926c415d7e96983, type: 3}
|
|
||||||
- {fileID: 21300000, guid: 3fa072f7f8a26cf45b84781ce2dfdc51, type: 3}
|
|
||||||
- {fileID: 21300000, guid: 3f6826496e2a1334ab74ec68262b2c11, type: 3}
|
|
||||||
- {fileID: 21300000, guid: 98ec939c075818c4e869916da0b33aad, type: 3}
|
|
||||||
--- !u!1 &987091747
|
--- !u!1 &987091747
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -7675,6 +7667,10 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
signPredictor: {fileID: 1991376311}
|
signPredictor: {fileID: 1991376311}
|
||||||
|
minigamelist: {fileID: 11400000, guid: 51453f9b41bc72f468ba3e67ab622f8f, type: 2}
|
||||||
|
feedbackProgress: {fileID: 211555568}
|
||||||
|
webcamScreen: {fileID: 1966441454}
|
||||||
|
gameEndedPanel: {fileID: 974474713}
|
||||||
themeList: {fileID: 11400000, guid: a247e2ce790f0f746a3bc521e6ab7d58, type: 2}
|
themeList: {fileID: 11400000, guid: a247e2ce790f0f746a3bc521e6ab7d58, type: 2}
|
||||||
fingerSpelling: {fileID: 11400000, guid: e02921b294fdad940b6e4d57e716d3bf, type: 2}
|
fingerSpelling: {fileID: 11400000, guid: e02921b294fdad940b6e4d57e716d3bf, type: 2}
|
||||||
letterPrefab: {fileID: 4639383499500021565, guid: c3e66e8957864914cb022af914df6a28, type: 3}
|
letterPrefab: {fileID: 4639383499500021565, guid: c3e66e8957864914cb022af914df6a28, type: 3}
|
||||||
@@ -7696,15 +7692,10 @@ MonoBehaviour:
|
|||||||
inputPanel: {fileID: 640467091}
|
inputPanel: {fileID: 640467091}
|
||||||
scoreDisplay: {fileID: 2026578772}
|
scoreDisplay: {fileID: 2026578772}
|
||||||
scoreBonus: {fileID: 1537143412}
|
scoreBonus: {fileID: 1537143412}
|
||||||
gameEndedPanel: {fileID: 974474713}
|
|
||||||
minigame: {fileID: 11400000, guid: 165c1d9867275924d9720d409e935f95, type: 2}
|
|
||||||
minigamelist: {fileID: 11400000, guid: 51453f9b41bc72f468ba3e67ab622f8f, type: 2}
|
|
||||||
gotoGameButton: {fileID: 482979078}
|
gotoGameButton: {fileID: 482979078}
|
||||||
inputTextField: {fileID: 752351940}
|
inputTextField: {fileID: 752351940}
|
||||||
feedbackText: {fileID: 887237819}
|
feedbackText: {fileID: 887237819}
|
||||||
feedbackProgress: {fileID: 211555568}
|
|
||||||
feedbackProgressImage: {fileID: 1107240765}
|
feedbackProgressImage: {fileID: 1107240765}
|
||||||
webcamScreen: {fileID: 1966441454}
|
|
||||||
timerCircle: {fileID: 683997248}
|
timerCircle: {fileID: 683997248}
|
||||||
confirmPanel: {fileID: 1002919202}
|
confirmPanel: {fileID: 1002919202}
|
||||||
confirmText: {fileID: 1672600188}
|
confirmText: {fileID: 1672600188}
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
using DigitalRuby.Tween;
|
using DigitalRuby.Tween;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using Random = UnityEngine.Random;
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
public class HangmanController : AbstractFeedback
|
public class HangmanController : AbstractMinigameController
|
||||||
{
|
{
|
||||||
|
[Header("ConcreteVariables")]
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The scriptable with all the themes, will be used to select a random word for hangman.
|
/// The scriptable with all the themes, will be used to select a random word for hangman.
|
||||||
/// The spellingthemeList will be used for the words.
|
/// The spellingthemeList will be used for the words.
|
||||||
@@ -17,7 +16,7 @@ public class HangmanController : AbstractFeedback
|
|||||||
public ThemeList themeList;
|
public ThemeList themeList;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// reference to the fingerspelling-theme to reach the letter-thresholds
|
/// reference to the fingerspelling-theme to reach the letter-thresholds and to pass to the signPredictor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Theme fingerSpelling;
|
public Theme fingerSpelling;
|
||||||
|
|
||||||
@@ -96,11 +95,6 @@ public class HangmanController : AbstractFeedback
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TMP_Text scoreBonus;
|
public TMP_Text scoreBonus;
|
||||||
|
|
||||||
///// <summary>
|
|
||||||
///// This panel holds the panels for input and playing the game, sharing webcam and feedback
|
|
||||||
///// </summary>
|
|
||||||
//public GameObject inputGamePanel;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This int shows what mode we are in, used in update: <br></br>
|
/// This int shows what mode we are in, used in update: <br></br>
|
||||||
/// 0 : single or multiplayer?<br></br>
|
/// 0 : single or multiplayer?<br></br>
|
||||||
@@ -111,27 +105,6 @@ public class HangmanController : AbstractFeedback
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private int mode;
|
private int mode;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The game over panel
|
|
||||||
/// </summary>
|
|
||||||
public GameObject gameEndedPanel;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference to the minigame ScriptableObject
|
|
||||||
/// </summary>
|
|
||||||
public Minigame minigame;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// We keep the minigamelist as well so that the minigame-index doesn't get reset
|
|
||||||
/// DO NOT REMOVE
|
|
||||||
/// </summary>
|
|
||||||
public MinigameList minigamelist;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference to the current user
|
|
||||||
/// </summary>
|
|
||||||
private User user;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The button to go into the game
|
/// The button to go into the game
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -152,21 +125,11 @@ public class HangmanController : AbstractFeedback
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TMP_Text feedbackText;
|
public TMP_Text feedbackText;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference to the progress bar
|
|
||||||
/// </summary>
|
|
||||||
public Slider feedbackProgress;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reference to the progress bar image, so we can add fancy colors
|
/// Reference to the progress bar image, so we can add fancy colors
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Image feedbackProgressImage;
|
public Image feedbackProgressImage;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// reference to the webcam background
|
|
||||||
/// </summary>
|
|
||||||
public RawImage webcamScreen;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Previous incorrect sign, so we can keep track whether the user is wrong or the user is still changing signs
|
/// Previous incorrect sign, so we can keep track whether the user is wrong or the user is still changing signs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -239,48 +202,11 @@ public class HangmanController : AbstractFeedback
|
|||||||
private int winScore = 25;
|
private int winScore = 25;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Start is called before the first frame update
|
/// Set the AbstractMinigameController variable to inform it of the theme for the signPredictor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Start()
|
protected override Theme signPredictorTheme
|
||||||
{
|
{
|
||||||
signPredictor.SwapScreen(webcamScreen);
|
get { return fingerSpelling; }
|
||||||
signPredictor.SetModel(ModelIndex.FINGERSPELLING);
|
|
||||||
AddSelfAsListener();
|
|
||||||
|
|
||||||
StartController();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called at the start of the scene AND when the scene is replayed
|
|
||||||
/// </summary>
|
|
||||||
public void StartController()
|
|
||||||
{
|
|
||||||
// Make sure the mode starts at zero
|
|
||||||
mode = 0;
|
|
||||||
|
|
||||||
|
|
||||||
// Make sure that only the player-selection panel is the one shown
|
|
||||||
gamePanel.SetActive(false);
|
|
||||||
inputPanel.SetActive(false);
|
|
||||||
playerPanel.SetActive(true);
|
|
||||||
|
|
||||||
// Make sure that unneeded panels are inactive
|
|
||||||
gameEndedPanel.SetActive(false);
|
|
||||||
confirmPanel.SetActive(false);
|
|
||||||
|
|
||||||
// Create entry in current user for keeping track of progress
|
|
||||||
user = UserList.GetCurrentUser();
|
|
||||||
var progress = user.GetMinigameProgress(minigame.index);
|
|
||||||
if (progress == null)
|
|
||||||
{
|
|
||||||
progress = new PersistentDataController.SavedMinigameProgress();
|
|
||||||
progress.minigameIndex = minigame.index;
|
|
||||||
user.AddMinigameProgress(progress);
|
|
||||||
}
|
|
||||||
UserList.Save();
|
|
||||||
|
|
||||||
// Guesses needs to be created instantly because it is used in the FeedbackLoop
|
|
||||||
//guesses = new List<string>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -289,7 +215,7 @@ public class HangmanController : AbstractFeedback
|
|||||||
public void StartGame()
|
public void StartGame()
|
||||||
{
|
{
|
||||||
// Change the mode
|
// Change the mode
|
||||||
mode = 2;
|
SwitchMode(2);
|
||||||
|
|
||||||
// Activate the right panel
|
// Activate the right panel
|
||||||
gamePanel.SetActive(true);
|
gamePanel.SetActive(true);
|
||||||
@@ -334,11 +260,7 @@ public class HangmanController : AbstractFeedback
|
|||||||
public void GoToInput()
|
public void GoToInput()
|
||||||
{
|
{
|
||||||
// Change the mode
|
// Change the mode
|
||||||
mode = 1;
|
SwitchMode(1);
|
||||||
|
|
||||||
// Initialise the word to an empty String
|
|
||||||
currentWord = "";
|
|
||||||
inputTextField.text = currentWord.ToUpper();
|
|
||||||
|
|
||||||
// Activate the right panel
|
// Activate the right panel
|
||||||
gamePanel.SetActive(false);
|
gamePanel.SetActive(false);
|
||||||
@@ -346,7 +268,11 @@ public class HangmanController : AbstractFeedback
|
|||||||
inputPanel.SetActive(true);
|
inputPanel.SetActive(true);
|
||||||
playerPanel.SetActive(false);
|
playerPanel.SetActive(false);
|
||||||
|
|
||||||
|
// Initialise the word to an empty String
|
||||||
|
currentWord = "";
|
||||||
|
|
||||||
PanelMultiplayerInput script = inputPanel.GetComponent<PanelMultiplayerInput>();
|
PanelMultiplayerInput script = inputPanel.GetComponent<PanelMultiplayerInput>();
|
||||||
|
script.inputTextField.text = "";
|
||||||
|
|
||||||
gotoGameButton = script.gotoGameButton;
|
gotoGameButton = script.gotoGameButton;
|
||||||
inputTextField = script.inputTextField;
|
inputTextField = script.inputTextField;
|
||||||
@@ -470,7 +396,7 @@ public class HangmanController : AbstractFeedback
|
|||||||
{
|
{
|
||||||
confirmPanel.SetActive(true);
|
confirmPanel.SetActive(true);
|
||||||
confirmText.text = $"Letter '{currentSign.ToUpper()}' ?";
|
confirmText.text = $"Letter '{currentSign.ToUpper()}' ?";
|
||||||
mode = 4;
|
SwitchMode(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -478,7 +404,7 @@ public class HangmanController : AbstractFeedback
|
|||||||
case 2: // Sign your letter
|
case 2: // Sign your letter
|
||||||
if (!guesses.Contains(currentSign))
|
if (!guesses.Contains(currentSign))
|
||||||
{
|
{
|
||||||
mode = 3;
|
SwitchMode(3);
|
||||||
ConfirmAccept();
|
ConfirmAccept();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -517,24 +443,23 @@ public class HangmanController : AbstractFeedback
|
|||||||
usedLettersText.text += letter.ToString().ToUpper();
|
usedLettersText.text += letter.ToString().ToUpper();
|
||||||
|
|
||||||
// The current sign was accepted, return to the game
|
// The current sign was accepted, return to the game
|
||||||
mode = 2;
|
SwitchMode(2);
|
||||||
|
if (corrects == currentWord.Length)
|
||||||
if (corrects == currentWord.Replace(" ", "").Length)
|
|
||||||
{
|
{
|
||||||
// Victory, deactivate the model and show the scoreboard
|
// Victory, deactivate the model and show the scoreboard
|
||||||
ActivateWin();
|
ActivateEnd(true);
|
||||||
}
|
}
|
||||||
else if (NUMBER_OF_FAILS_BEFORE_GAMEOVER < wrongs)
|
else if (NUMBER_OF_FAILS_BEFORE_GAMEOVER < wrongs)
|
||||||
{
|
{
|
||||||
// You lost, deactivate the model and show the scoreboard
|
// You lost, deactivate the model and show the scoreboard
|
||||||
ActivateGameOver();
|
ActivateEnd(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mode == 4)
|
else if (mode == 4)
|
||||||
{
|
{
|
||||||
currentWord += letter;
|
currentWord += letter;
|
||||||
inputTextField.text = currentWord.ToUpper();
|
inputTextField.text = currentWord.ToUpper();
|
||||||
mode = 1;
|
SwitchMode(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -544,9 +469,23 @@ public class HangmanController : AbstractFeedback
|
|||||||
|
|
||||||
// The current sign was rejected, return to the game-mode
|
// The current sign was rejected, return to the game-mode
|
||||||
if (mode == 3)
|
if (mode == 3)
|
||||||
mode = 2;
|
SwitchMode(2);
|
||||||
else if (mode == 4)
|
else if (mode == 4)
|
||||||
mode = 1;
|
SwitchMode(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SwitchMode(int mode)
|
||||||
|
{
|
||||||
|
this.mode = mode;
|
||||||
|
// In mode 1 and 2, the signPredictor needs to run, otherwise it does not
|
||||||
|
if (mode == 1 || mode == 2)
|
||||||
|
{
|
||||||
|
gameIsActive = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gameIsActive = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -599,7 +538,7 @@ public class HangmanController : AbstractFeedback
|
|||||||
/// This function returns the score that the user currently has
|
/// This function returns the score that the user currently has
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The current score of the user</returns>
|
/// <returns>The current score of the user</returns>
|
||||||
private int CalculateScore()
|
public override int CalculateScore()
|
||||||
{
|
{
|
||||||
int won = corrects == currentWord.Length ? 1 : 0;
|
int won = corrects == currentWord.Length ? 1 : 0;
|
||||||
return corrects * correctLetterScore + wrongs * incorrectLetterScore + winScore * won;
|
return corrects * correctLetterScore + wrongs * incorrectLetterScore + winScore * won;
|
||||||
@@ -640,115 +579,19 @@ public class HangmanController : AbstractFeedback
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update and save the scores
|
/// The logic to process the signs sent by the signPredictor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void SaveScores()
|
/// <param name="accuracy">The accuracy of the passed sign</param>
|
||||||
|
/// <param name="predictedSign">The name of the passed sign</param>
|
||||||
|
protected override void ProcessMostProbableSign(float accuracy, string predictedSign)
|
||||||
{
|
{
|
||||||
// Calculate new score
|
|
||||||
int newScore = CalculateScore();
|
|
||||||
// Save the score as a tuple: < int score, string time ago>
|
|
||||||
Score score = new Score();
|
|
||||||
score.scoreValue = newScore;
|
|
||||||
score.time = DateTime.Now.ToString();
|
|
||||||
|
|
||||||
// Save the new score
|
|
||||||
var progress = user.GetMinigameProgress(minigame.index);
|
|
||||||
|
|
||||||
// Get the current list of scores
|
|
||||||
List<Score> latestScores = progress.latestScores;
|
|
||||||
List<Score> highestScores = progress.highestScores;
|
|
||||||
|
|
||||||
// Add the new score
|
|
||||||
latestScores.Add(score);
|
|
||||||
highestScores.Add(score);
|
|
||||||
|
|
||||||
// Sort the scores
|
|
||||||
highestScores.Sort((a, b) => b.scoreValue.CompareTo(a.scoreValue));
|
|
||||||
|
|
||||||
// Only save the top 10 scores, so this list doesn't keep growing endlessly
|
|
||||||
progress.latestScores = latestScores.Take(10).ToList();
|
|
||||||
progress.highestScores = highestScores.Take(10).ToList();
|
|
||||||
|
|
||||||
UserList.Save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Display win screen
|
|
||||||
/// </summary>
|
|
||||||
private void ActivateWin()
|
|
||||||
{
|
|
||||||
// Deactivate the model
|
|
||||||
mode = 0;
|
|
||||||
|
|
||||||
// Save the scores and show the scoreboard
|
|
||||||
SaveScores();
|
|
||||||
gameEndedPanel.GetComponent<HangmanGameEndedPanel>().GenerateContent(
|
|
||||||
guessWord: currentWord.ToLower(),
|
|
||||||
correctLetters: corrects,
|
|
||||||
incorrectLetters: wrongs,
|
|
||||||
sprite: hangmanImage.sprite,
|
|
||||||
result: "GEWONNEN",
|
|
||||||
score: CalculateScore()
|
|
||||||
);
|
|
||||||
|
|
||||||
gameEndedPanel.SetActive(true);
|
|
||||||
|
|
||||||
// @lukas stuff
|
|
||||||
DeleteWord();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Displays the game over panel and score values
|
|
||||||
/// </summary>
|
|
||||||
private void ActivateGameOver()
|
|
||||||
{
|
|
||||||
// Deactivate the model
|
|
||||||
mode = 0;
|
|
||||||
|
|
||||||
// Save the scores and show the scoreboard
|
|
||||||
SaveScores();
|
|
||||||
gameEndedPanel.GetComponent<HangmanGameEndedPanel>().GenerateContent(
|
|
||||||
guessWord: currentWord.ToLower(),
|
|
||||||
correctLetters: corrects,
|
|
||||||
incorrectLetters: wrongs,
|
|
||||||
sprite: hangmanImage.sprite,
|
|
||||||
result: "VERLOREN",
|
|
||||||
score: CalculateScore()
|
|
||||||
);
|
|
||||||
|
|
||||||
gameEndedPanel.SetActive(true);
|
|
||||||
|
|
||||||
DeleteWord();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The updateFunction that is called when new probabilities become available
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
protected override IEnumerator UpdateFeedback()
|
|
||||||
{
|
|
||||||
// Get the sign with the highest prediction
|
|
||||||
if ((mode == 1 || mode == 2) &&
|
|
||||||
signPredictor != null &&
|
|
||||||
signPredictor.learnableProbabilities != null)
|
|
||||||
{
|
|
||||||
KeyValuePair<string, float> highestPrediction = signPredictor.learnableProbabilities.Aggregate((x, y) => x.Value > y.Value ? x : y);
|
|
||||||
float accuracy = highestPrediction.Value;
|
|
||||||
string predictedSign = highestPrediction.Key;
|
|
||||||
|
|
||||||
// vvv TEMPORARY STUFF vvv
|
|
||||||
if (predictedSign == "J" && accuracy <= 0.965f)
|
|
||||||
{
|
|
||||||
highestPrediction = signPredictor.learnableProbabilities.Aggregate((x, y) => x.Value > y.Value && x.Key != "J" ? x : y);
|
|
||||||
}
|
|
||||||
accuracy = highestPrediction.Value;
|
|
||||||
predictedSign = highestPrediction.Key;
|
|
||||||
// ^^^ TEMPORARY STUFF ^^^
|
|
||||||
|
|
||||||
// Grab the threshold for the most probable letter
|
// Grab the threshold for the most probable letter
|
||||||
Learnable letter = fingerSpelling.learnables.Find((l) => l.name == predictedSign);
|
Learnable letter = fingerSpelling.learnables.Find((l) => l.name == predictedSign);
|
||||||
float threshold = letter.thresholdPercentage;
|
float threshold = letter.thresholdPercentage;
|
||||||
|
|
||||||
|
// If there is a feedback-object, we wil change its appearance
|
||||||
|
if (feedbackText != null && feedbackProgressImage != null)
|
||||||
|
{
|
||||||
float oldValue = feedbackProgress.value;
|
float oldValue = feedbackProgress.value;
|
||||||
// use an exponential scale
|
// use an exponential scale
|
||||||
float newValue = Mathf.Exp(4 * (Mathf.Clamp(accuracy / threshold, 0.0f, 1.0f) - 1.0f));
|
float newValue = Mathf.Exp(4 * (Mathf.Clamp(accuracy / threshold, 0.0f, 1.0f) - 1.0f));
|
||||||
@@ -781,14 +624,19 @@ public class HangmanController : AbstractFeedback
|
|||||||
feedbackText.color = red;
|
feedbackText.color = red;
|
||||||
feedbackProgressImage.color = red;
|
feedbackProgressImage.color = red;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The logic for the internal workings of the game
|
||||||
if (accuracy > threshold)
|
if (accuracy > threshold)
|
||||||
{
|
{
|
||||||
|
// A different sign was predicted compared to the last call of this function
|
||||||
if (previousSign != predictedSign)
|
if (previousSign != predictedSign)
|
||||||
{
|
{
|
||||||
// Reset the timer
|
// Reset the timer
|
||||||
previousSign = predictedSign;
|
previousSign = predictedSign;
|
||||||
currentTime = 0;
|
currentTime = 0;
|
||||||
|
// If you are entering a word the timer needs to work
|
||||||
|
// If you are playing the game and haven't guessed the letter yet, then the timer needs to work
|
||||||
if ((mode == 1) ||
|
if ((mode == 1) ||
|
||||||
(mode == 2 && !guesses.Contains(previousSign.ToUpper())))
|
(mode == 2 && !guesses.Contains(previousSign.ToUpper())))
|
||||||
{
|
{
|
||||||
@@ -796,6 +644,7 @@ public class HangmanController : AbstractFeedback
|
|||||||
}
|
}
|
||||||
timerCircle.fillAmount = currentTime;
|
timerCircle.fillAmount = currentTime;
|
||||||
}
|
}
|
||||||
|
// The same sign was predicted as last time and said sign has been held for a sufficiently long time
|
||||||
else if (currentTime == maxTime)
|
else if (currentTime == maxTime)
|
||||||
{
|
{
|
||||||
// Set the predictedSign as your guess and update the Hangman
|
// Set the predictedSign as your guess and update the Hangman
|
||||||
@@ -817,13 +666,61 @@ public class HangmanController : AbstractFeedback
|
|||||||
runTime = false;
|
runTime = false;
|
||||||
timerCircle.fillAmount = currentTime;
|
timerCircle.fillAmount = currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (feedbackProgress != null)
|
|
||||||
|
/// <summary>
|
||||||
|
/// The logic to set the scoreboard of hangman
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="victory">SHows whether or not the player won</param>
|
||||||
|
protected override void SetScoreBoard(bool victory)
|
||||||
{
|
{
|
||||||
|
string resultTxt;
|
||||||
feedbackProgress.value = 0.0f;
|
if (victory)
|
||||||
|
{
|
||||||
|
resultTxt = "GEWONNEN";
|
||||||
}
|
}
|
||||||
yield return null;
|
else
|
||||||
|
{
|
||||||
|
resultTxt = "VERLOREN";
|
||||||
|
}
|
||||||
|
gameEndedPanel.GetComponent<HangmanGameEndedPanel>().GenerateContent(
|
||||||
|
guessWord: currentWord.ToLower(),
|
||||||
|
correctLetters: corrects,
|
||||||
|
incorrectLetters: wrongs,
|
||||||
|
sprite: hangmanImage.sprite,
|
||||||
|
result: resultTxt,
|
||||||
|
score: CalculateScore()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The hangman-specific logic that needs to be called at the start of the game
|
||||||
|
/// </summary>
|
||||||
|
protected override void StartGameLogic()
|
||||||
|
{
|
||||||
|
// Make sure the mode starts at zero
|
||||||
|
SwitchMode(0);
|
||||||
|
|
||||||
|
|
||||||
|
// Make sure that only the player-selection panel is the one shown
|
||||||
|
gamePanel.SetActive(false);
|
||||||
|
inputPanel.SetActive(false);
|
||||||
|
playerPanel.SetActive(true);
|
||||||
|
|
||||||
|
// Make sure that unneeded panels are inactive
|
||||||
|
gameEndedPanel.SetActive(false);
|
||||||
|
confirmPanel.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Hangman-specific logic that needs to be called at the end of a game
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="victory"></param>
|
||||||
|
protected override void EndGameLogic(bool victory)
|
||||||
|
{
|
||||||
|
// Deactivate the model
|
||||||
|
SwitchMode(0);
|
||||||
|
|
||||||
|
DeleteWord();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,16 @@ using UnityEngine.UI;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The hangman-variant of the ScoreBoard
|
/// The hangman-variant of the ScoreBoard
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class HangmanGameEndedPanel : MonoBehaviour
|
public class HangmanGameEndedPanel : AbstractGameEndedPanel
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Tell the scoreboard that the scoreboard is for HangMan
|
||||||
|
/// </summary>
|
||||||
|
protected override MinigameIndex minigameIndex
|
||||||
|
{
|
||||||
|
get { return MinigameIndex.HANGMAN; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// "VERLOREN" or "GEWONNEN"
|
/// "VERLOREN" or "GEWONNEN"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -40,28 +48,11 @@ public class HangmanGameEndedPanel : MonoBehaviour
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TMP_Text scoreText;
|
public TMP_Text scoreText;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference to the scoreboard entries container
|
|
||||||
/// </summary>
|
|
||||||
public Transform scoreboardEntriesContainer;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The GameObjects representing the letters
|
|
||||||
/// </summary>
|
|
||||||
private List<GameObject> scoreboardEntries = new List<GameObject>();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference to the ScoreboardEntry prefab
|
|
||||||
/// </summary>
|
|
||||||
public GameObject scoreboardEntry;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reference to the end result image
|
/// Reference to the end result image
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Image image;
|
public Image image;
|
||||||
|
|
||||||
public List<Sprite> sprites;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate the content of the GameEnded panel
|
/// Generate the content of the GameEnded panel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -99,105 +90,4 @@ public class HangmanGameEndedPanel : MonoBehaviour
|
|||||||
scoreText.text = $"Score: {score}";
|
scoreText.text = $"Score: {score}";
|
||||||
SetScoreBoard();
|
SetScoreBoard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets the scoreboard
|
|
||||||
/// </summary>
|
|
||||||
private void SetScoreBoard()
|
|
||||||
{
|
|
||||||
// Clean the previous scoreboard entries
|
|
||||||
for (int i = 0; i < scoreboardEntries.Count; i++)
|
|
||||||
{
|
|
||||||
Destroy(scoreboardEntries[i]);
|
|
||||||
}
|
|
||||||
scoreboardEntries.Clear();
|
|
||||||
|
|
||||||
// Instantiate new entries
|
|
||||||
// Get all scores from all users
|
|
||||||
List<Tuple<string, Score>> allScores = new List<Tuple<string, Score>>();
|
|
||||||
foreach (User user in UserList.GetUsers())
|
|
||||||
{
|
|
||||||
// Get user's progress for this minigame
|
|
||||||
var progress = user.GetMinigameProgress(MinigameIndex.HANGMAN);
|
|
||||||
if (progress != null)
|
|
||||||
{
|
|
||||||
// Add scores to dictionary
|
|
||||||
List<Score> scores = progress.highestScores;
|
|
||||||
foreach (Score score in scores)
|
|
||||||
{
|
|
||||||
allScores.Add(new Tuple<string, Score>(user.GetUsername(), score));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort allScores based on Score.scoreValue
|
|
||||||
allScores.Sort((a, b) => b.Item2.scoreValue.CompareTo(a.Item2.scoreValue));
|
|
||||||
|
|
||||||
// Instantiate scoreboard entries
|
|
||||||
int rank = 1;
|
|
||||||
foreach (Tuple<string, Score> tup in allScores.Take(10))
|
|
||||||
{
|
|
||||||
string username = tup.Item1;
|
|
||||||
Score score = tup.Item2;
|
|
||||||
|
|
||||||
GameObject entry = Instantiate(scoreboardEntry, scoreboardEntriesContainer);
|
|
||||||
scoreboardEntries.Add(entry);
|
|
||||||
|
|
||||||
// Set the player icon
|
|
||||||
entry.transform.Find("Image").GetComponent<Image>().sprite = UserList.GetUserByUsername(username).GetAvatar();
|
|
||||||
|
|
||||||
// Set the player name
|
|
||||||
entry.transform.Find("PlayerName").GetComponent<TMP_Text>().text = username;
|
|
||||||
|
|
||||||
// Set the score
|
|
||||||
entry.transform.Find("Score").GetComponent<TMP_Text>().text = score.scoreValue.ToString();
|
|
||||||
|
|
||||||
// Set the rank
|
|
||||||
entry.transform.Find("Rank").GetComponent<TMP_Text>().text = rank.ToString();
|
|
||||||
|
|
||||||
// Set the ago
|
|
||||||
// Convert the score.time to Datetime
|
|
||||||
DateTime time = DateTime.Parse(score.time);
|
|
||||||
DateTime currentTime = DateTime.Now;
|
|
||||||
TimeSpan diff = currentTime.Subtract(time);
|
|
||||||
|
|
||||||
string formatted;
|
|
||||||
if (diff.Days > 0)
|
|
||||||
{
|
|
||||||
formatted = $"{diff.Days}d ";
|
|
||||||
}
|
|
||||||
else if (diff.Hours > 0)
|
|
||||||
{
|
|
||||||
formatted = $"{diff.Hours}h ";
|
|
||||||
}
|
|
||||||
else if (diff.Minutes > 0)
|
|
||||||
{
|
|
||||||
formatted = $"{diff.Minutes}m ";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
formatted = "now";
|
|
||||||
}
|
|
||||||
|
|
||||||
entry.transform.Find("Ago").GetComponent<TMP_Text>().text = formatted;
|
|
||||||
|
|
||||||
|
|
||||||
// Alternating colors looks nice
|
|
||||||
if (rank % 2 == 0)
|
|
||||||
{
|
|
||||||
Image image = entry.transform.GetComponent<Image>();
|
|
||||||
image.color = new Color(image.color.r, image.color.g, image.color.b, 0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make new score stand out
|
|
||||||
if (diff.TotalSeconds < 1)
|
|
||||||
{
|
|
||||||
Image image = entry.transform.GetComponent<Image>();
|
|
||||||
image.color = new Color(0, 229, 255, 233);
|
|
||||||
}
|
|
||||||
|
|
||||||
rank++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,10 @@
|
|||||||
"GUID:e83ddf9a537a96b4a804a16bb7872ec1",
|
"GUID:e83ddf9a537a96b4a804a16bb7872ec1",
|
||||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||||
"GUID:1631ed2680c61245b8211d943c1639a8",
|
"GUID:1631ed2680c61245b8211d943c1639a8",
|
||||||
"GUID:d0b6b39a21908f94fbbd9f2c196a9725",
|
|
||||||
"GUID:58e104b97fb3752438ada2902a36dcbf",
|
"GUID:58e104b97fb3752438ada2902a36dcbf",
|
||||||
"GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25"
|
"GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25",
|
||||||
|
"GUID:403dd94a93598934eb522dc36df43d7b",
|
||||||
|
"GUID:d0b6b39a21908f94fbbd9f2c196a9725"
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
|
|||||||
@@ -1557,20 +1557,19 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
signPredictor: {fileID: 1150323775}
|
signPredictor: {fileID: 1150323775}
|
||||||
|
minigamelist: {fileID: 11400000, guid: 51453f9b41bc72f468ba3e67ab622f8f, type: 2}
|
||||||
|
feedbackProgress: {fileID: 1753834854}
|
||||||
|
webcamScreen: {fileID: 496523654}
|
||||||
|
gameEndedPanel: {fileID: 2498222378566216023}
|
||||||
answerField: {fileID: 0}
|
answerField: {fileID: 0}
|
||||||
timingFeedback: {fileID: 128049076}
|
timingFeedback: {fileID: 128049076}
|
||||||
scoreDisplay: {fileID: 1627575593}
|
scoreDisplay: {fileID: 1627575593}
|
||||||
minigame: {fileID: 11400000, guid: e726e0b93ea88465db7ee27605deb83f, type: 2}
|
|
||||||
minigamelist: {fileID: 11400000, guid: 51453f9b41bc72f468ba3e67ab622f8f, type: 2}
|
|
||||||
songList: {fileID: 11400000, guid: 4f0ce70309bb901feb28199a82a7d195, type: 2}
|
songList: {fileID: 11400000, guid: 4f0ce70309bb901feb28199a82a7d195, type: 2}
|
||||||
hitZonePerfect: {fileID: 2012531008}
|
hitZonePerfect: {fileID: 2012531008}
|
||||||
hitZoneGood: {fileID: 369868393}
|
hitZoneGood: {fileID: 369868393}
|
||||||
hitZoneMeh: {fileID: 141066497}
|
hitZoneMeh: {fileID: 141066497}
|
||||||
webcamScreen: {fileID: 496523654}
|
|
||||||
symbolPrefab: {fileID: 4639383499500021565, guid: f3117b0203a1342a48a95904347b03c8, type: 3}
|
symbolPrefab: {fileID: 4639383499500021565, guid: f3117b0203a1342a48a95904347b03c8, type: 3}
|
||||||
symbolContainer: {fileID: 2093721209}
|
symbolContainer: {fileID: 2093721209}
|
||||||
scoreboardEntriesContainer: {fileID: 2498222377153197597}
|
|
||||||
scoreboardEntry: {fileID: 9154151134820372555, guid: d4a3a228b08d61847acc6da35b44e52c, type: 3}
|
|
||||||
lpmText: {fileID: 2498222377094258231}
|
lpmText: {fileID: 2498222377094258231}
|
||||||
perfectSignsText: {fileID: 2498222378642934129}
|
perfectSignsText: {fileID: 2498222378642934129}
|
||||||
goodSignsText: {fileID: 524776817}
|
goodSignsText: {fileID: 524776817}
|
||||||
@@ -1578,9 +1577,7 @@ MonoBehaviour:
|
|||||||
terribleSignsText: {fileID: 1343527143}
|
terribleSignsText: {fileID: 1343527143}
|
||||||
notFoundSignsText: {fileID: 850357042}
|
notFoundSignsText: {fileID: 850357042}
|
||||||
scoreText: {fileID: 2498222378754007924}
|
scoreText: {fileID: 2498222378754007924}
|
||||||
gameEndedPanel: {fileID: 2498222378566216023}
|
|
||||||
feedbackText: {fileID: 1753834853}
|
feedbackText: {fileID: 1753834853}
|
||||||
feedbackProgressBar: {fileID: 1753834854}
|
|
||||||
feedbackProgressImage: {fileID: 1753834852}
|
feedbackProgressImage: {fileID: 1753834852}
|
||||||
perfectSprite: {fileID: 21300000, guid: 43b0de2d8fcec1540bb9989e45db4581, type: 3}
|
perfectSprite: {fileID: 21300000, guid: 43b0de2d8fcec1540bb9989e45db4581, type: 3}
|
||||||
goodSprite: {fileID: 21300000, guid: 168acd43cf46d1c419991a2620485bf6, type: 3}
|
goodSprite: {fileID: 21300000, guid: 168acd43cf46d1c419991a2620485bf6, type: 3}
|
||||||
@@ -1857,7 +1854,7 @@ MonoBehaviour:
|
|||||||
modelInfoFile: {fileID: 4900000, guid: fb8b51022bdcd654a9f29c054832a1b5, type: 3}
|
modelInfoFile: {fileID: 4900000, guid: fb8b51022bdcd654a9f29c054832a1b5, type: 3}
|
||||||
modelInfoFileEmbedding: {fileID: 4900000, guid: 4e303164823194bc4be87f4c9550cfd0, type: 3}
|
modelInfoFileEmbedding: {fileID: 4900000, guid: 4e303164823194bc4be87f4c9550cfd0, type: 3}
|
||||||
configAsset: {fileID: 4900000, guid: 6288c43cdca97374782dac1ea87aa029, type: 3}
|
configAsset: {fileID: 4900000, guid: 6288c43cdca97374782dac1ea87aa029, type: 3}
|
||||||
screen: {fileID: 0}
|
screen: {fileID: 496523654}
|
||||||
--- !u!4 &1150323776
|
--- !u!4 &1150323776
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -3524,7 +3521,7 @@ GameObject:
|
|||||||
- component: {fileID: 2498222377094258230}
|
- component: {fileID: 2498222377094258230}
|
||||||
- component: {fileID: 2498222377094258231}
|
- component: {fileID: 2498222377094258231}
|
||||||
m_Layer: 5
|
m_Layer: 5
|
||||||
m_Name: LPM
|
m_Name: GPM
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
@@ -3578,7 +3575,7 @@ MonoBehaviour:
|
|||||||
m_OnCullStateChanged:
|
m_OnCullStateChanged:
|
||||||
m_PersistentCalls:
|
m_PersistentCalls:
|
||||||
m_Calls: []
|
m_Calls: []
|
||||||
m_text: XXX LPM
|
m_text: XXX GPM
|
||||||
m_isRightToLeft: 0
|
m_isRightToLeft: 0
|
||||||
m_fontAsset: {fileID: 11400000, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
|
m_fontAsset: {fileID: 11400000, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
|
||||||
m_sharedMaterial: {fileID: -2577534979213189211, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
|
m_sharedMaterial: {fileID: -2577534979213189211, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
|
||||||
@@ -4700,29 +4697,6 @@ CanvasRenderer:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 2498222378566216023}
|
m_GameObject: {fileID: 2498222378566216023}
|
||||||
m_CullTransparentMesh: 1
|
m_CullTransparentMesh: 1
|
||||||
--- !u!114 &2498222378566215979
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 2498222378566216023}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 5aa929dce1f59b340b4a0cca1bb68edc, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
endText: {fileID: 2498222377166680336}
|
|
||||||
lpmText: {fileID: 2498222377094258231}
|
|
||||||
lettersRightText: {fileID: 0}
|
|
||||||
lettersWrongText: {fileID: 0}
|
|
||||||
lettersTotalText: {fileID: 0}
|
|
||||||
accuracyText: {fileID: 2498222378642934129}
|
|
||||||
wordsText: {fileID: 0}
|
|
||||||
timeText: {fileID: 0}
|
|
||||||
scoreText: {fileID: 2498222378754007924}
|
|
||||||
scoreboardEntriesContainer: {fileID: 2498222377153197597}
|
|
||||||
scoreboardEntry: {fileID: 9154151134820372555, guid: d4a3a228b08d61847acc6da35b44e52c, type: 3}
|
|
||||||
--- !u!224 &2498222378566216020
|
--- !u!224 &2498222378566216020
|
||||||
RectTransform:
|
RectTransform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -4788,7 +4762,7 @@ GameObject:
|
|||||||
- component: {fileID: 2498222378566216020}
|
- component: {fileID: 2498222378566216020}
|
||||||
- component: {fileID: 2498222378566215978}
|
- component: {fileID: 2498222378566215978}
|
||||||
- component: {fileID: 2498222378566216021}
|
- component: {fileID: 2498222378566216021}
|
||||||
- component: {fileID: 2498222378566215979}
|
- component: {fileID: 2498222378566216024}
|
||||||
m_Layer: 5
|
m_Layer: 5
|
||||||
m_Name: GameEnded Panel
|
m_Name: GameEnded Panel
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@@ -4796,6 +4770,27 @@ GameObject:
|
|||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
m_StaticEditorFlags: 0
|
m_StaticEditorFlags: 0
|
||||||
m_IsActive: 0
|
m_IsActive: 0
|
||||||
|
--- !u!114 &2498222378566216024
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2498222378566216023}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 9a86c239be1aa1543ba8a4ace5f658b1, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
scoreboardEntriesContainer: {fileID: 2498222377153197597}
|
||||||
|
scoreboardEntry: {fileID: 9154151134820372555, guid: d4a3a228b08d61847acc6da35b44e52c, type: 3}
|
||||||
|
perfectSignsText: {fileID: 2498222378642934129}
|
||||||
|
goodSignsText: {fileID: 524776817}
|
||||||
|
mehSignsText: {fileID: 6218584}
|
||||||
|
terribleSignsText: {fileID: 1343527143}
|
||||||
|
notFoundSignsText: {fileID: 850357042}
|
||||||
|
gpmText: {fileID: 2498222377094258231}
|
||||||
|
scoreText: {fileID: 2498222378754007924}
|
||||||
--- !u!1 &2498222378611643141
|
--- !u!1 &2498222378611643141
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
using DigitalRuby.Tween;
|
using DigitalRuby.Tween;
|
||||||
using System;
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
@@ -11,7 +9,7 @@ using Random = UnityEngine.Random;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains all game logic for the JustSign game
|
/// Contains all game logic for the JustSign game
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class JustSignController : AbstractFeedback
|
public class JustSignController : AbstractMinigameController
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All of the words that can be used in this session
|
/// All of the words that can be used in this session
|
||||||
@@ -33,17 +31,6 @@ public class JustSignController : AbstractFeedback
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TMP_Text scoreDisplay;
|
public TMP_Text scoreDisplay;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference to the minigame ScriptableObject
|
|
||||||
/// </summary>
|
|
||||||
public Minigame minigame;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// We keep the minigamelist as well so that the minigame-index doesn't get reset
|
|
||||||
/// DO NOT REMOVE
|
|
||||||
/// </summary>
|
|
||||||
public MinigameList minigamelist;
|
|
||||||
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// Reference to the list of available songs
|
/// Reference to the list of available songs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -69,11 +56,6 @@ public class JustSignController : AbstractFeedback
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public RectTransform hitZoneMeh;
|
public RectTransform hitZoneMeh;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference to the webcam
|
|
||||||
/// </summary>
|
|
||||||
public RawImage webcamScreen;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Score obtained when getting a perfect hit
|
/// Score obtained when getting a perfect hit
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -124,11 +106,6 @@ public class JustSignController : AbstractFeedback
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private List<GameObject> activeSymbols = new List<GameObject>();
|
private List<GameObject> activeSymbols = new List<GameObject>();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Have the symbols started spawning or not
|
|
||||||
/// </summary>
|
|
||||||
private bool gameIsActive = false;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Controls movement speed of symbols (higher -> faster)
|
/// Controls movement speed of symbols (higher -> faster)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -184,26 +161,6 @@ public class JustSignController : AbstractFeedback
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private int incorrectSigns;
|
private int incorrectSigns;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference to the scoreboard entries container
|
|
||||||
/// </summary>
|
|
||||||
public Transform scoreboardEntriesContainer;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The GameObjects representing the letters
|
|
||||||
/// </summary>
|
|
||||||
private List<GameObject> scoreboardEntries = new List<GameObject>();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference to the ScoreboardEntry prefab
|
|
||||||
/// </summary>
|
|
||||||
public GameObject scoreboardEntry;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference to the current user
|
|
||||||
/// </summary>
|
|
||||||
private User user;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// LPM
|
/// LPM
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -239,21 +196,11 @@ public class JustSignController : AbstractFeedback
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TMP_Text scoreText;
|
public TMP_Text scoreText;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference to the gameEnded panel, so we can update its display
|
|
||||||
/// </summary>
|
|
||||||
public GameObject gameEndedPanel;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reference to the feedback field
|
/// Reference to the feedback field
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TMP_Text feedbackText;
|
public TMP_Text feedbackText;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference to the progress bar
|
|
||||||
/// </summary>
|
|
||||||
public Slider feedbackProgressBar;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reference to the progress bar image, so we can add fancy colors
|
/// Reference to the progress bar image, so we can add fancy colors
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -299,53 +246,9 @@ public class JustSignController : AbstractFeedback
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public GameObject userFeedback;
|
public GameObject userFeedback;
|
||||||
|
|
||||||
/// <summary>
|
protected override Theme signPredictorTheme
|
||||||
/// Start is called before the first frame update
|
|
||||||
/// </summary>
|
|
||||||
public void Start()
|
|
||||||
{
|
{
|
||||||
currentTheme = minigame.themeList.themes[minigame.themeList.currentThemeIndex];
|
get { return currentTheme; }
|
||||||
signPredictor.SetModel(currentTheme.modelIndex);
|
|
||||||
signPredictor.SwapScreen(webcamScreen);
|
|
||||||
AddSelfAsListener();
|
|
||||||
|
|
||||||
StartController();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Holds the game-specific logic to start the controller
|
|
||||||
/// </summary>
|
|
||||||
public void StartController()
|
|
||||||
{
|
|
||||||
userFeedback.SetActive(currentTheme.modelIndex != ModelIndex.NONE);
|
|
||||||
previewMessage.SetActive(currentTheme.modelIndex == ModelIndex.NONE);
|
|
||||||
perfectSigns = 0;
|
|
||||||
goodSigns = 0;
|
|
||||||
mehSigns = 0;
|
|
||||||
terribleSigns = 0;
|
|
||||||
incorrectSigns = 0;
|
|
||||||
timingFeedback.text = "";
|
|
||||||
imageFeedback.sprite = minigame.thumbnail;
|
|
||||||
gameEndedPanel.SetActive(false);
|
|
||||||
// Create entry in current user for keeping track of progress
|
|
||||||
user = UserList.GetCurrentUser();
|
|
||||||
var progress = user.GetMinigameProgress(minigame.index);
|
|
||||||
if (progress == null)
|
|
||||||
{
|
|
||||||
progress = new PersistentDataController.SavedMinigameProgress();
|
|
||||||
progress.minigameIndex = minigame.index;
|
|
||||||
user.AddMinigameProgress(progress);
|
|
||||||
}
|
|
||||||
UserList.Save();
|
|
||||||
|
|
||||||
scoreDisplay.text = $"Score: {CalculateScore()}";
|
|
||||||
words.AddRange(currentTheme.learnables);
|
|
||||||
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>
|
/// <summary>
|
||||||
@@ -388,7 +291,8 @@ public class JustSignController : AbstractFeedback
|
|||||||
// Check if the song has ended and activate scorescreen if it has
|
// Check if the song has ended and activate scorescreen if it has
|
||||||
if (currentTime - beginTime > currentSong.duration)
|
if (currentTime - beginTime > currentSong.duration)
|
||||||
{
|
{
|
||||||
ActivateEnd();
|
// The boolean that is passed is irrelevant for this game
|
||||||
|
ActivateEnd(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move all active symbols to the right
|
// Move all active symbols to the right
|
||||||
@@ -406,28 +310,11 @@ public class JustSignController : AbstractFeedback
|
|||||||
/// Calculate the score
|
/// Calculate the score
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The calculated score</returns>
|
/// <returns>The calculated score</returns>
|
||||||
public int CalculateScore()
|
public override int CalculateScore()
|
||||||
{
|
{
|
||||||
return goodSigns * goodScore + perfectSigns * perfectScore + mehScore * mehSigns + terribleScore * terribleSigns + incorrectSigns * offscreenScore;
|
return goodSigns * goodScore + perfectSigns * perfectScore + mehScore * mehSigns + terribleScore * terribleSigns + incorrectSigns * offscreenScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Display Scoreboard + Metrics
|
|
||||||
/// </summary>
|
|
||||||
public void ActivateEnd()
|
|
||||||
{
|
|
||||||
gameIsActive = false;
|
|
||||||
while (activeSymbols.Count > 0)
|
|
||||||
{
|
|
||||||
DestroySymbolAt(0);
|
|
||||||
}
|
|
||||||
// TODO: Scoreboard
|
|
||||||
SaveScores();
|
|
||||||
SetScoreMetrics();
|
|
||||||
SetScoreBoard();
|
|
||||||
gameEndedPanel.SetActive(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Destroy the symbol at the given index
|
/// Destroy the symbol at the given index
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -474,191 +361,15 @@ public class JustSignController : AbstractFeedback
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update and save the scores
|
/// The logic to process the signs sent by the signPredictor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SaveScores()
|
/// <param name="accuracy">The accuracy of the passed sign</param>
|
||||||
|
/// <param name="predictedSign">The name of the passed sign</param>
|
||||||
|
protected override void ProcessMostProbableSign(float accuracy, string predictedSign)
|
||||||
{
|
{
|
||||||
// Calculate new score
|
Learnable predSign = currentTheme.learnables.Find(l => l.name.ToUpper() == predictedSign);
|
||||||
int newScore = CalculateScore();
|
|
||||||
|
|
||||||
// Save the score as a tuple: < int score, string time ago>
|
|
||||||
Score score = new Score();
|
|
||||||
score.scoreValue = newScore;
|
|
||||||
score.time = DateTime.Now.ToString();
|
|
||||||
|
|
||||||
// Save the new score
|
|
||||||
var progress = user.GetMinigameProgress(minigame.index);
|
|
||||||
|
|
||||||
// Get the current list of scores
|
|
||||||
List<Score> latestScores = progress.latestScores;
|
|
||||||
List<Score> highestScores = progress.highestScores;
|
|
||||||
|
|
||||||
// Add the new score
|
|
||||||
latestScores.Add(score);
|
|
||||||
highestScores.Add(score);
|
|
||||||
|
|
||||||
// Sort the scores
|
|
||||||
highestScores.Sort((a, b) => b.scoreValue.CompareTo(a.scoreValue));
|
|
||||||
|
|
||||||
// Only save the top 10 scores, so this list doesn't keep growing endlessly
|
|
||||||
progress.latestScores = latestScores.Take(10).ToList();
|
|
||||||
progress.highestScores = highestScores.Take(10).ToList();
|
|
||||||
|
|
||||||
PersistentDataController.GetInstance().Save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Set score metrics
|
|
||||||
/// </summary>
|
|
||||||
private void SetScoreMetrics()
|
|
||||||
{
|
|
||||||
// In de zone
|
|
||||||
perfectSignsText.text = perfectSigns.ToString();
|
|
||||||
|
|
||||||
// Aanvaardbaar
|
|
||||||
goodSignsText.text = goodSigns.ToString();
|
|
||||||
|
|
||||||
// Nipt
|
|
||||||
mehSignsText.text = mehSigns.ToString();
|
|
||||||
|
|
||||||
// Slechte timing
|
|
||||||
terribleSignsText.text = terribleSigns.ToString();
|
|
||||||
|
|
||||||
// Niet Geraden
|
|
||||||
notFoundSignsText.text = incorrectSigns.ToString();
|
|
||||||
|
|
||||||
// LPM
|
|
||||||
int duration = songList.songs[songList.currentSongIndex].duration;
|
|
||||||
int correctSigns = goodSigns + perfectSigns + mehSigns + terribleSigns;
|
|
||||||
lpmText.text = (60f * correctSigns / duration).ToString("#") + " GPM";
|
|
||||||
|
|
||||||
// Score
|
|
||||||
scoreText.text = $"Score: {CalculateScore()}";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets the scoreboard
|
|
||||||
/// </summary>
|
|
||||||
private void SetScoreBoard()
|
|
||||||
{
|
|
||||||
// Clean the previous scoreboard entries
|
|
||||||
for (int i = 0; i < scoreboardEntries.Count; i++)
|
|
||||||
{
|
|
||||||
Destroy(scoreboardEntries[i]);
|
|
||||||
}
|
|
||||||
scoreboardEntries.Clear();
|
|
||||||
|
|
||||||
// Instantiate new entries
|
|
||||||
// Get all scores from all users
|
|
||||||
List<Tuple<string, Score>> allScores = new List<Tuple<string, Score>>();
|
|
||||||
foreach (User user in UserList.GetUsers())
|
|
||||||
{
|
|
||||||
// Get user's progress for this minigame
|
|
||||||
var progress = user.GetMinigameProgress(minigame.index);
|
|
||||||
if (progress != null)
|
|
||||||
{
|
|
||||||
// Add scores to dictionary
|
|
||||||
List<Score> scores = progress.highestScores;
|
|
||||||
foreach (Score score in scores)
|
|
||||||
{
|
|
||||||
allScores.Add(new Tuple<string, Score>(user.GetUsername(), score));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort allScores based on Score.scoreValue
|
|
||||||
allScores.Sort((a, b) => b.Item2.scoreValue.CompareTo(a.Item2.scoreValue));
|
|
||||||
|
|
||||||
// Instantiate scoreboard entries
|
|
||||||
int rank = 1;
|
|
||||||
foreach (Tuple<string, Score> tup in allScores.Take(10))
|
|
||||||
{
|
|
||||||
string username = tup.Item1;
|
|
||||||
Score score = tup.Item2;
|
|
||||||
|
|
||||||
GameObject entry = Instantiate(scoreboardEntry, scoreboardEntriesContainer);
|
|
||||||
scoreboardEntries.Add(entry);
|
|
||||||
|
|
||||||
// Set the player icon
|
|
||||||
entry.transform.Find("Image").GetComponent<Image>().sprite = UserList.GetUserByUsername(username).GetAvatar();
|
|
||||||
|
|
||||||
// Set the player name
|
|
||||||
entry.transform.Find("PlayerName").GetComponent<TMP_Text>().text = username;
|
|
||||||
|
|
||||||
// Set the score
|
|
||||||
entry.transform.Find("Score").GetComponent<TMP_Text>().text = score.scoreValue.ToString();
|
|
||||||
|
|
||||||
// Set the rank
|
|
||||||
entry.transform.Find("Rank").GetComponent<TMP_Text>().text = rank.ToString();
|
|
||||||
|
|
||||||
// Set the ago
|
|
||||||
// Convert the score.time to Datetime
|
|
||||||
DateTime time = DateTime.Parse(score.time);
|
|
||||||
DateTime currentTime = DateTime.Now;
|
|
||||||
TimeSpan diff = currentTime.Subtract(time);
|
|
||||||
|
|
||||||
string formatted;
|
|
||||||
if (diff.Days > 0)
|
|
||||||
{
|
|
||||||
formatted = $"{diff.Days}d ";
|
|
||||||
}
|
|
||||||
else if (diff.Hours > 0)
|
|
||||||
{
|
|
||||||
formatted = $"{diff.Hours}h ";
|
|
||||||
}
|
|
||||||
else if (diff.Minutes > 0)
|
|
||||||
{
|
|
||||||
formatted = $"{diff.Minutes}m ";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
formatted = "now";
|
|
||||||
}
|
|
||||||
|
|
||||||
entry.transform.Find("Ago").GetComponent<TMP_Text>().text = formatted;
|
|
||||||
|
|
||||||
|
|
||||||
// Alternating colors looks nice
|
|
||||||
if (rank % 2 == 0)
|
|
||||||
{
|
|
||||||
Image image = entry.transform.GetComponent<Image>();
|
|
||||||
image.color = new Color(image.color.r, image.color.g, image.color.b, 0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make new score stand out
|
|
||||||
if (diff.TotalSeconds < 1)
|
|
||||||
{
|
|
||||||
Image image = entry.transform.GetComponent<Image>();
|
|
||||||
image.color = new Color(0, 229, 255, 233);
|
|
||||||
}
|
|
||||||
|
|
||||||
rank++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The updateFunction that is called when new probabilities become available
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
protected override IEnumerator UpdateFeedback()
|
|
||||||
{
|
|
||||||
// Get the predicted sign
|
|
||||||
if (signPredictor != null && signPredictor.learnableProbabilities != null && gameIsActive)
|
|
||||||
{
|
|
||||||
// Get highest predicted sign
|
|
||||||
string predictedSign = signPredictor.learnableProbabilities.Aggregate((a, b) => a.Value > b.Value ? a : b).Key;
|
|
||||||
float accuracy = signPredictor.learnableProbabilities[predictedSign];
|
|
||||||
|
|
||||||
// vvv TEMPORARY STUFF vvv
|
|
||||||
if (predictedSign == "J" && accuracy <= 0.97f)
|
|
||||||
{
|
|
||||||
predictedSign = signPredictor.learnableProbabilities.Aggregate((x, y) => x.Value > y.Value && x.Key != "J" ? x : y).Key;
|
|
||||||
}
|
|
||||||
accuracy = signPredictor.learnableProbabilities[predictedSign];
|
|
||||||
// ^^^ TEMPORARY STUFF ^^^
|
|
||||||
|
|
||||||
Learnable predSign = currentTheme.learnables.Find(l => l.name.ToUpper().Replace(" ", "-") == predictedSign);
|
|
||||||
|
|
||||||
|
// If there is a feedback-object, we wil change its appearance
|
||||||
if (feedbackText != null && feedbackProgressImage != null)
|
if (feedbackText != null && feedbackProgressImage != null)
|
||||||
{
|
{
|
||||||
Color col;
|
Color col;
|
||||||
@@ -681,18 +392,19 @@ public class JustSignController : AbstractFeedback
|
|||||||
feedbackText.color = col;
|
feedbackText.color = col;
|
||||||
feedbackProgressImage.color = col;
|
feedbackProgressImage.color = col;
|
||||||
|
|
||||||
float oldValue = feedbackProgressBar.value;
|
float oldValue = feedbackProgress.value;
|
||||||
// use an exponential scale
|
// use an exponential scale
|
||||||
float newValue = Mathf.Exp(4 * (Mathf.Clamp(accuracy / predSign.thresholdPercentage, 0.0f, 1.0f) - 1.0f));
|
float newValue = Mathf.Exp(4 * (Mathf.Clamp(accuracy / predSign.thresholdPercentage, 0.0f, 1.0f) - 1.0f));
|
||||||
feedbackProgressBar.gameObject.Tween("FeedbackUpdate", oldValue, newValue, 0.2f, TweenScaleFunctions.CubicEaseInOut, (t) =>
|
feedbackProgress.gameObject.Tween("FeedbackUpdate", oldValue, newValue, 0.2f, TweenScaleFunctions.CubicEaseInOut, (t) =>
|
||||||
{
|
{
|
||||||
if (feedbackProgressBar != null)
|
if (feedbackProgress != null)
|
||||||
{
|
{
|
||||||
feedbackProgressBar.value = t.CurrentValue;
|
feedbackProgress.value = t.CurrentValue;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The logic for the internal workings of the game
|
||||||
if (accuracy > predSign.thresholdPercentage)
|
if (accuracy > predSign.thresholdPercentage)
|
||||||
{
|
{
|
||||||
int matchedSymbolIndex = activeWords.IndexOf(predictedSign.ToUpper());
|
int matchedSymbolIndex = activeWords.IndexOf(predictedSign.ToUpper());
|
||||||
@@ -745,11 +457,64 @@ public class JustSignController : AbstractFeedback
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (feedbackProgressBar != null)
|
|
||||||
{
|
|
||||||
|
|
||||||
feedbackProgressBar.value = 0.0f;
|
/// <summary>
|
||||||
|
/// The logic to set the scoreboard of justsign
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="victory">Shows whether or not the player won, is not relevant for JustSIgn</param>
|
||||||
|
protected override void SetScoreBoard(bool victory)
|
||||||
|
{
|
||||||
|
gameEndedPanel.GetComponent<JustSignGameEndedPanel>().GenerateContent(
|
||||||
|
perfectSigns: perfectSigns,
|
||||||
|
goodSigns: goodSigns,
|
||||||
|
mehSigns: mehSigns,
|
||||||
|
terribleSigns: terribleSigns,
|
||||||
|
incorrectSigns: incorrectSigns,
|
||||||
|
duration: currentSong.duration,
|
||||||
|
score: CalculateScore()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The justsign-specific logic that needs to be called at the start of the game
|
||||||
|
/// </summary>
|
||||||
|
protected override void StartGameLogic()
|
||||||
|
{
|
||||||
|
// Set the current theme so that it can be passed along
|
||||||
|
|
||||||
|
currentTheme = minigame.themeList.themes[minigame.themeList.currentThemeIndex];
|
||||||
|
|
||||||
|
userFeedback.SetActive(currentTheme.modelIndex != ModelIndex.NONE);
|
||||||
|
previewMessage.SetActive(currentTheme.modelIndex == ModelIndex.NONE);
|
||||||
|
perfectSigns = 0;
|
||||||
|
goodSigns = 0;
|
||||||
|
mehSigns = 0;
|
||||||
|
terribleSigns = 0;
|
||||||
|
incorrectSigns = 0;
|
||||||
|
timingFeedback.text = "";
|
||||||
|
imageFeedback.sprite = minigame.thumbnail;
|
||||||
|
gameEndedPanel.SetActive(false);
|
||||||
|
|
||||||
|
scoreDisplay.text = $"Score: {CalculateScore()}";
|
||||||
|
words.AddRange(currentTheme.learnables);
|
||||||
|
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>
|
||||||
|
/// The justsign-specific logic that needs to be called at the end of a game
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="victory"></param>
|
||||||
|
protected override void EndGameLogic(bool victory)
|
||||||
|
{
|
||||||
|
gameIsActive = false;
|
||||||
|
while (activeSymbols.Count > 0)
|
||||||
|
{
|
||||||
|
DestroySymbolAt(0);
|
||||||
}
|
}
|
||||||
yield return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
90
Assets/JustSign/Scripts/JustSignGameEndedPanel.cs
Normal file
90
Assets/JustSign/Scripts/JustSignGameEndedPanel.cs
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
/// <summary>
|
||||||
|
/// The JustSign-variant of the ScoreBoard
|
||||||
|
/// </summary>
|
||||||
|
public class JustSignGameEndedPanel : AbstractGameEndedPanel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Tell the scoreboard that the scoreboard is for JustSign
|
||||||
|
/// </summary>
|
||||||
|
protected override MinigameIndex minigameIndex
|
||||||
|
{
|
||||||
|
get { return MinigameIndex.JUST_SIGN; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The field that will display the amount of perfect signs
|
||||||
|
/// </summary>
|
||||||
|
public TMP_Text perfectSignsText;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The field that will display the amount of good signs
|
||||||
|
/// </summary>
|
||||||
|
public TMP_Text goodSignsText;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The field that will display the amount of meh signs
|
||||||
|
/// </summary>
|
||||||
|
public TMP_Text mehSignsText;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The field that will display the amount of terrible signs
|
||||||
|
/// </summary>
|
||||||
|
public TMP_Text terribleSignsText;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The field that will display the amount of not found signs
|
||||||
|
/// </summary>
|
||||||
|
public TMP_Text notFoundSignsText;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The field that will display the signs per minute
|
||||||
|
/// </summary>
|
||||||
|
public TMP_Text gpmText;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Score
|
||||||
|
/// </summary>
|
||||||
|
public TMP_Text scoreText;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generate the content of the gameEnded panel
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="perfectSigns">The amount of perfect signs</param>
|
||||||
|
/// <param name="goodSigns">The amount of good signs</param>
|
||||||
|
/// <param name="mehSigns">The amount of meh signs</param>
|
||||||
|
/// <param name="terribleSigns">The emount of terrible signs</param>
|
||||||
|
/// <param name="incorrectSigns">The amount of incorrect signs</param>
|
||||||
|
/// <param name="duration">The duration of the song that was played</param>
|
||||||
|
/// <param name="score">The score obtained by the player</param>
|
||||||
|
public void GenerateContent(int perfectSigns, int goodSigns, int mehSigns, int terribleSigns, int incorrectSigns, int duration, int score)
|
||||||
|
{
|
||||||
|
// In de zone
|
||||||
|
perfectSignsText.text = perfectSigns.ToString();
|
||||||
|
|
||||||
|
// Aanvaardbaar
|
||||||
|
goodSignsText.text = goodSigns.ToString();
|
||||||
|
|
||||||
|
// Nipt
|
||||||
|
mehSignsText.text = mehSigns.ToString();
|
||||||
|
|
||||||
|
// Slechte timing
|
||||||
|
terribleSignsText.text = terribleSigns.ToString();
|
||||||
|
|
||||||
|
// Niet Geraden
|
||||||
|
notFoundSignsText.text = incorrectSigns.ToString();
|
||||||
|
|
||||||
|
// LPM
|
||||||
|
int correctSigns = goodSigns + perfectSigns + mehSigns + terribleSigns;
|
||||||
|
gpmText.text = (60f * correctSigns / duration).ToString("#") + " GPM";
|
||||||
|
|
||||||
|
// Score
|
||||||
|
scoreText.text = $"Score: {score}";
|
||||||
|
SetScoreBoard();
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/JustSign/Scripts/JustSignGameEndedPanel.cs.meta
Normal file
11
Assets/JustSign/Scripts/JustSignGameEndedPanel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9a86c239be1aa1543ba8a4ace5f658b1
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -7,7 +7,8 @@
|
|||||||
"GUID:1631ed2680c61245b8211d943c1639a8",
|
"GUID:1631ed2680c61245b8211d943c1639a8",
|
||||||
"GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25",
|
"GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25",
|
||||||
"GUID:58e104b97fb3752438ada2902a36dcbf",
|
"GUID:58e104b97fb3752438ada2902a36dcbf",
|
||||||
"GUID:d0b6b39a21908f94fbbd9f2c196a9725"
|
"GUID:d0b6b39a21908f94fbbd9f2c196a9725",
|
||||||
|
"GUID:403dd94a93598934eb522dc36df43d7b"
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
|
|||||||
@@ -297,6 +297,7 @@ public class SignPredictor : MonoBehaviour
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static bool resourceManagerIsInitialized = false;
|
private static bool resourceManagerIsInitialized = false;
|
||||||
|
|
||||||
|
private List<string> signs;
|
||||||
private EmbeddingDataList embeddingDataList;
|
private EmbeddingDataList embeddingDataList;
|
||||||
|
|
||||||
private ModelIndex modelID;
|
private ModelIndex modelID;
|
||||||
@@ -521,15 +522,6 @@ public class SignPredictor : MonoBehaviour
|
|||||||
{
|
{
|
||||||
learnableProbabilities = new Dictionary<string, float>();
|
learnableProbabilities = new Dictionary<string, float>();
|
||||||
|
|
||||||
// Temporary fix
|
|
||||||
List<string> signs = new List<string>()
|
|
||||||
{
|
|
||||||
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
|
|
||||||
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (int j = 0; j < result.Count; j++)
|
for (int j = 0; j < result.Count; j++)
|
||||||
{
|
{
|
||||||
learnableProbabilities.Add(signs[j].ToUpper(), result[j]);
|
learnableProbabilities.Add(signs[j].ToUpper(), result[j]);
|
||||||
@@ -715,4 +707,8 @@ public class SignPredictor : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetSignsList(List<string> signs)
|
||||||
|
{
|
||||||
|
this.signs = signs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
Assets/Minigames.meta
Normal file
8
Assets/Minigames.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 353d02d53aeb14341835f87efae01039
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Assets/Minigames/Scripts.meta
Normal file
8
Assets/Minigames/Scripts.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d5e1253d871fce14ab568e5c9ad4ced2
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -4,49 +4,18 @@ using System.Linq;
|
|||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
/// <summary>
|
||||||
public class GameEndedPanel : MonoBehaviour
|
/// Abstract class for all minigame-gameEndedPanels
|
||||||
|
/// </summary>
|
||||||
|
public abstract class AbstractGameEndedPanel : MonoBehaviour
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// "VERLOREN" or "GEWONNEN"
|
/// The index of minigame that needs a GameEndedPanel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TMP_Text endText;
|
protected abstract MinigameIndex minigameIndex
|
||||||
|
{
|
||||||
/// <summary>
|
get;
|
||||||
/// LPM
|
}
|
||||||
/// </summary>
|
|
||||||
public TMP_Text lpmText;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Letters ( right | wrong )
|
|
||||||
/// </summary>
|
|
||||||
public TMP_Text lettersRightText;
|
|
||||||
public TMP_Text lettersWrongText;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Letters
|
|
||||||
/// </summary>
|
|
||||||
public TMP_Text lettersTotalText;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Accuracy
|
|
||||||
/// </summary>
|
|
||||||
public TMP_Text accuracyText;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Words
|
|
||||||
/// </summary>
|
|
||||||
public TMP_Text wordsText;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Time
|
|
||||||
/// </summary>
|
|
||||||
public TMP_Text timeText;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Score
|
|
||||||
/// </summary>
|
|
||||||
public TMP_Text scoreText;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reference to the scoreboard entries container
|
/// Reference to the scoreboard entries container
|
||||||
@@ -63,55 +32,10 @@ public class GameEndedPanel : MonoBehaviour
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public GameObject scoreboardEntry;
|
public GameObject scoreboardEntry;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generate the content of the GameEnded panel
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="startTime">Time of starting the minigame</param>
|
|
||||||
/// <param name="totalWords">Total number of words</param>
|
|
||||||
/// <param name="correctLetters">Total number of correctly spelled letters</param>
|
|
||||||
/// <param name="incorrectLetters">Total number of incorrectly spelled letters</param>
|
|
||||||
/// <param name="result">"VERLOREN" or "GEWONNEN"</param>
|
|
||||||
/// <param name="score">Final score</param>
|
|
||||||
public void GenerateContent(DateTime startTime, int totalWords, int correctLetters, int incorrectLetters, string result, int score)
|
|
||||||
{
|
|
||||||
// Final result
|
|
||||||
endText.text = result;
|
|
||||||
|
|
||||||
// LPM
|
|
||||||
TimeSpan duration = DateTime.Now.Subtract(startTime);
|
|
||||||
lpmText.text = (60f * correctLetters / duration.TotalSeconds).ToString("#") + " LPM";
|
|
||||||
|
|
||||||
// Letters ( right | wrong ) total
|
|
||||||
lettersRightText.text = correctLetters.ToString();
|
|
||||||
lettersWrongText.text = incorrectLetters.ToString();
|
|
||||||
lettersTotalText.text = (correctLetters + incorrectLetters).ToString();
|
|
||||||
|
|
||||||
// Accuracy
|
|
||||||
if (correctLetters + incorrectLetters > 0)
|
|
||||||
{
|
|
||||||
accuracyText.text = ((correctLetters) * 100f / (correctLetters + incorrectLetters)).ToString("#.##") + "%";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
accuracyText.text = "-";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Words
|
|
||||||
wordsText.text = $"{totalWords}";
|
|
||||||
|
|
||||||
// Time
|
|
||||||
timeText.text = duration.ToString(@"mm\:ss");
|
|
||||||
|
|
||||||
// Score
|
|
||||||
scoreText.text = $"Score: {score}";
|
|
||||||
SetScoreBoard();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the scoreboard
|
/// Sets the scoreboard
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void SetScoreBoard()
|
protected void SetScoreBoard()
|
||||||
{
|
{
|
||||||
// Clean the previous scoreboard entries
|
// Clean the previous scoreboard entries
|
||||||
for (int i = 0; i < scoreboardEntries.Count; i++)
|
for (int i = 0; i < scoreboardEntries.Count; i++)
|
||||||
@@ -126,7 +50,7 @@ public class GameEndedPanel : MonoBehaviour
|
|||||||
foreach (User user in UserList.GetUsers())
|
foreach (User user in UserList.GetUsers())
|
||||||
{
|
{
|
||||||
// Get user's progress for this minigame
|
// Get user's progress for this minigame
|
||||||
var progress = user.GetMinigameProgress(MinigameIndex.SPELLING_BEE);
|
var progress = user.GetMinigameProgress(minigameIndex);
|
||||||
if (progress != null)
|
if (progress != null)
|
||||||
{
|
{
|
||||||
// Add scores to dictionary
|
// Add scores to dictionary
|
||||||
11
Assets/Minigames/Scripts/AbstractGameEndedPanel.cs.meta
Normal file
11
Assets/Minigames/Scripts/AbstractGameEndedPanel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 73d452eb6e118ec4091d6cdd82f3550c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
221
Assets/Minigames/Scripts/AbstractMinigameController.cs
Normal file
221
Assets/Minigames/Scripts/AbstractMinigameController.cs
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
/// <summary>
|
||||||
|
/// Shared abstract class for the minigameControllers
|
||||||
|
/// </summary>
|
||||||
|
public abstract class AbstractMinigameController : AbstractFeedback
|
||||||
|
{
|
||||||
|
[Header("AbstractVariables")]
|
||||||
|
/// <summary>
|
||||||
|
/// We keep the minigamelist so that the minigame-index doesn't get reset
|
||||||
|
/// DO NOT REMOVE
|
||||||
|
/// </summary>
|
||||||
|
public MinigameList minigamelist;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A bool to denote whether or not the game is still being played
|
||||||
|
/// </summary>
|
||||||
|
protected bool gameIsActive;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reference to the progress bar
|
||||||
|
/// </summary>
|
||||||
|
public Slider feedbackProgress;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reference to the current user
|
||||||
|
/// </summary>
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reference to the minigame ScriptableObject
|
||||||
|
/// </summary>
|
||||||
|
protected Minigame minigame;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Each minigame has a webcamTexture, this will be used in children-methods
|
||||||
|
/// </summary>
|
||||||
|
public RawImage webcamScreen;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reference to the gameEnded panel, so we can update its display
|
||||||
|
/// </summary>
|
||||||
|
public GameObject gameEndedPanel;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The theme that will be used by the signpredictor, this needs to be passed from the concrete class.
|
||||||
|
/// This theme CAN be different from the theme that words are fetched from (Think SpellingBee and Hangman)
|
||||||
|
/// </summary>
|
||||||
|
protected abstract Theme signPredictorTheme
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Start is called before the first frame update, seal it to prevent minigames from changing it
|
||||||
|
/// </summary>
|
||||||
|
protected void Start()
|
||||||
|
{
|
||||||
|
// Get the scriptable of the current minigame
|
||||||
|
minigame = minigamelist.minigames[minigamelist.currentMinigameIndex];
|
||||||
|
|
||||||
|
// Start the game-specific start-logic
|
||||||
|
StartController();
|
||||||
|
|
||||||
|
// Prepare the signPredictor
|
||||||
|
signPredictor.SetModel(signPredictorTheme.modelIndex);
|
||||||
|
signPredictor.SwapScreen(webcamScreen);
|
||||||
|
signPredictor.SetSignsList(GetSignsList());
|
||||||
|
AddSelfAsListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// All minigames use the same principle, they grab the most probable sign and use said sign to show feedback to the user
|
||||||
|
/// Because we don't want minigames to write their own UpdateFeedbacks this function will be sealed
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="System.NotImplementedException"></exception>
|
||||||
|
protected override sealed IEnumerator UpdateFeedback()
|
||||||
|
{
|
||||||
|
// Get the predicted sign
|
||||||
|
if (signPredictor != null && signPredictor.learnableProbabilities != null && gameIsActive)
|
||||||
|
{
|
||||||
|
// Get highest predicted sign
|
||||||
|
string predictedSign = signPredictor.learnableProbabilities.Aggregate((a, b) => a.Value > b.Value ? a : b).Key;
|
||||||
|
float accuracy = signPredictor.learnableProbabilities[predictedSign];
|
||||||
|
|
||||||
|
// vvv TEMPORARY STUFF vvv
|
||||||
|
if (predictedSign == "J" && accuracy <= 0.97f)
|
||||||
|
{
|
||||||
|
predictedSign = signPredictor.learnableProbabilities.Aggregate((x, y) => x.Value > y.Value && x.Key != "J" ? x : y).Key;
|
||||||
|
}
|
||||||
|
accuracy = signPredictor.learnableProbabilities[predictedSign];
|
||||||
|
// ^^^ TEMPORARY STUFF ^^^
|
||||||
|
|
||||||
|
ProcessMostProbableSign(accuracy, predictedSign);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This part is the only reason that feedbackProgress is needed in the abstract
|
||||||
|
else if (feedbackProgress != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
feedbackProgress.value = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Each game keeps a score, this score needs to be saved at some point
|
||||||
|
/// </summary>
|
||||||
|
public void SaveScores()
|
||||||
|
{
|
||||||
|
// Calculate new score
|
||||||
|
int newScore = CalculateScore();
|
||||||
|
|
||||||
|
// Save the score as a tuple: < int score, string time ago>
|
||||||
|
Score score = new Score();
|
||||||
|
score.scoreValue = newScore;
|
||||||
|
score.time = DateTime.Now.ToString();
|
||||||
|
|
||||||
|
// Save the new score
|
||||||
|
var progress = user.GetMinigameProgress(minigame.index);
|
||||||
|
|
||||||
|
// Get the current list of scores
|
||||||
|
List<Score> latestScores = progress.latestScores;
|
||||||
|
List<Score> highestScores = progress.highestScores;
|
||||||
|
|
||||||
|
// Add the new score
|
||||||
|
latestScores.Add(score);
|
||||||
|
highestScores.Add(score);
|
||||||
|
|
||||||
|
// Sort the scores
|
||||||
|
highestScores.Sort((a, b) => b.scoreValue.CompareTo(a.scoreValue));
|
||||||
|
|
||||||
|
// Only save the top 10 scores, so this list doesn't keep growing endlessly
|
||||||
|
progress.latestScores = latestScores.Take(10).ToList();
|
||||||
|
progress.highestScores = highestScores.Take(10).ToList();
|
||||||
|
|
||||||
|
PersistentDataController.GetInstance().Save();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// The function that activates when the game ends, handles some endgame logic and displays the EndPanel
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="won"></param>
|
||||||
|
public void ActivateEnd(bool victory)
|
||||||
|
{
|
||||||
|
EndGameLogic(victory);
|
||||||
|
SaveScores();
|
||||||
|
SetScoreBoard(victory);
|
||||||
|
|
||||||
|
gameEndedPanel.SetActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Once the most probable sign has been fetched, they can be processed
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="accuracy">The accuracy of the passed sign</param>
|
||||||
|
/// <param name="predictedSign">The name of the passed sign</param>
|
||||||
|
protected abstract void ProcessMostProbableSign(float accuracy, string predictedSign);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Each minigame has their own way of calculating their score
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The score that the user has at that point</returns>
|
||||||
|
public abstract int CalculateScore();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Each minigame has an AbstractGameEndedPanel at the end, but they each have their own unique concrete instance
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="victory">1 if the player won, 0 if they lost. Some games need this</param>
|
||||||
|
protected abstract void SetScoreBoard(bool victory);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Each minigame puts their GameLogic to be called at (re)start in a seperate function from Start()
|
||||||
|
/// </summary>
|
||||||
|
public void StartController()
|
||||||
|
{
|
||||||
|
StartGameLogic();
|
||||||
|
|
||||||
|
// Create entry in current user for keeping track of progress
|
||||||
|
user = UserList.GetCurrentUser();
|
||||||
|
var progress = user.GetMinigameProgress(minigame.index);
|
||||||
|
if (progress == null)
|
||||||
|
{
|
||||||
|
progress = new PersistentDataController.SavedMinigameProgress();
|
||||||
|
progress.minigameIndex = minigame.index;
|
||||||
|
user.AddMinigameProgress(progress);
|
||||||
|
}
|
||||||
|
UserList.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Logic to be called at the start of the game
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void StartGameLogic();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Function that contains all the logic to end the game
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="victory">1 if the player won, 0 if they lost. Some games need this</param>
|
||||||
|
protected abstract void EndGameLogic(bool victory);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// All non-fingerspelling-minigames have the same logic for the GetSignsList
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The signsList that needs to be passed to the signPredictor</returns>
|
||||||
|
private List<string> GetSignsList()
|
||||||
|
{
|
||||||
|
List<string> signsList = new List<string>();
|
||||||
|
foreach (Learnable learnable in signPredictorTheme.learnables)
|
||||||
|
{
|
||||||
|
signsList.Add(learnable.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return signsList;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Minigames/Scripts/AbstractMinigameController.cs.meta
Normal file
11
Assets/Minigames/Scripts/AbstractMinigameController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a32c0ecc5507e4542a79c1b96a47b0a7
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
20
Assets/Minigames/Scripts/MinigameScripts.asmdef
Normal file
20
Assets/Minigames/Scripts/MinigameScripts.asmdef
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "MinigameScripts",
|
||||||
|
"rootNamespace": "",
|
||||||
|
"references": [
|
||||||
|
"GUID:d0b6b39a21908f94fbbd9f2c196a9725",
|
||||||
|
"GUID:e83ddf9a537a96b4a804a16bb7872ec1",
|
||||||
|
"GUID:1631ed2680c61245b8211d943c1639a8",
|
||||||
|
"GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25",
|
||||||
|
"GUID:6055be8ebefd69e48b49212b09b47b2f"
|
||||||
|
],
|
||||||
|
"includePlatforms": [],
|
||||||
|
"excludePlatforms": [],
|
||||||
|
"allowUnsafeCode": false,
|
||||||
|
"overrideReferences": false,
|
||||||
|
"precompiledReferences": [],
|
||||||
|
"autoReferenced": true,
|
||||||
|
"defineConstraints": [],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false
|
||||||
|
}
|
||||||
7
Assets/Minigames/Scripts/MinigameScripts.asmdef.meta
Normal file
7
Assets/Minigames/Scripts/MinigameScripts.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 403dd94a93598934eb522dc36df43d7b
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -5,7 +5,7 @@ using UnityEditor;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.TestTools;
|
using UnityEngine.TestTools;
|
||||||
|
|
||||||
public class GameEndedPanelTests
|
public class SpellingBeeGameEndedPanelTests
|
||||||
{
|
{
|
||||||
[UnitySetUp]
|
[UnitySetUp]
|
||||||
public IEnumerator SetupFunction()
|
public IEnumerator SetupFunction()
|
||||||
@@ -31,15 +31,15 @@ public class GameEndedPanelTests
|
|||||||
yield return new WaitForSeconds(1f);
|
yield return new WaitForSeconds(1f);
|
||||||
|
|
||||||
|
|
||||||
spellingBeeController.ActivateWin();
|
spellingBeeController.ActivateEnd(true);
|
||||||
|
|
||||||
GameEndedPanel gameEndedPanel = (GameEndedPanel)GameObject.FindObjectOfType(typeof(GameEndedPanel));
|
SpellingBeeGameEndedPanel SpellingBeeGameEndedPanel = (SpellingBeeGameEndedPanel)GameObject.FindObjectOfType(typeof(SpellingBeeGameEndedPanel));
|
||||||
Assert.NotNull(gameEndedPanel);
|
Assert.NotNull(SpellingBeeGameEndedPanel);
|
||||||
Assert.AreEqual("Score: 0", gameEndedPanel.scoreText.text);
|
Assert.AreEqual("Score: 0", SpellingBeeGameEndedPanel.scoreText.text);
|
||||||
Assert.AreEqual("1", gameEndedPanel.lettersRightText.text);
|
Assert.AreEqual("1", SpellingBeeGameEndedPanel.lettersRightText.text);
|
||||||
Assert.AreEqual("2", gameEndedPanel.lettersWrongText.text);
|
Assert.AreEqual("2", SpellingBeeGameEndedPanel.lettersWrongText.text);
|
||||||
Assert.AreEqual("3", gameEndedPanel.lettersTotalText.text);
|
Assert.AreEqual("3", SpellingBeeGameEndedPanel.lettersTotalText.text);
|
||||||
Assert.AreEqual("00:01", gameEndedPanel.timeText.text);
|
Assert.AreEqual("00:01", SpellingBeeGameEndedPanel.timeText.text);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,12 +36,12 @@ public class SpellingBeeControllerTests
|
|||||||
public IEnumerator ActivateGameOverTest()
|
public IEnumerator ActivateGameOverTest()
|
||||||
{
|
{
|
||||||
SpellingBeeController spellingBeeController = (SpellingBeeController)GameObject.FindObjectOfType(typeof(SpellingBeeController));
|
SpellingBeeController spellingBeeController = (SpellingBeeController)GameObject.FindObjectOfType(typeof(SpellingBeeController));
|
||||||
spellingBeeController.ActivateGameOver();
|
spellingBeeController.ActivateEnd(false);
|
||||||
|
|
||||||
yield return new WaitForSeconds(0.2f);
|
yield return new WaitForSeconds(0.2f);
|
||||||
GameEndedPanel gameEndedPanel = (GameEndedPanel)GameObject.FindObjectOfType(typeof(GameEndedPanel));
|
SpellingBeeGameEndedPanel SpellingBeeGameEndedPanel = (SpellingBeeGameEndedPanel)GameObject.FindObjectOfType(typeof(SpellingBeeGameEndedPanel));
|
||||||
Assert.NotNull(gameEndedPanel);
|
Assert.NotNull(SpellingBeeGameEndedPanel);
|
||||||
Assert.AreEqual("VERLOREN", gameEndedPanel.endText.text);
|
Assert.AreEqual("VERLOREN", SpellingBeeGameEndedPanel.endText.text);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,12 +49,12 @@ public class SpellingBeeControllerTests
|
|||||||
public IEnumerator ActivateWinTests()
|
public IEnumerator ActivateWinTests()
|
||||||
{
|
{
|
||||||
SpellingBeeController spellingBeeController = (SpellingBeeController)GameObject.FindObjectOfType(typeof(SpellingBeeController));
|
SpellingBeeController spellingBeeController = (SpellingBeeController)GameObject.FindObjectOfType(typeof(SpellingBeeController));
|
||||||
spellingBeeController.ActivateWin();
|
spellingBeeController.ActivateEnd(true);
|
||||||
|
|
||||||
yield return new WaitForSeconds(0.2f);
|
yield return new WaitForSeconds(0.2f);
|
||||||
GameEndedPanel gameEndedPanel = (GameEndedPanel)GameObject.FindObjectOfType(typeof(GameEndedPanel));
|
SpellingBeeGameEndedPanel SpellingBeeGameEndedPanel = (SpellingBeeGameEndedPanel)GameObject.FindObjectOfType(typeof(SpellingBeeGameEndedPanel));
|
||||||
Assert.NotNull(gameEndedPanel);
|
Assert.NotNull(SpellingBeeGameEndedPanel);
|
||||||
Assert.AreEqual("GEWONNEN", gameEndedPanel.endText.text);
|
Assert.AreEqual("GEWONNEN", SpellingBeeGameEndedPanel.endText.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
[UnityTest]
|
[UnityTest]
|
||||||
@@ -64,8 +64,8 @@ public class SpellingBeeControllerTests
|
|||||||
spellingBeeController.AddSeconds(-60);
|
spellingBeeController.AddSeconds(-60);
|
||||||
|
|
||||||
yield return new WaitForSeconds(0.1f);
|
yield return new WaitForSeconds(0.1f);
|
||||||
GameEndedPanel gameEndedPanel = (GameEndedPanel)GameObject.FindObjectOfType(typeof(GameEndedPanel));
|
SpellingBeeGameEndedPanel SpellingBeeGameEndedPanel = (SpellingBeeGameEndedPanel)GameObject.FindObjectOfType(typeof(SpellingBeeGameEndedPanel));
|
||||||
Assert.NotNull(gameEndedPanel);
|
Assert.NotNull(SpellingBeeGameEndedPanel);
|
||||||
Assert.AreEqual("VERLOREN", gameEndedPanel.endText.text);
|
Assert.AreEqual("VERLOREN", SpellingBeeGameEndedPanel.endText.text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
"SpellingBeeScripts",
|
"SpellingBeeScripts",
|
||||||
"AccountsScripts",
|
"AccountsScripts",
|
||||||
"SystemArchitecture",
|
"SystemArchitecture",
|
||||||
"SignPredictor"
|
"SignPredictor",
|
||||||
|
"MinigameScripts"
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
|
|||||||
@@ -1432,6 +1432,8 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 5aa929dce1f59b340b4a0cca1bb68edc, type: 3}
|
m_Script: {fileID: 11500000, guid: 5aa929dce1f59b340b4a0cca1bb68edc, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
scoreboardEntriesContainer: {fileID: 1499197559}
|
||||||
|
scoreboardEntry: {fileID: 9154151134820372555, guid: d4a3a228b08d61847acc6da35b44e52c, type: 3}
|
||||||
endText: {fileID: 1502459770}
|
endText: {fileID: 1502459770}
|
||||||
lpmText: {fileID: 1172084829}
|
lpmText: {fileID: 1172084829}
|
||||||
lettersRightText: {fileID: 994850063}
|
lettersRightText: {fileID: 994850063}
|
||||||
@@ -1441,8 +1443,6 @@ MonoBehaviour:
|
|||||||
wordsText: {fileID: 1754130538}
|
wordsText: {fileID: 1754130538}
|
||||||
timeText: {fileID: 1052827058}
|
timeText: {fileID: 1052827058}
|
||||||
scoreText: {fileID: 653157662}
|
scoreText: {fileID: 653157662}
|
||||||
scoreboardEntriesContainer: {fileID: 1499197559}
|
|
||||||
scoreboardEntry: {fileID: 9154151134820372555, guid: d4a3a228b08d61847acc6da35b44e52c, type: 3}
|
|
||||||
--- !u!1 &778704239
|
--- !u!1 &778704239
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -3982,21 +3982,20 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
signPredictor: {fileID: 1592592444}
|
signPredictor: {fileID: 1592592444}
|
||||||
|
minigamelist: {fileID: 11400000, guid: 51453f9b41bc72f468ba3e67ab622f8f, type: 2}
|
||||||
|
feedbackProgress: {fileID: 967164046}
|
||||||
|
webcamScreen: {fileID: 1743003084}
|
||||||
|
gameEndedPanel: {fileID: 757133117}
|
||||||
themeList: {fileID: 11400000, guid: a247e2ce790f0f746a3bc521e6ab7d58, type: 2}
|
themeList: {fileID: 11400000, guid: a247e2ce790f0f746a3bc521e6ab7d58, type: 2}
|
||||||
fingerspelling: {fileID: 11400000, guid: e02921b294fdad940b6e4d57e716d3bf, type: 2}
|
fingerspelling: {fileID: 11400000, guid: e02921b294fdad940b6e4d57e716d3bf, type: 2}
|
||||||
minigame: {fileID: 11400000, guid: 8a087d241d652634eb4f6352267ea7dc, type: 2}
|
|
||||||
minigamelist: {fileID: 11400000, guid: 51453f9b41bc72f468ba3e67ab622f8f, type: 2}
|
|
||||||
letterPrefab: {fileID: 4639383499500021565, guid: c3e66e8957864914cb022af914df6a28, type: 3}
|
letterPrefab: {fileID: 4639383499500021565, guid: c3e66e8957864914cb022af914df6a28, type: 3}
|
||||||
letterContainer: {fileID: 1346005056}
|
letterContainer: {fileID: 1346005056}
|
||||||
wordImage: {fileID: 1338727891}
|
wordImage: {fileID: 1338727891}
|
||||||
timerText: {fileID: 1843239267}
|
timerText: {fileID: 1843239267}
|
||||||
bonusTimeText: {fileID: 1812475780}
|
bonusTimeText: {fileID: 1812475780}
|
||||||
Scoreboard: {fileID: 862382568}
|
Scoreboard: {fileID: 862382568}
|
||||||
gameEndedPanel: {fileID: 757133117}
|
|
||||||
feedbackText: {fileID: 967164047}
|
feedbackText: {fileID: 967164047}
|
||||||
feedbackProgress: {fileID: 967164046}
|
|
||||||
feedbackProgressImage: {fileID: 967164045}
|
feedbackProgressImage: {fileID: 967164045}
|
||||||
webcamScreen: {fileID: 1743003084}
|
|
||||||
scoreDisplay: {fileID: 1985911006}
|
scoreDisplay: {fileID: 1985911006}
|
||||||
scoreBonus: {fileID: 1130901870}
|
scoreBonus: {fileID: 1130901870}
|
||||||
--- !u!1 &1499197558
|
--- !u!1 &1499197558
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using TMPro;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public partial class SpellingBeeController : AbstractFeedback
|
public partial class SpellingBeeController : AbstractMinigameController
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All of the words that can be used in this session
|
/// All of the words that can be used in this session
|
||||||
@@ -45,11 +45,6 @@ public partial class SpellingBeeController : AbstractFeedback
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private float timerValue;
|
private float timerValue;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Indicates if the game is still going
|
|
||||||
/// </summary>
|
|
||||||
private bool gameEnded;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of learnables to get the threshold for the letters
|
/// List of learnables to get the threshold for the letters
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -81,22 +76,6 @@ public partial class SpellingBeeController : AbstractFeedback
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private DateTime startTime;
|
private DateTime startTime;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference to the current user
|
|
||||||
/// </summary>
|
|
||||||
private User user;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference to the minigame ScriptableObject
|
|
||||||
/// </summary>
|
|
||||||
public Minigame minigame;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// We keep the minigamelist as well so that the minigame-index doesn't get reset
|
|
||||||
/// DO NOT REMOVE
|
|
||||||
/// </summary>
|
|
||||||
public MinigameList minigamelist;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Letter prefab
|
/// Letter prefab
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -137,21 +116,11 @@ public partial class SpellingBeeController : AbstractFeedback
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Transform Scoreboard;
|
public Transform Scoreboard;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference to the gameEnded panel, so we can update its display
|
|
||||||
/// </summary>
|
|
||||||
public GameObject gameEndedPanel;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reference to the feedback field
|
/// Reference to the feedback field
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TMP_Text feedbackText;
|
public TMP_Text feedbackText;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference to the progress bar
|
|
||||||
/// </summary>
|
|
||||||
public Slider feedbackProgress;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reference to the progress bar image, so we can add fancy colors
|
/// Reference to the progress bar image, so we can add fancy colors
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -172,11 +141,6 @@ public partial class SpellingBeeController : AbstractFeedback
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected string previousIncorrectSign = null;
|
protected string previousIncorrectSign = null;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reference used to set the webcam for the SignPredictor
|
|
||||||
/// </summary>
|
|
||||||
public RawImage webcamScreen;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reference to display the score
|
/// Reference to display the score
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -198,57 +162,11 @@ public partial class SpellingBeeController : AbstractFeedback
|
|||||||
private int incorrectLettersScore = -5;
|
private int incorrectLettersScore = -5;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Start is called before the first frame update
|
/// Set the AbstractMinigameController variable to inform it of the theme for the signPredictor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Start()
|
protected override Theme signPredictorTheme
|
||||||
{
|
{
|
||||||
signPredictor.SetModel(ModelIndex.FINGERSPELLING);
|
get { return fingerspelling; }
|
||||||
signPredictor.SwapScreen(webcamScreen);
|
|
||||||
AddSelfAsListener();
|
|
||||||
|
|
||||||
StartController();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Is called at the start of the scene AND when the game is replayed
|
|
||||||
/// </summary>
|
|
||||||
public void StartController()
|
|
||||||
{
|
|
||||||
correctLetters = 0;
|
|
||||||
incorrectLetters = 0;
|
|
||||||
|
|
||||||
words.Clear();
|
|
||||||
// We use -1 instead of 0 so SetNextWord can simply increment it each time
|
|
||||||
spelledWords = -1;
|
|
||||||
wordIndex = 0;
|
|
||||||
|
|
||||||
gameEnded = false;
|
|
||||||
timerValue = 30.0f;
|
|
||||||
bonusActiveRemaining = 0.0f;
|
|
||||||
startTime = DateTime.Now;
|
|
||||||
|
|
||||||
gameEndedPanel.SetActive(false);
|
|
||||||
bonusTimeText.SetActive(false);
|
|
||||||
|
|
||||||
// Create entry in current user for keeping track of progress
|
|
||||||
user = UserList.GetCurrentUser();
|
|
||||||
var progress = user.GetMinigameProgress(minigame.index);
|
|
||||||
if (progress == null)
|
|
||||||
{
|
|
||||||
progress = new PersistentDataController.SavedMinigameProgress();
|
|
||||||
progress.minigameIndex = MinigameIndex.SPELLING_BEE;
|
|
||||||
user.AddMinigameProgress(progress);
|
|
||||||
}
|
|
||||||
UserList.Save();
|
|
||||||
|
|
||||||
currentTheme = minigame.themeList.themes[minigame.themeList.currentThemeIndex];
|
|
||||||
//feedback.signPredictor.SetModel(currentTheme.modelIndex);
|
|
||||||
words.AddRange(currentTheme.learnables);
|
|
||||||
ShuffleWords();
|
|
||||||
NextWord();
|
|
||||||
|
|
||||||
scoreDisplay.text = $"Score: {CalculateScore()}";
|
|
||||||
scoreBonus.text = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -256,7 +174,7 @@ public partial class SpellingBeeController : AbstractFeedback
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
if (!gameEnded)
|
if (gameIsActive)
|
||||||
{
|
{
|
||||||
timerValue -= Time.deltaTime;
|
timerValue -= Time.deltaTime;
|
||||||
if (bonusActiveRemaining <= 0.0 && bonusTimeText.activeSelf)
|
if (bonusActiveRemaining <= 0.0 && bonusTimeText.activeSelf)
|
||||||
@@ -272,7 +190,8 @@ public partial class SpellingBeeController : AbstractFeedback
|
|||||||
if (timerValue <= 0.0f)
|
if (timerValue <= 0.0f)
|
||||||
{
|
{
|
||||||
timerValue = 0.0f;
|
timerValue = 0.0f;
|
||||||
ActivateGameOver();
|
//ActivateGameOver();
|
||||||
|
ActivateEnd(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int minutes = Mathf.FloorToInt(timerValue / 60.0f);
|
int minutes = Mathf.FloorToInt(timerValue / 60.0f);
|
||||||
@@ -302,89 +221,11 @@ public partial class SpellingBeeController : AbstractFeedback
|
|||||||
/// Calculate the score
|
/// Calculate the score
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The calculated score</returns>
|
/// <returns>The calculated score</returns>
|
||||||
public int CalculateScore()
|
public override int CalculateScore()
|
||||||
{
|
{
|
||||||
return correctLetters * correctLettersScore + incorrectLetters * incorrectLettersScore;
|
return correctLetters * correctLettersScore + incorrectLetters * incorrectLettersScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Displays the game over panel and score values
|
|
||||||
/// </summary>
|
|
||||||
public void ActivateGameOver()
|
|
||||||
{
|
|
||||||
gameEnded = true;
|
|
||||||
DeleteWord();
|
|
||||||
|
|
||||||
// Save the scores and show the scoreboard
|
|
||||||
SaveScores();
|
|
||||||
gameEndedPanel.GetComponent<GameEndedPanel>().GenerateContent(
|
|
||||||
startTime: startTime,
|
|
||||||
totalWords: spelledWords,
|
|
||||||
correctLetters: correctLetters,
|
|
||||||
incorrectLetters: incorrectLetters,
|
|
||||||
result: "VERLOREN",
|
|
||||||
score: CalculateScore()
|
|
||||||
);
|
|
||||||
|
|
||||||
gameEndedPanel.SetActive(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Display win screen
|
|
||||||
/// </summary>
|
|
||||||
public void ActivateWin()
|
|
||||||
{
|
|
||||||
gameEnded = true;
|
|
||||||
DeleteWord();
|
|
||||||
|
|
||||||
// Save the scores and show the scoreboard
|
|
||||||
SaveScores();
|
|
||||||
gameEndedPanel.GetComponent<GameEndedPanel>().GenerateContent(
|
|
||||||
startTime: startTime,
|
|
||||||
totalWords: spelledWords,
|
|
||||||
correctLetters: correctLetters,
|
|
||||||
incorrectLetters: incorrectLetters,
|
|
||||||
result: "GEWONNEN",
|
|
||||||
score: CalculateScore()
|
|
||||||
);
|
|
||||||
|
|
||||||
gameEndedPanel.SetActive(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Update and save the scores
|
|
||||||
/// </summary>
|
|
||||||
public void SaveScores()
|
|
||||||
{
|
|
||||||
// Calculate new score
|
|
||||||
int newScore = CalculateScore();
|
|
||||||
|
|
||||||
// Save the score as a tuple: < int score, string time ago>
|
|
||||||
Score score = new Score();
|
|
||||||
score.scoreValue = newScore;
|
|
||||||
score.time = DateTime.Now.ToString();
|
|
||||||
|
|
||||||
// Save the new score
|
|
||||||
var progress = user.GetMinigameProgress(minigame.index);
|
|
||||||
|
|
||||||
// Get the current list of scores
|
|
||||||
List<Score> latestScores = progress.latestScores;
|
|
||||||
List<Score> highestScores = progress.highestScores;
|
|
||||||
|
|
||||||
// Add the new score
|
|
||||||
latestScores.Add(score);
|
|
||||||
highestScores.Add(score);
|
|
||||||
|
|
||||||
// Sort the scores
|
|
||||||
highestScores.Sort((a, b) => b.scoreValue.CompareTo(a.scoreValue));
|
|
||||||
|
|
||||||
// Only save the top 10 scores, so this list doesn't keep growing endlessly
|
|
||||||
progress.latestScores = latestScores.Take(10).ToList();
|
|
||||||
progress.highestScores = highestScores.Take(10).ToList();
|
|
||||||
|
|
||||||
UserList.Save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete all letter objects
|
/// Delete all letter objects
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -414,7 +255,7 @@ public partial class SpellingBeeController : AbstractFeedback
|
|||||||
/// <param name="successful">true if the letter was correctly signed, false otherwise</param>
|
/// <param name="successful">true if the letter was correctly signed, false otherwise</param>
|
||||||
public void NextLetter(bool successful)
|
public void NextLetter(bool successful)
|
||||||
{
|
{
|
||||||
if (gameEnded) { return; }
|
if (!gameIsActive) { return; }
|
||||||
|
|
||||||
// Change color of current letter (skip spaces)
|
// Change color of current letter (skip spaces)
|
||||||
if (successful)
|
if (successful)
|
||||||
@@ -469,7 +310,8 @@ public partial class SpellingBeeController : AbstractFeedback
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ActivateWin();
|
//ActivateWin();
|
||||||
|
ActivateEnd(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -514,7 +356,7 @@ public partial class SpellingBeeController : AbstractFeedback
|
|||||||
Learnable letter = fingerspelling.learnables.Find(l => l.name == sign);
|
Learnable letter = fingerspelling.learnables.Find(l => l.name == sign);
|
||||||
return letter.thresholdPercentage;
|
return letter.thresholdPercentage;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The updateFunction that is called when new probabilities become available
|
/// The updateFunction that is called when new probabilities become available
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -525,7 +367,7 @@ public partial class SpellingBeeController : AbstractFeedback
|
|||||||
string currentSign = GetSign();
|
string currentSign = GetSign();
|
||||||
// Get the predicted sign
|
// Get the predicted sign
|
||||||
if (signPredictor != null && signPredictor.learnableProbabilities != null &&
|
if (signPredictor != null && signPredictor.learnableProbabilities != null &&
|
||||||
currentSign != null && signPredictor.learnableProbabilities.ContainsKey(currentSign))
|
currentSign != null && signPredictor.learnableProbabilities.ContainsKey(currentSign) && gameIsActive)
|
||||||
{
|
{
|
||||||
float accCurrentSign = signPredictor.learnableProbabilities[currentSign];
|
float accCurrentSign = signPredictor.learnableProbabilities[currentSign];
|
||||||
float thresholdCurrentSign = GetTresholdPercentage(currentSign);
|
float thresholdCurrentSign = GetTresholdPercentage(currentSign);
|
||||||
@@ -613,6 +455,7 @@ public partial class SpellingBeeController : AbstractFeedback
|
|||||||
}
|
}
|
||||||
yield return null;
|
yield return null;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Function to get the current letter that needs to be signed
|
/// Function to get the current letter that needs to be signed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -638,4 +481,157 @@ public partial class SpellingBeeController : AbstractFeedback
|
|||||||
}
|
}
|
||||||
NextLetter(successful);
|
NextLetter(successful);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The logic to process the signs sent by the signPredictor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="accuracy">The accuracy of the passed sign</param>
|
||||||
|
/// <param name="predictedSign">The name of the passed sign</param>
|
||||||
|
protected override void ProcessMostProbableSign(float accuracy, string predictedSign)
|
||||||
|
{
|
||||||
|
string currentSign = GetSign();
|
||||||
|
float accPredictSign = accuracy;
|
||||||
|
float accCurrentSign = signPredictor.learnableProbabilities[currentSign];
|
||||||
|
float thresholdCurrentSign = GetTresholdPercentage(currentSign);
|
||||||
|
float thresholdPredictedSign = GetTresholdPercentage(predictedSign);
|
||||||
|
|
||||||
|
// If there is a feedback-object, we wil change its appearance
|
||||||
|
if (feedbackText != null && feedbackProgressImage != null)
|
||||||
|
{
|
||||||
|
Color col;
|
||||||
|
if (accPredictSign > thresholdCurrentSign)
|
||||||
|
{
|
||||||
|
feedbackText.text = "Goed";
|
||||||
|
col = new Color(0x8b / 255.0f, 0xd4 / 255.0f, 0x5e / 255.0f);
|
||||||
|
}
|
||||||
|
else if (accCurrentSign > 0.9 * thresholdCurrentSign)
|
||||||
|
{
|
||||||
|
feedbackText.text = "Bijna...";
|
||||||
|
col = new Color(0xf2 / 255.0f, 0x7f / 255.0f, 0x0c / 255.0f);
|
||||||
|
}
|
||||||
|
else if (accPredictSign > thresholdPredictedSign)
|
||||||
|
{
|
||||||
|
feedbackText.text = $"Verkeerde gebaar: '{predictedSign}'";
|
||||||
|
col = new Color(0xf5 / 255.0f, 0x49 / 255.0f, 0x3d / 255.0f);
|
||||||
|
accCurrentSign = 0.0f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
feedbackText.text = "Detecteren...";
|
||||||
|
col = new Color(0xf5 / 255.0f, 0x49 / 255.0f, 0x3d / 255.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
feedbackText.color = col;
|
||||||
|
feedbackProgressImage.color = col;
|
||||||
|
|
||||||
|
float oldValue = feedbackProgress.value;
|
||||||
|
// use an exponential scale
|
||||||
|
float newValue = Mathf.Exp(4 * (Mathf.Clamp(accCurrentSign / thresholdCurrentSign, 0.0f, 1.0f) - 1.0f));
|
||||||
|
feedbackProgress.gameObject.Tween("FeedbackUpdate", oldValue, newValue, 0.2f, TweenScaleFunctions.CubicEaseInOut, (t) =>
|
||||||
|
{
|
||||||
|
if (feedbackProgress != null)
|
||||||
|
{
|
||||||
|
feedbackProgress.value = t.CurrentValue;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// The logic for the internal workings of the game
|
||||||
|
if (accPredictSign > thresholdPredictedSign)
|
||||||
|
{
|
||||||
|
// Correct sign, instantly pass it along
|
||||||
|
if (predictedSign == currentSign)
|
||||||
|
{
|
||||||
|
PredictSign(predictedSign);
|
||||||
|
timer = DateTime.Now;
|
||||||
|
predictedSign = null;
|
||||||
|
previousIncorrectSign = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Incorrect sign, wait a bit before passing it along
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (previousIncorrectSign != predictedSign)
|
||||||
|
{
|
||||||
|
timer = DateTime.Now;
|
||||||
|
previousIncorrectSign = predictedSign;
|
||||||
|
}
|
||||||
|
else if (DateTime.Now - timer > TimeSpan.FromSeconds(2.0f))
|
||||||
|
{
|
||||||
|
PredictSign(predictedSign);
|
||||||
|
timer = DateTime.Now;
|
||||||
|
predictedSign = null;
|
||||||
|
previousIncorrectSign = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The logic to set the scoreboard of spellingbee
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="victory">SHows whether or not the player won</param>
|
||||||
|
protected override void SetScoreBoard(bool victory)
|
||||||
|
{
|
||||||
|
string resultTxt;
|
||||||
|
if (victory)
|
||||||
|
{
|
||||||
|
resultTxt = "GEWONNEN";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
resultTxt = "VERLOREN";
|
||||||
|
}
|
||||||
|
// Save the scores and show the scoreboard
|
||||||
|
gameEndedPanel.GetComponent<SpellingBeeGameEndedPanel>().GenerateContent(
|
||||||
|
startTime: startTime,
|
||||||
|
totalWords: spelledWords,
|
||||||
|
correctLetters: correctLetters,
|
||||||
|
incorrectLetters: incorrectLetters,
|
||||||
|
result: resultTxt,
|
||||||
|
score: CalculateScore()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The spellinbee-specific logic that needs to be called at the start of the game
|
||||||
|
/// </summary>
|
||||||
|
protected override void StartGameLogic()
|
||||||
|
{
|
||||||
|
correctLetters = 0;
|
||||||
|
incorrectLetters = 0;
|
||||||
|
|
||||||
|
words.Clear();
|
||||||
|
// We use -1 instead of 0 so SetNextWord can simply increment it each time
|
||||||
|
spelledWords = -1;
|
||||||
|
wordIndex = 0;
|
||||||
|
|
||||||
|
gameIsActive = true;
|
||||||
|
timerValue = 30.0f;
|
||||||
|
bonusActiveRemaining = 0.0f;
|
||||||
|
startTime = DateTime.Now;
|
||||||
|
|
||||||
|
gameEndedPanel.SetActive(false);
|
||||||
|
bonusTimeText.SetActive(false);
|
||||||
|
|
||||||
|
currentTheme = minigame.themeList.themes[minigame.themeList.currentThemeIndex];
|
||||||
|
//feedback.signPredictor.SetModel(currentTheme.modelIndex);
|
||||||
|
words.AddRange(currentTheme.learnables);
|
||||||
|
ShuffleWords();
|
||||||
|
NextWord();
|
||||||
|
|
||||||
|
scoreDisplay.text = $"Score: {CalculateScore()}";
|
||||||
|
scoreBonus.text = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The spellingbee-specific logic that needs to be called at the end of a game
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="victory"></param>
|
||||||
|
protected override void EndGameLogic(bool victory)
|
||||||
|
{
|
||||||
|
gameIsActive = false;
|
||||||
|
DeleteWord();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
102
Assets/SpellingBee/Scripts/SpellingBeeGameEndedPanel.cs
Normal file
102
Assets/SpellingBee/Scripts/SpellingBeeGameEndedPanel.cs
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class SpellingBeeGameEndedPanel : AbstractGameEndedPanel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Tell the scoreboard that the scoreboard is for SpellingBee
|
||||||
|
/// </summary>
|
||||||
|
protected override MinigameIndex minigameIndex
|
||||||
|
{
|
||||||
|
get { return MinigameIndex.SPELLING_BEE; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// "VERLOREN" or "GEWONNEN"
|
||||||
|
/// </summary>
|
||||||
|
public TMP_Text endText;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// LPM
|
||||||
|
/// </summary>
|
||||||
|
public TMP_Text lpmText;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Letters ( right | wrong )
|
||||||
|
/// </summary>
|
||||||
|
public TMP_Text lettersRightText;
|
||||||
|
public TMP_Text lettersWrongText;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Letters
|
||||||
|
/// </summary>
|
||||||
|
public TMP_Text lettersTotalText;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Accuracy
|
||||||
|
/// </summary>
|
||||||
|
public TMP_Text accuracyText;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Words
|
||||||
|
/// </summary>
|
||||||
|
public TMP_Text wordsText;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Time
|
||||||
|
/// </summary>
|
||||||
|
public TMP_Text timeText;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Score
|
||||||
|
/// </summary>
|
||||||
|
public TMP_Text scoreText;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generate the content of the GameEnded panel
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="startTime">Time of starting the minigame</param>
|
||||||
|
/// <param name="totalWords">Total number of words</param>
|
||||||
|
/// <param name="correctLetters">Total number of correctly spelled letters</param>
|
||||||
|
/// <param name="incorrectLetters">Total number of incorrectly spelled letters</param>
|
||||||
|
/// <param name="result">"VERLOREN" or "GEWONNEN"</param>
|
||||||
|
/// <param name="score">Final score</param>
|
||||||
|
public void GenerateContent(DateTime startTime, int totalWords, int correctLetters, int incorrectLetters, string result, int score)
|
||||||
|
{
|
||||||
|
// Final result
|
||||||
|
endText.text = result;
|
||||||
|
|
||||||
|
// LPM
|
||||||
|
TimeSpan duration = DateTime.Now.Subtract(startTime);
|
||||||
|
lpmText.text = (60f * correctLetters / duration.TotalSeconds).ToString("#") + " LPM";
|
||||||
|
|
||||||
|
// Letters ( right | wrong ) total
|
||||||
|
lettersRightText.text = correctLetters.ToString();
|
||||||
|
lettersWrongText.text = incorrectLetters.ToString();
|
||||||
|
lettersTotalText.text = (correctLetters + incorrectLetters).ToString();
|
||||||
|
|
||||||
|
// Accuracy
|
||||||
|
if (correctLetters + incorrectLetters > 0)
|
||||||
|
{
|
||||||
|
accuracyText.text = ((correctLetters) * 100f / (correctLetters + incorrectLetters)).ToString("#.##") + "%";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
accuracyText.text = "-";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Words
|
||||||
|
wordsText.text = $"{totalWords}";
|
||||||
|
|
||||||
|
// Time
|
||||||
|
timeText.text = duration.ToString(@"mm\:ss");
|
||||||
|
|
||||||
|
// Score
|
||||||
|
scoreText.text = $"Score: {score}";
|
||||||
|
SetScoreBoard();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,8 @@
|
|||||||
"GUID:d0b6b39a21908f94fbbd9f2c196a9725",
|
"GUID:d0b6b39a21908f94fbbd9f2c196a9725",
|
||||||
"GUID:58e104b97fb3752438ada2902a36dcbf",
|
"GUID:58e104b97fb3752438ada2902a36dcbf",
|
||||||
"GUID:e83ddf9a537a96b4a804a16bb7872ec1",
|
"GUID:e83ddf9a537a96b4a804a16bb7872ec1",
|
||||||
"GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25"
|
"GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25",
|
||||||
|
"GUID:403dd94a93598934eb522dc36df43d7b"
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
|
|||||||
@@ -168,7 +168,8 @@ PlayerSettings:
|
|||||||
- {fileID: 0}
|
- {fileID: 0}
|
||||||
- {fileID: 0}
|
- {fileID: 0}
|
||||||
- {fileID: 0}
|
- {fileID: 0}
|
||||||
- {fileID: 11400000, guid: 57fdfdc7df920454ba35444c783867d8, type: 2}
|
- {fileID: 0}
|
||||||
|
- {fileID: 0}
|
||||||
metroInputSource: 0
|
metroInputSource: 0
|
||||||
wsaTransparentSwapchain: 0
|
wsaTransparentSwapchain: 0
|
||||||
m_HolographicPauseOnTrackingLoss: 1
|
m_HolographicPauseOnTrackingLoss: 1
|
||||||
|
|||||||
Reference in New Issue
Block a user