using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; using UnityEngine.Video; public class PanelMultipleChoice : MonoBehaviour { /// /// Reference to the webcam screen /// public RawImage webcamScreen; /// /// Video 'play' sprite /// public Sprite playSprite; /// /// Video 'pause' sprite /// public Sprite pauseSprite; /// /// Reference to its course controller to be able to go to call NextSignMultipleChoice to go to the next panel /// public CoursesController courseController; /// /// Reference to instructional video player /// public VideoPlayer videoPlayer; /// /// Refrence to the video play/pause button /// public Image playButton; /// /// Reference to the image for displaying the current words sprite /// public Transform optionContainer; /// /// Reference to the image for displaying the current words sprite, for a fingerspelling courses /// public Transform optionFingerspellingContainer; /// /// Reference to the option prefab /// public GameObject optionPrefab; /// /// Reference to the option prefab, for a fingerspelling course /// public GameObject optionFingerspellingPrefab; /// /// Reference to the saved progress /// public PersistentDataController.SavedCourseProgress progress; /// /// The current sign that will be displayed /// private Learnable currentSign; /// /// Reference to all signs in this course /// public List signs; /// /// Index of the current sign /// public int currentSignIndex; /// /// Boolean used to check whether the current course is a fingerspelling course /// public bool isFingerSpelling; /// /// Boolean used to check whether the user has already answered the question /// private bool hasAnswered = false; /// /// Get a list of wrongs answers /// /// The index of the correct sign /// public List GetWrongOptions(int notThisIndex) { List randomSigns = new List(); // TODO: find more koosjer way to do this while (randomSigns.Count < 3) { int index = progress.GetRandomLearnable().index; if (index != notThisIndex && !randomSigns.Contains(signs[index])) { randomSigns.Add(signs[index]); } } return randomSigns; } /// /// Update the display of this panel /// public void Display() { currentSign = signs[currentSignIndex]; videoPlayer.aspectRatio = VideoAspectRatio.FitInside; videoPlayer.clip = currentSign.clip; videoPlayer.Play(); // Gets three random selected signs from the list signs which are not equal to currentSign List allOptions = GetWrongOptions(currentSignIndex); // Add the correct sign at a random position in the list of all options int randomIndex = UnityEngine.Random.Range(0, allOptions.Count + 1); allOptions.Insert(randomIndex, currentSign); var prefab = isFingerSpelling ? optionFingerspellingPrefab : optionPrefab; var container = isFingerSpelling ? optionFingerspellingContainer : optionContainer; foreach (Learnable option in allOptions) { GameObject multipleChoiceOption = GameObject.Instantiate(prefab, container); if (!isFingerSpelling) multipleChoiceOption.transform.Find("TextOption").GetComponent().text = option.name; multipleChoiceOption.transform.Find("ImageOption").GetComponent().sprite = option.image; Button button = multipleChoiceOption.GetComponent