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

Added documentation for startpause and webcam

See merge request wesign/unity-application!27
This commit is contained in:
Jerome Coudron 2023-03-10 11:06:34 +00:00
commit e19fd2de8c
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)

View File

@ -3,40 +3,78 @@ using UnityEngine;
using UnityEngine.SceneManagement;
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
{
/// <summary>
/// Index to indicate which camera is being used
/// </summary>
int camdex = 0;
/// <summary>
/// This texture is used as an intermidiary between the camera output and the display image
/// </summary>
WebCamTexture tex;
/// <summary>
/// Reference to the RawImage that will display the video
/// </summary>
public RawImage display;
/// <summary>
/// Reference to the button that is currently used to test the feedback-display
/// </summary>
public Button feedback;
/// <summary>
/// This is a reference to the PANEL that holds the feedbackwindow
/// </summary>
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;
/// <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()
{
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();
}
}
/// <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()
{
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
/// <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)
{
display.texture = null;
@ -56,6 +98,10 @@ public class Webcam : MonoBehaviour
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()
{
if (popup.activeSelf)