Resolve WES-49 "Courses list"
This commit is contained in:
@@ -1,11 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class ChangeSceneOnClick : MonoBehaviour
|
||||
{
|
||||
public static void loadScene(string sceneName) {
|
||||
SceneManager.LoadScene(sceneName);
|
||||
}
|
||||
}
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class ChangeSceneOnClick : MonoBehaviour
|
||||
{
|
||||
// Backwards compatible because SOMEONE did not use correct naming convention
|
||||
public void loadScene(string sceneName)
|
||||
{
|
||||
SceneManager.LoadScene(sceneName);
|
||||
}
|
||||
|
||||
// Load scene from path name
|
||||
public void LoadScene(string sceneName)
|
||||
{
|
||||
SceneManager.LoadScene(sceneName);
|
||||
}
|
||||
|
||||
// Load scene from reference
|
||||
public void LoadScene(Scene scene)
|
||||
{
|
||||
SceneManager.LoadScene(scene.buildIndex);
|
||||
}
|
||||
|
||||
// Load scene from build index
|
||||
public void LoadScene(int buildIndex)
|
||||
{
|
||||
SceneManager.LoadScene(buildIndex);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
11
Assets/Common/Scripts/CourseItem.cs.meta
Normal file
11
Assets/Common/Scripts/CourseItem.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea605a5461e2dbd47b402db3bf33c69f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
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);
|
||||
}
|
||||
}
|
||||
11
Assets/Common/Scripts/CourseScreenManager.cs.meta
Normal file
11
Assets/Common/Scripts/CourseScreenManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00e2726fda637a1488461b7a43e46343
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Assets/Common/Scripts/ListScreenManager.cs
Normal file
43
Assets/Common/Scripts/ListScreenManager.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class ListScreenManager : MonoBehaviour
|
||||
{
|
||||
[Header("List Screen Components")]
|
||||
public Transform item_container;
|
||||
|
||||
[Header("Prefabs")]
|
||||
public GameObject item_prefab;
|
||||
|
||||
// TODO: change to ScriptableObject;
|
||||
[Header("ScriptableObjects")]
|
||||
public int numberOfItems;
|
||||
public string[] itemTitle;
|
||||
public float[] itemProgress;
|
||||
public Sprite[] itemThumbnail;
|
||||
public string[] itemScene;
|
||||
|
||||
void Start()
|
||||
{
|
||||
for (int i = 0; i < numberOfItems; i++)
|
||||
{
|
||||
// Create instance of prefab
|
||||
GameObject instance = GameObject.Instantiate(item_prefab, item_container);
|
||||
|
||||
// Dynamically load appearance
|
||||
CourseItem item = instance.GetComponent<CourseItem>();
|
||||
item.courseTitle = itemTitle[i];
|
||||
item.courseThumbnail = itemThumbnail[i];
|
||||
item.courseProgress = itemProgress[i];
|
||||
item.courseScene = itemScene[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadScene(string sceneName)
|
||||
{
|
||||
SceneManager.LoadScene(sceneName);
|
||||
}
|
||||
}
|
||||
11
Assets/Common/Scripts/ListScreenManager.cs.meta
Normal file
11
Assets/Common/Scripts/ListScreenManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fac0bf527487ad48835aff400b1f762
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user