Merge branch 'courses-code-formatting-and-documentation' into 'development'

Added documentation for startpause and webcam

See merge request wesign/unity-application!27
This commit was merged in pull request #27.
This commit is contained in:
Jerome Coudron
2023-03-10 11:06:34 +00:00
2 changed files with 148 additions and 33 deletions

View File

@@ -3,48 +3,94 @@ using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using UnityEngine.Video; 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 public class StartPause : MonoBehaviour
{ {
[Header("UI References")] /// <summary>
// Reference to instructional video player /// Reference to instructional video player
/// </summary>
public VideoPlayer player; public VideoPlayer player;
// Reference to pause button /// <summary>
/// Reference to pause button
/// </summary>
public Button button; public Button button;
// Reference to sprite for the pause button
/// <summary>
/// Reference to sprite for the pause button
/// </summary>
public Sprite pauseSprite; 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; 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; 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; public UserList userList;
// The current user
/// <summary>
/// The current user
/// </summary>
private User user; private User user;
// Current user progress for this course
/// <summary>
/// Current user progress for this course
/// </summary>
private Progress progress = null; private Progress progress = null;
[Header("Course")]
// ScriptableObject with list of all courses /// <summary>
/// ScriptableObject with list of all courses
/// </summary>
public CourseList courselist; public CourseList courselist;
// Reference to Course ScriptableObject
/// <summary>
/// Reference to Course ScriptableObject
/// </summary>
private Course course; 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; 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; 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; 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() public void Awake()
{ {
// Setting up course // Setting up course
course = courselist.courses[courselist.currentCourseIndex]; course = courselist.courses[courselist.currentCourseIndex];
maxWords = course.learnables.Count; maxWords = course.learnables.Count;
// Create entry in current user for keeping track of progress // Create entry in current user for keeping track of progress
user = userList.GetCurrentUser(); user = userList.GetCurrentUser();
progress = user.courses.Find((p) => p != null && p.Get<CourseIndex>("courseIndex") == course.index); 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 // 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() private void NextVideo()
{ {
player.clip = course.learnables[currentWordIndex].clip; player.clip = course.learnables[currentWordIndex].clip;
@@ -76,13 +126,20 @@ public class StartPause : MonoBehaviour
button.image.color = col; 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() private void NextImage()
{ {
wordImage.sprite = course.learnables[currentWordIndex].image; 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() public void Pause()
{ {
if (!player.isPlaying) if (!player.isPlaying)
@@ -104,8 +161,16 @@ public class StartPause : MonoBehaviour
} }
// Press next-sign button for next word // 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() 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 // Goto the next word/letter
currentWordIndex++; 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() public void FinishCourse()
{ {
// TODO: update progress (maybe this can also be at the `NextSign()`-method) // TODO: update progress (maybe this can also be at the `NextSign()`-method)

View File

@@ -3,40 +3,78 @@ using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using UnityEngine.UI; using UnityEngine.UI;
/// <summary>
/// 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.
/// </summary>
public class Webcam : MonoBehaviour public class Webcam : MonoBehaviour
{ {
/// <summary>
/// Index to indicate which camera is being used
/// </summary>
int camdex = 0; int camdex = 0;
/// <summary>
/// This texture is used as an intermidiary between the camera output and the display image
/// </summary>
WebCamTexture tex; WebCamTexture tex;
/// <summary>
/// Reference to the RawImage that will display the video
/// </summary>
public RawImage display; public RawImage display;
/// <summary>
/// Reference to the button that is currently used to test the feedback-display
/// </summary>
public Button feedback; public Button feedback;
/// <summary>
/// This is a reference to the PANEL that holds the feedbackwindow
/// </summary>
public GameObject popup; public GameObject popup;
/// <summary>
/// This is a reference to the textfield that holds the part of the feedback-window that will change: bad/good/excellent
/// </summary>
public TextMeshProUGUI dynamic; public TextMeshProUGUI dynamic;
/// <summary>
/// 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.
/// </summary>
void Awake() void Awake()
{ {
popup.SetActive(false); 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.Play();
tex = new WebCamTexture(device.name); }
display.texture = tex;
tex.Play();
} }
/// <summary>
/// So long as there are cameras to use, you swap the camera you are using to another in the list.
/// </summary>
public void SwapCam() public void SwapCam()
{ {
if (WebCamTexture.devices.Length > 0) if (WebCamTexture.devices.Length > 0)
{ {
// Stop the old camera // Stop the old camera
display.texture = null; // If there was no camera playing before, then you dont have to reset the texture, as it wasn't assigned in the first place.
tex.Stop(); if (tex.isPlaying) {
tex = null; display.texture = null;
tex.Stop();
// Find the new camera tex = null;
camdex += 1; }
camdex %= WebCamTexture.devices.Length; // Find the new camera
camdex += 1;
camdex %= WebCamTexture.devices.Length;
// Start the new camera // Start the new camera
WebCamDevice device = WebCamTexture.devices[camdex]; WebCamDevice device = WebCamTexture.devices[camdex];
tex = new WebCamTexture(device.name); tex = new WebCamTexture(device.name);
@@ -46,7 +84,11 @@ public class Webcam : MonoBehaviour
} }
} }
// Scene changing is implemented here to avoid problems with webcam /// <summary>
/// The notmal sceneChanger cannot be used here since the camera also needs to be stopped.
/// This extra functionality is implemented in this function
/// </summary>
/// <param name="sceneName"> The path for the scene you want to travel to, assuming root-directory is Assets</param>
public void LoadScene(string sceneName) public void LoadScene(string sceneName)
{ {
display.texture = null; display.texture = null;
@@ -56,6 +98,10 @@ public class Webcam : MonoBehaviour
SceneManager.LoadScene(sceneName); SceneManager.LoadScene(sceneName);
} }
/// <summary>
/// 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.
/// </summary>
public void Show_feedback() public void Show_feedback()
{ {
if (popup.activeSelf) if (popup.activeSelf)