From 02ff49a3473f77f7c087f55fa1333c472f4a4b26 Mon Sep 17 00:00:00 2001 From: Jerome Coudron Date: Fri, 10 Mar 2023 11:06:33 +0000 Subject: [PATCH] Added documentation for startpause and webcam --- Assets/Courses/Scripts/StartPause.cs | 107 ++++++++++++++++++++++----- Assets/Courses/Scripts/Webcam.cs | 74 ++++++++++++++---- 2 files changed, 148 insertions(+), 33 deletions(-) diff --git a/Assets/Courses/Scripts/StartPause.cs b/Assets/Courses/Scripts/StartPause.cs index 991b1c7..8eb09b4 100644 --- a/Assets/Courses/Scripts/StartPause.cs +++ b/Assets/Courses/Scripts/StartPause.cs @@ -3,48 +3,94 @@ using UnityEngine; using UnityEngine.UI; using UnityEngine.Video; +/// +/// This class is responsible for loading all data from the Course-scriptableobject. +/// Specifically it fetches and displays the correct title, videos and images while also keeping track of the progress. +/// public class StartPause : MonoBehaviour { - [Header("UI References")] - // Reference to instructional video player + /// + /// Reference to instructional video player + /// public VideoPlayer player; - // Reference to pause button + /// + /// Reference to pause button + /// public Button button; - // Reference to sprite for the pause button + + /// + /// Reference to sprite for the pause button + /// public Sprite pauseSprite; - // Reference to the image for displaying the current words sprite + + /// + /// Reference to the image for displaying the current words sprite + /// public Image wordImage; - // Reference to the text object for displaying the current word + + /// + /// Reference to the text object for displaying the current word + /// public TextMeshProUGUI title; - [Header("User")] - // Reference to user list to get current user + + /// + /// Reference to user list to get current user + /// public UserList userList; - // The current user + + /// + /// The current user + /// private User user; - // Current user progress for this course + + /// + /// Current user progress for this course + /// private Progress progress = null; - [Header("Course")] - // ScriptableObject with list of all courses + + /// + /// ScriptableObject with list of all courses + /// public CourseList courselist; - // Reference to Course ScriptableObject + + /// + /// Reference to Course ScriptableObject + /// private Course course; - // Index of the current word/letter in the course.learnables list + + /// + /// Index of the current word/letter in the course.learnables list + /// private int currentWordIndex = 0; - // This holds the amount of words in the course + + /// + /// This holds the amount of words in the course + /// private int maxWords; - // Number of correct words so far - // (can be modified to a list or something like that to give better feedback) + + /// + /// Number of correct words so far + /// (can be modified to a list or something like that to give better feedback) + /// private int correctWords = 0; + + /// + /// This function is called when the script is initialised. + /// It takes the correct course from the courselist, using the courseIndex. + /// Then it checks whether or not the User has started the course yet, to possibly create a new progress atribute for the course. + /// Then it sets up the course-screen to display relevant information from the course-scriptable. + /// public void Awake() { // Setting up course course = courselist.courses[courselist.currentCourseIndex]; maxWords = course.learnables.Count; + // Create entry in current user for keeping track of progress user = userList.GetCurrentUser(); progress = user.courses.Find((p) => p != null && p.Get("courseIndex") == course.index); @@ -65,6 +111,10 @@ public class StartPause : MonoBehaviour } // These two functions generate video and image from files + /// + /// This function uses the word_i integer to grab the correct video from the course.learnabels. + /// When it has this video, it will load it into the videoplayer and set it to start. + /// private void NextVideo() { player.clip = course.learnables[currentWordIndex].clip; @@ -76,13 +126,20 @@ public class StartPause : MonoBehaviour button.image.color = col; } - // This doesn't work + /// + /// This function uses the word_i integer to grab the correct image from the course.learnabels. + /// Then it simply loads it into wordImage so that it can be displayed. + /// private void NextImage() { wordImage.sprite = course.learnables[currentWordIndex].image; } - // Activate by pressing the center of the screen + /// + /// 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 Pause() { if (!player.isPlaying) @@ -104,8 +161,16 @@ public class StartPause : MonoBehaviour } // Press next-sign button for next word + /// + /// This function is called when the next-sign button is pressed. + /// It increased the wordindex and fetches new videos/images if index public void NextSign() { + // If the currentindex >= maxwords, it indicated that the course is already finished, running the next code is the meaningless. + if (currentWordIndex >= maxWords) { return; } + // Goto the next word/letter currentWordIndex++; @@ -127,6 +192,10 @@ public class StartPause : MonoBehaviour } } + + /// + /// finishcourse is called to save the "finished" progress to the user. + /// public void FinishCourse() { // TODO: update progress (maybe this can also be at the `NextSign()`-method) diff --git a/Assets/Courses/Scripts/Webcam.cs b/Assets/Courses/Scripts/Webcam.cs index 5bc00dd..6b2a8e4 100644 --- a/Assets/Courses/Scripts/Webcam.cs +++ b/Assets/Courses/Scripts/Webcam.cs @@ -3,40 +3,78 @@ using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; +/// +/// This class is dedicated to the camera and other actions that later could be connected to it, like the feedback. +/// It is responsible for finding working cameras, displaying them and being able to toggle between them. +/// This class also holds temporary code to display feedback via a button. +/// public class Webcam : MonoBehaviour { + + /// + /// Index to indicate which camera is being used + /// int camdex = 0; + + + /// + /// This texture is used as an intermidiary between the camera output and the display image + /// WebCamTexture tex; + /// + /// Reference to the RawImage that will display the video + /// public RawImage display; + + /// + /// Reference to the button that is currently used to test the feedback-display + /// public Button feedback; + + /// + /// This is a reference to the PANEL that holds the feedbackwindow + /// public GameObject popup; + + /// + /// This is a reference to the textfield that holds the part of the feedback-window that will change: bad/good/excellent + /// public TextMeshProUGUI dynamic; + /// + /// This function is called at the start of the frame. + /// It inactivatis the popup, finds a webcam to use and links it via the WebcamTexture to the display RawImage. + /// void Awake() { popup.SetActive(false); + if (WebCamTexture.devices.Length > 0) { + WebCamDevice device = WebCamTexture.devices[camdex]; + tex = new WebCamTexture(device.name); + display.texture = tex; - WebCamDevice device = WebCamTexture.devices[camdex]; - tex = new WebCamTexture(device.name); - display.texture = tex; - - tex.Play(); + tex.Play(); + } } + /// + /// So long as there are cameras to use, you swap the camera you are using to another in the list. + /// public void SwapCam() { if (WebCamTexture.devices.Length > 0) { // Stop the old camera - display.texture = null; - tex.Stop(); - tex = null; - - // Find the new camera - camdex += 1; - camdex %= WebCamTexture.devices.Length; - + // If there was no camera playing before, then you dont have to reset the texture, as it wasn't assigned in the first place. + if (tex.isPlaying) { + display.texture = null; + tex.Stop(); + tex = null; + } + // Find the new camera + camdex += 1; + camdex %= WebCamTexture.devices.Length; // Start the new camera WebCamDevice device = WebCamTexture.devices[camdex]; tex = new WebCamTexture(device.name); @@ -46,7 +84,11 @@ public class Webcam : MonoBehaviour } } - // Scene changing is implemented here to avoid problems with webcam + /// + /// The notmal sceneChanger cannot be used here since the camera also needs to be stopped. + /// This extra functionality is implemented in this function + /// + /// The path for the scene you want to travel to, assuming root-directory is Assets public void LoadScene(string sceneName) { display.texture = null; @@ -56,6 +98,10 @@ public class Webcam : MonoBehaviour SceneManager.LoadScene(sceneName); } + /// + /// This function toggles between inactivity and activity for the popup panel. + /// This will be changed later when the model gets integrated, probably being timed to dissapear. + /// public void Show_feedback() { if (popup.activeSelf)