using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; /// /// CourseScreen scene manager /// public class CourseScreenManager : MonoBehaviour { /// /// Reference to text that displays when there are no recent courses /// public GameObject noRecentCourses; /// /// Reference to recent-courses-list container object /// public Transform recentCoursesContainer; /// /// Reference to recommended-courses-list container object /// public Transform recommendedCoursesContainer; /// /// Prefab of the course item object /// public GameObject courseItem; /// /// Reference to the users so we can get the current user; /// public UserList userList; /// /// Reference to the courses /// public CourseList courseList; /// /// Start is called before the first frame update /// void Start() { User user = userList.GetCurrentUser(); // Recent courses List> recentCourses = user.GetRecentCourses(); noRecentCourses.SetActive(recentCourses.Count <= 0); foreach (Tuple course in recentCourses) { // Create instance of prefab GameObject instance = GameObject.Instantiate(courseItem, recentCoursesContainer); // Dynamically load appearance CourseItem item = instance.GetComponent(); item.course = courseList.courses.Find((j) => j.index == course.Item1); item.progress = course.Item2; } // Recommended courses List> recommenedCourses = user.GetRecommendedCourses(); foreach (Tuple course in recommenedCourses) { // Create instance of prefab GameObject instance = GameObject.Instantiate(courseItem, recommendedCoursesContainer); // Dynamically load appearance CourseItem item = instance.GetComponent(); item.course = courseList.courses.Find((j) => j.index == course.Item1); item.progress = course.Item2; } } /// /// Method used as callback for course item onClick events /// /// The path to the new scene (path == $"Assets/{sceneName}") public void LoadScene(string sceneName) { SceneManager.LoadScene(sceneName); } }