using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
///
/// Handles the display of courses in the ListCourseScreen and CourseScreenManager scene
///
public class CourseItem : MonoBehaviour
{
///
/// Reference to the course object
///
public Course course;
///
/// Progress of the current user on this specific course
///
public float progress;
///
/// UI Reference to the image for displaying the course thumbnail
///
public Image thumbnail;
///
/// UI Reference to the gameobject for displaying the course title
///
public TMP_Text title;
///
/// UI Reference to the button so the correct callback can be trigger on click
///
public Button button;
///
/// Reference to the slider that displays the progress of the user
///
public GameObject slider;
///
/// Reference to the gameobject that holds the text 'COMPLETED'
///
public GameObject completed;
///
/// Start is called before the first frame update
///
void Start()
{
// Use public function so that this component can get Instantiated
GenerateContent();
}
///
/// (Re)generate the CourseItem object and update its appearance
///
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.GetComponent().value = progress;
// Add click functionality
button.onClick.AddListener(() => SceneManager.LoadScene("Courses/Scenes/Course_0"));
}
}