83 lines
2.2 KiB
C#
83 lines
2.2 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
/// Handles the display of courses in the ListCourseScreen and CourseScreenManager scene
|
|
/// </summary>
|
|
public class CourseItem : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// Reference to the courseList
|
|
/// </summary>
|
|
public CourseList courseList;
|
|
|
|
/// <summary>
|
|
/// Reference to the course object
|
|
/// </summary>
|
|
public Course course;
|
|
|
|
/// <summary>
|
|
/// Progress of the current user on this specific course
|
|
/// </summary>
|
|
public float progress;
|
|
|
|
/// <summary>
|
|
/// UI Reference to the image for displaying the course thumbnail
|
|
/// </summary>
|
|
public Image thumbnail;
|
|
|
|
/// <summary>
|
|
/// UI Reference to the gameobject for displaying the course title
|
|
/// </summary>
|
|
public TMP_Text title;
|
|
|
|
/// <summary>
|
|
/// UI Reference to the button so the correct callback can be trigger on click
|
|
/// </summary>
|
|
public Button button;
|
|
|
|
/// <summary>
|
|
/// Reference to the progressBar that displays the progress of the user
|
|
/// </summary>
|
|
public GameObject slider;
|
|
|
|
/// <summary>
|
|
/// Reference to the gameobject that holds the text 'COMPLETED'
|
|
/// </summary>
|
|
public GameObject completed;
|
|
|
|
/// <summary>
|
|
/// Start is called before the first frame update
|
|
/// </summary>
|
|
void Start()
|
|
{
|
|
// Use public function so that this component can get Instantiated
|
|
GenerateContent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// (Re)generate the CourseItem object and update its appearance
|
|
/// </summary>
|
|
public void GenerateContent()
|
|
{
|
|
// Set appearance
|
|
thumbnail.sprite = course.thumbnail;
|
|
title.text = course.title;
|
|
|
|
// Set progress
|
|
progress = Mathf.Clamp01(progress);
|
|
completed.SetActive(1.0f <= progress);
|
|
slider.SetActive(0.0f <= progress && progress < 1.0f);
|
|
slider.GetComponentInChildren<SlicedSlider>().fillAmount = progress;
|
|
|
|
// Add click functionality
|
|
button.onClick.AddListener(() =>
|
|
{
|
|
courseList.SetCurrentCourse(course.index);
|
|
SystemController.GetInstance().LoadNextScene("Common/Scenes/CourseActivityScreen");
|
|
});
|
|
|
|
}
|
|
}
|