Resolve WES-49 "Courses list"
This commit is contained in:
67
Assets/Common/Scripts/CourseScreenManager.cs
Normal file
67
Assets/Common/Scripts/CourseScreenManager.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Unity.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class CourseScreenManager : MonoBehaviour
|
||||
{
|
||||
[Header("Course Screen Components")]
|
||||
public GameObject noRecentCourses;
|
||||
public Transform recentCourses;
|
||||
public Transform recommendedCourses;
|
||||
|
||||
[Header("Prefabs")]
|
||||
public GameObject course_item;
|
||||
|
||||
// TODO: change to ScriptableObject;
|
||||
[Header("ScriptableObjects")]
|
||||
public int numberOfRecentCourses;
|
||||
public string[] recentCourseTitle;
|
||||
public float[] recentCourseProgress;
|
||||
public Sprite[] recentCourseThumbnail;
|
||||
public string[] recentCourseScene;
|
||||
public int numberOfRecommendedCourses;
|
||||
public string[] recommendedCourseTitle;
|
||||
public float[] recommendedCourseProgress;
|
||||
public Sprite[] recommendedCourseThumbnail;
|
||||
public string[] recommendedCourseScene;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Recent courses
|
||||
noRecentCourses.SetActive(numberOfRecentCourses <= 0);
|
||||
|
||||
for (int i = 0; i < numberOfRecentCourses; i++)
|
||||
{
|
||||
// Create instance of prefab
|
||||
GameObject instance = GameObject.Instantiate(course_item, recentCourses);
|
||||
|
||||
// Dynamically load appearance
|
||||
CourseItem item = instance.GetComponent<CourseItem>();
|
||||
item.courseTitle = recentCourseTitle[i];
|
||||
item.courseThumbnail = recentCourseThumbnail[i];
|
||||
item.courseProgress = recentCourseProgress[i];
|
||||
item.courseScene = recentCourseScene[i];
|
||||
}
|
||||
|
||||
// Recommended courses
|
||||
for (int i = 0; i < numberOfRecommendedCourses; i++)
|
||||
{
|
||||
// Create instance of prefab
|
||||
GameObject instance = GameObject.Instantiate(course_item, recommendedCourses);
|
||||
|
||||
// Dynamically load appearance
|
||||
CourseItem item = instance.GetComponent<CourseItem>();
|
||||
item.courseTitle = recommendedCourseTitle[i];
|
||||
item.courseThumbnail = recommendedCourseThumbnail[i];
|
||||
item.courseProgress = 0.0f; // So progress bar doesn't show
|
||||
item.courseScene = recommendedCourseScene[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadScene(string sceneName)
|
||||
{
|
||||
SceneManager.LoadScene(sceneName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user