//using Mediapipe.Unity.Tutorial; using Mediapipe.Unity.Tutorial; using System.Collections; using TMPro; using UnityEngine; using UnityEngine.UI; // for your own scripts make sure to add the following line: using DigitalRuby.Tween; using UnityEngine.SceneManagement; namespace Assets.Courses.Scripts { public class Feedback : MonoBehaviour { /// /// Reference to the feedback field /// public TMP_Text feedback; /// /// Reference to the sign predictor /// public Wesign_extractor signPredictor; /// /// Reference to the TemplateCourse /// public TemplateCourse templateCourse; /// /// Reference to the progress bar /// public GameObject progress; /// /// Start is called before the first frame update /// void Start() { // Start the coroutine to update the scale every 200 milliseconds StartCoroutine(UpdateFeedback()); } /// /// UpdateScale updates the progress bar every 200ms, updated the feedback text, and progress bar color /// If a high enough accuracy is detected, it will go to the next sign /// /// IEnumerator UpdateFeedback() { while (true) { // Get current sign char currentSign = (char)(65 + templateCourse.GetWordIndex()); //Debug.Log(currentSign); // Get the predicted sign if (signPredictor != null && signPredictor.letterProbabilities != null && signPredictor.letterProbabilities.ContainsKey(currentSign)) { int accuracy = (int)(signPredictor.letterProbabilities[currentSign] * 100); if (accuracy > 98) { feedback.text = "Perfect!!!"; feedback.color = Color.green; progress.GetComponent().color = Color.green; } else if (accuracy > 95) { feedback.text = "Super!"; feedback.color = Color.green; progress.GetComponent().color = Color.green; } else if (accuracy > 90) { feedback.text = "Goed"; feedback.color = Color.green; progress.GetComponent().color = Color.green; } else if (accuracy > 80) { feedback.text = "Bijna..."; feedback.color = new Color(0xFF, 0xE5, 0x00); progress.GetComponent().color = new Color(0xFF, 0xE5, 0x00); } else { feedback.text = "Detecteren ..."; feedback.color = Color.red; progress.GetComponent().color = Color.red; } // use an exponential scale float newScale = Mathf.Exp(((float)accuracy / 24.5f) - 4); Vector3 newScaleVector = new Vector3(newScale, progress.transform.localScale.y, progress.transform.localScale.z); System.Action> updateProgressScale = (t) => { if (progress != null) { progress.transform.localScale = t.CurrentValue; } }; progress.Tween("ScaleProgress", progress.transform.localScale, newScaleVector, 0.2f, TweenScaleFunctions.CubicEaseInOut, updateProgressScale); if (accuracy > 90) { // Wait and go to next sign yield return new WaitForSeconds(1); templateCourse.NextSign(); } } else { progress.transform.localScale = new Vector3(0f, progress.transform.localScale.y, progress.transform.localScale.z); //Debug.Log("doesn't contain A"); } // Wait for 200 milliseconds before updating the scale again yield return new WaitForSeconds(0.2f); } } } }