using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; using UnityEngine.Video; /// /// Class to handle panel with image, video and webcam /// public class PanelWithVideoAndImage : MonoBehaviour { /// /// Reference to the feedback progress bar /// public GameObject feedbackProgressObject; /// /// Reference to the object containing the message for when the course is loaded in preview mode /// public GameObject previewMessage; /// /// True if the course is loaded in preview mode, false otherwise /// public bool isPreview; /// /// Video 'play' sprite /// public Sprite playSprite; /// /// Video 'pause' sprite /// public Sprite pauseSprite; /// /// Reference to instructional video player /// public VideoPlayer videoPlayer; /// /// Refrence to the video play/pause button /// public Image playButton; /// /// Reference to the webcam /// public RawImage webcamScreen; /// /// Reference to the image for displaying the current words sprite /// public Transform signImageContainer; /// /// Reference to the prefab for displaying the image /// public GameObject signImagePrefab; /// /// Reference to the feedback field /// public TMP_Text feedbackText; /// /// Reference to the progress bar /// public Slider feedbackProgressBar; /// /// Reference to the progress bar image, so we can add fancy colors /// public Image feedbackProgressImage; /// /// Reference to the list of learnables /// public List signs; /// /// Index of the current learnable in the list with learnables /// public int currentSignIndex; /// /// Update the display of this panel /// public void Display() { Learnable currentSign = signs[currentSignIndex]; videoPlayer.aspectRatio = VideoAspectRatio.FitInside; videoPlayer.clip = currentSign.clip; videoPlayer.Play(); feedbackProgressObject.SetActive(!isPreview); previewMessage.SetActive(isPreview); List sprites = new List() { currentSign.image }; if (currentSign.handGuide != null) sprites.Add(currentSign.handGuide); foreach (Sprite s in sprites) { GameObject sprite = GameObject.Instantiate(signImagePrefab, signImageContainer); sprite.GetComponent().sprite = s; } } /// /// This function is called when the pause-button is pressed on the video. /// It switches between playing and pausing the video. /// It then makes the button invisible when the video is playing, or visible when it's paused. /// public void TogglePlayPause() { if (!videoPlayer.isPlaying) { // Play video and switch sprite of button playButton.sprite = pauseSprite; videoPlayer.Play(); } else { // Pause video and and switch sprite of button playButton.sprite = playSprite; videoPlayer.Pause(); } } }