Resolve WES-49 "Courses list"
This commit is contained in:
52
Assets/Common/Scripts/CourseItem.cs
Normal file
52
Assets/Common/Scripts/CourseItem.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user