Integrate minigame and courses

This commit is contained in:
Dries Van Schuylenbergh
2023-03-08 19:07:57 +00:00
parent 7e98fea538
commit 852a17b0b4
56 changed files with 1431 additions and 1300 deletions

View File

@@ -1,16 +1,35 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
[CreateAssetMenu(fileName="New Course", menuName="course")]
[CreateAssetMenu(menuName = "Create new Scriptable/Course")]
public class Course : ScriptableObject
{
public string title;
public string description;
public Sprite thumbnail;
public int progress;
[Serializable]
// Small class to hold information about a single learnable (e.g., a word or a letter)
public class Learnable
{
// Name of the word/letter to learn
public string name;
// Sprite of this word/letter
public Sprite image;
// Example video clip
public VideoClip clip;
}
public Sprite[] images;
public VideoClip[] videos;
[Header("Course info")]
// Course index
public CourseIndex index;
// Course title
public string title;
// Short desciption of the course
public string description;
// Thumbnail of the course
public Sprite thumbnail;
[Header("Learnable words")]
// List of learnable words/letters
public List<Learnable> learnables = new List<Learnable>();
}

View File

@@ -2,8 +2,8 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class CourseIndex
// TODO: add other courses
public enum CourseIndex
{
// Start is called before the first frame update
public static int index = 0;
FINGERSPELLING
}

View File

@@ -2,8 +2,14 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName="New CourseList", menuName="CourseList")]
[CreateAssetMenu(menuName = "Create new Scriptable/CourseList")]
public class CourseList : ScriptableObject
{
public Course[] courses;
[Header("Current Course")]
// Index of the current course
public int currentCourseIndex = 0;
[Header("Courses")]
// List of courses
public List<Course> courses = new List<Course>();
}

View File

@@ -1,40 +1,76 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video; // To alter video
using UnityEngine.UI; // For general image + button jobs
using TMPro; // For text
using UnityEngine.Video;
using UnityEngine.UI;
using TMPro;
using UnityEditor;
public class StartPause : MonoBehaviour
{
[Header("UI References")]
// Reference to instructional video player
public VideoPlayer player;
// Reference to pause button
public Button button;
// Reference to sprite for the pause button
public Sprite pauseSprite;
public Image word_image;
// Reference to the image for displaying the current words sprite
public Image wordImage;
// Reference to the text object for displaying the current word
public TextMeshProUGUI title;
[Header("User")]
// Reference to user list to get current user
public UserList userList;
// The current user
private User user;
// Current user progress for this course
private Progress progress = null;
[Header("Course")]
// ScriptableObject with list of all courses
public CourseList courselist;
// Reference to Course ScriptableObject
private Course course;
private int word_i = 0;
// Index of the current word/letter in the course.learnables list
private int currentWordIndex = 0;
// In my example, i have 4 videos/images
private int max_words = 4;
private int maxWords = 4;
// Number of correct words so far
// (can be modified to a list or something like that to give better feedback)
private int correctWords = 0;
// Start is called before the first frame update
public void Awake()
{
course = courselist.courses[CourseIndex.index];
// Setting up course
course = courselist.courses[courselist.currentCourseIndex];
// Create entry in current user for keeping track of progress
user = userList.users[userList.currentUserIndex];
progress = user.courses.Find((p) => p != null && p.Get<CourseIndex>("courseIndex") == course.index);
if (progress == null)
{
progress = new Progress();
progress.AddOrUpdate<CourseIndex>("courseIndex", CourseIndex.FINGERSPELLING);
progress.AddOrUpdate<float>("courseProgress", -1.0f);
user.courses.Add(progress);
}
EditorUtility.SetDirty(user);
// Setup UI
button.image.sprite = pauseSprite;
title.text = course.name;
next_video();
next_image();
NextVideo();
NextImage();
}
// These two functions generate video and image from files
private void next_video(){
player.clip = course.videos[word_i];
private void NextVideo()
{
player.clip = course.learnables[currentWordIndex].clip;
// This loads first frame, so that it can be used as a sort-of preview for the video
player.Play();
player.Pause();
@@ -45,11 +81,9 @@ public class StartPause : MonoBehaviour
}
// This doesn't work
private void next_image(){
Sprite tex = course.images[word_i];
word_image.sprite = tex;
private void NextImage()
{
wordImage.sprite = course.learnables[currentWordIndex].image;
}
// Activate by pressing the center of the screen
@@ -74,10 +108,32 @@ public class StartPause : MonoBehaviour
}
// Press next-sign button for next word
public void NextSign(){
word_i++;
word_i %= max_words;
next_video();
next_image();
public void NextSign()
{
// Goto the next word/letter
currentWordIndex++;
// TODO: fix correct word count
correctWords++;
progress.AddOrUpdate<float>("courseProgress", (float)correctWords / (float)maxWords);
EditorUtility.SetDirty(user);
// Update UI if course is not finished yet
if (currentWordIndex < maxWords)
{
NextVideo();
NextImage();
}
// Finish course and record progress
else
{
FinishCourse();
}
}
public void FinishCourse()
{
// TODO: update progress (maybe this can also be at the `NextSign()`-method)
progress.AddOrUpdate<float>("courseProgress", correctWords / maxWords);
}
}