Added documentation for startpause and webcam

This commit is contained in:
Jerome Coudron
2023-03-10 11:06:33 +00:00
parent 594e95d7e1
commit 02ff49a347
2 changed files with 148 additions and 33 deletions

View File

@@ -3,48 +3,94 @@ using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
/// <summary>
/// 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.
/// </summary>
public class StartPause : MonoBehaviour
{
[Header("UI References")]
// Reference to instructional video player
/// <summary>
/// Reference to instructional video player
/// </summary>
public VideoPlayer player;
// Reference to pause button
/// <summary>
/// Reference to pause button
/// </summary>
public Button button;
// Reference to sprite for the pause button
/// <summary>
/// Reference to sprite for the pause button
/// </summary>
public Sprite pauseSprite;
// Reference to the image for displaying the current words sprite
/// <summary>
/// Reference to the image for displaying the current words sprite
/// </summary>
public Image wordImage;
// Reference to the text object for displaying the current word
/// <summary>
/// Reference to the text object for displaying the current word
/// </summary>
public TextMeshProUGUI title;
[Header("User")]
// Reference to user list to get current user
/// <summary>
/// Reference to user list to get current user
/// </summary>
public UserList userList;
// The current user
/// <summary>
/// The current user
/// </summary>
private User user;
// Current user progress for this course
/// <summary>
/// Current user progress for this course
/// </summary>
private Progress progress = null;
[Header("Course")]
// ScriptableObject with list of all courses
/// <summary>
/// ScriptableObject with list of all courses
/// </summary>
public CourseList courselist;
// Reference to Course ScriptableObject
/// <summary>
/// Reference to Course ScriptableObject
/// </summary>
private Course course;
// Index of the current word/letter in the course.learnables list
/// <summary>
/// Index of the current word/letter in the course.learnables list
/// </summary>
private int currentWordIndex = 0;
// This holds the amount of words in the course
/// <summary>
/// This holds the amount of words in the course
/// </summary>
private int maxWords;
// Number of correct words so far
// (can be modified to a list or something like that to give better feedback)
/// <summary>
/// Number of correct words so far
/// (can be modified to a list or something like that to give better feedback)
/// </summary>
private int correctWords = 0;
/// <summary>
/// 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.
/// </summary>
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>("courseIndex") == course.index);
@@ -65,6 +111,10 @@ public class StartPause : MonoBehaviour
}
// These two functions generate video and image from files
/// <summary>
/// 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.
/// </summary>
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
/// <summary>
/// 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.
/// </summary>
private void NextImage()
{
wordImage.sprite = course.learnables[currentWordIndex].image;
}
// Activate by pressing the center of the screen
/// <summary>
/// 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.
/// </summary>
public void Pause()
{
if (!player.isPlaying)
@@ -104,8 +161,16 @@ public class StartPause : MonoBehaviour
}
// Press next-sign button for next word
/// <summary>
/// This function is called when the next-sign button is pressed.
/// It increased the wordindex and fetches new videos/images if index<max, because then the coure is not fincished yet.
/// If the maximum is reached, finishcourse is called to save the "finished" progress to the user.
/// </summary>
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
}
}
/// <summary>
/// finishcourse is called to save the "finished" progress to the user.
/// </summary>
public void FinishCourse()
{
// TODO: update progress (maybe this can also be at the `NextSign()`-method)