Resolve WES-99 "Cc refactor"
This commit is contained in:
@@ -5,11 +5,39 @@ 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.
|
||||
/// TemplateCourse scene manager
|
||||
/// </summary>
|
||||
public class StartPause : MonoBehaviour
|
||||
public class TemplateCourse : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Index to indicate which camera is being used
|
||||
/// </summary>
|
||||
private int camdex = 0;
|
||||
|
||||
/// <summary>
|
||||
/// This texture is used as an intermidiary between the camera output and the display image
|
||||
/// </summary>
|
||||
private WebCamTexture tex;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the RawImage that will display the video
|
||||
/// </summary>
|
||||
public RawImage webcamDisplay;
|
||||
|
||||
/// <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 feedbackPopup;
|
||||
|
||||
/// <summary>
|
||||
/// This is a reference to the textfield that holds the part of the feedback-window that will change: bad/good/excellent
|
||||
/// </summary>
|
||||
public TMP_Text dynamic;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to instructional video player
|
||||
@@ -19,22 +47,21 @@ public class StartPause : MonoBehaviour
|
||||
/// Reference to pause button
|
||||
/// </summary>
|
||||
public Button button;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Reference to sprite for the pause button
|
||||
/// </summary>
|
||||
public Sprite pauseSprite;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the image for displaying the current words sprite
|
||||
/// </summary>
|
||||
public Image wordImage;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the text object for displaying the current word
|
||||
/// </summary>
|
||||
public TextMeshProUGUI title;
|
||||
|
||||
public TMP_Text title;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to user list to get current user
|
||||
@@ -45,29 +72,27 @@ public class StartPause : MonoBehaviour
|
||||
/// The current user
|
||||
/// </summary>
|
||||
private User user;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Current user progress for this course
|
||||
/// </summary>
|
||||
private Progress progress = null;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ScriptableObject with list of all courses
|
||||
/// </summary>
|
||||
public CourseList courselist;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Reference to Course ScriptableObject
|
||||
/// </summary>
|
||||
private Course course;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Index of the current word/letter in the course.learnables list
|
||||
/// </summary>
|
||||
private int currentWordIndex = 0;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This holds the amount of words in the course
|
||||
/// </summary>
|
||||
@@ -89,11 +114,6 @@ public class StartPause : MonoBehaviour
|
||||
/// </summary>
|
||||
public Button CoursesButton;
|
||||
|
||||
/// <summary>
|
||||
/// Webcam class to close the webcam when the course is finished
|
||||
/// </summary>
|
||||
public Webcam Webcam;
|
||||
|
||||
/// <summary>
|
||||
/// DateTime containint the start moment
|
||||
/// </summary>
|
||||
@@ -102,16 +122,28 @@ public class StartPause : MonoBehaviour
|
||||
/// <summary>
|
||||
/// Reference to the timeSpent UI
|
||||
/// </summary>
|
||||
public TextMeshProUGUI timeSpent;
|
||||
public TMP_Text timeSpent;
|
||||
|
||||
/// <summary>
|
||||
/// This function is called when the script is initialised.
|
||||
/// It inactivatis the popup, finds a webcam to use and links it via the WebcamTexture to the display RawImage.
|
||||
/// 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()
|
||||
void Awake()
|
||||
{
|
||||
// Setting up Webcam
|
||||
feedbackPopup.SetActive(false);
|
||||
if (WebCamTexture.devices.Length > 0)
|
||||
{
|
||||
WebCamDevice device = WebCamTexture.devices[camdex];
|
||||
tex = new WebCamTexture(device.name);
|
||||
webcamDisplay.texture = tex;
|
||||
|
||||
tex.Play();
|
||||
}
|
||||
|
||||
// Setting up course
|
||||
course = courselist.courses[courselist.currentCourseIndex];
|
||||
maxWords = course.learnables.Count;
|
||||
@@ -140,7 +172,6 @@ public class StartPause : MonoBehaviour
|
||||
startMoment = DateTime.Now;
|
||||
}
|
||||
|
||||
// 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.
|
||||
@@ -190,7 +221,6 @@ 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.
|
||||
@@ -222,7 +252,6 @@ public class StartPause : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// finishcourse is called to save the "finished" progress to the user.
|
||||
/// </summary>
|
||||
@@ -236,10 +265,78 @@ public class StartPause : MonoBehaviour
|
||||
timeSpent.text = time.ToString(@"hh\:mm\:ss");
|
||||
|
||||
// Link button
|
||||
//CoursesButton.onClick.AddListener(() => { SceneManager.LoadScene("Assets/Common/Scenes/CoursesScreen.unity"); });
|
||||
CoursesButton.onClick.AddListener(() => { Webcam.LoadScene("Assets/Common/Scenes/CoursesScreen.unity"); });
|
||||
CoursesButton.onClick.AddListener(() => { SystemController.GetInstance().BackToPreviousScene(); });
|
||||
|
||||
progress.AddOrUpdate<float>("courseProgress", 1f);
|
||||
userList.Save();
|
||||
}
|
||||
|
||||
/// <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
|
||||
// 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)
|
||||
{
|
||||
webcamDisplay.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);
|
||||
webcamDisplay.texture = tex;
|
||||
|
||||
tex.Play();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The normal 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 Back()
|
||||
{
|
||||
webcamDisplay.texture = null;
|
||||
tex.Stop();
|
||||
tex = null;
|
||||
|
||||
SystemController.GetInstance().BackToPreviousScene();
|
||||
}
|
||||
|
||||
/// <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 ShowFeedback()
|
||||
{
|
||||
if (feedbackPopup.activeSelf)
|
||||
{
|
||||
dynamic.text = "";
|
||||
feedbackPopup.SetActive(false);
|
||||
return;
|
||||
}
|
||||
double index = UnityEngine.Random.value;
|
||||
if (index < 0.5)
|
||||
{
|
||||
dynamic.text = "Poor";
|
||||
}
|
||||
else if (index > 0.8)
|
||||
{
|
||||
dynamic.text = "Excellent";
|
||||
}
|
||||
else
|
||||
{
|
||||
dynamic.text = "Good";
|
||||
}
|
||||
feedbackPopup.SetActive(true);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae746f332e314e84c9df74b892c75d4d
|
||||
guid: 6b3f784c065813a4a8364b1299284816
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,128 +0,0 @@
|
||||
using TMPro;
|
||||
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;
|
||||
|
||||
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
|
||||
// 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);
|
||||
display.texture = tex;
|
||||
|
||||
tex.Play();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The normal 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;
|
||||
tex.Stop();
|
||||
tex = null;
|
||||
|
||||
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)
|
||||
{
|
||||
dynamic.text = "";
|
||||
popup.SetActive(false);
|
||||
return;
|
||||
}
|
||||
double index = UnityEngine.Random.value;
|
||||
if (index < 0.5)
|
||||
{
|
||||
dynamic.text = "Poor";
|
||||
}
|
||||
else if (index > 0.8)
|
||||
{
|
||||
dynamic.text = "Excellent";
|
||||
}
|
||||
else
|
||||
{
|
||||
dynamic.text = "Good";
|
||||
}
|
||||
popup.SetActive(true);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a85f8bd9399680347b4be72850a56fcf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user