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,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)