53 lines
1.3 KiB
C#
53 lines
1.3 KiB
C#
using JetBrains.Annotations;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class CourseItem : MonoBehaviour
|
|
{
|
|
// TODO: change to ScriptableObject Course;
|
|
[Header("ScriptableObject Course")]
|
|
public string courseTitle;
|
|
public float courseProgress;
|
|
public Sprite courseThumbnail;
|
|
public string courseScene;
|
|
|
|
[Header("UI references")]
|
|
public Image thumbnail;
|
|
public TMP_Text title;
|
|
public Button button;
|
|
public GameObject slider;
|
|
public GameObject completed;
|
|
|
|
|
|
void Start()
|
|
{
|
|
// Use public function so that this component can get Instantiated
|
|
GenerateContent();
|
|
}
|
|
|
|
private void LoadCourseInfo()
|
|
{
|
|
SceneManager.LoadScene(courseScene);
|
|
}
|
|
|
|
public void GenerateContent()
|
|
{
|
|
// Set appearance
|
|
thumbnail.sprite = courseThumbnail;
|
|
title.text = courseTitle;
|
|
|
|
// Set progress
|
|
float progress = Mathf.Clamp01(courseProgress);
|
|
completed.SetActive(1.0f <= progress);
|
|
slider.SetActive(0.0f < progress && progress < 1.0f);
|
|
slider.GetComponent<Slider>().value = progress;
|
|
|
|
// Add click functionality
|
|
button.onClick.AddListener(LoadCourseInfo);
|
|
}
|
|
}
|