added course prototype, image switch not working yet
This commit is contained in:
69
Assets/Scripts/StartPause.cs
Normal file
69
Assets/Scripts/StartPause.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Video;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class StartPause : MonoBehaviour
|
||||
{
|
||||
public VideoPlayer player;
|
||||
public Button button;
|
||||
public Sprite pauseSprite;
|
||||
public Image image;
|
||||
|
||||
private int word_i = 0;
|
||||
// In my example, i have 4 videos/images
|
||||
private int max_words = 4;
|
||||
|
||||
// Start is called before the first frame update
|
||||
public void Start()
|
||||
{
|
||||
next_video();
|
||||
//next_image();
|
||||
|
||||
button.image.sprite = pauseSprite;
|
||||
Color col = button.image.color;
|
||||
col.a = 255;
|
||||
button.image.color = col;
|
||||
}
|
||||
|
||||
// These two functions generate video and image from files
|
||||
private void next_video(){
|
||||
player.url = $"Assets/Videos/{word_i}.mp4";
|
||||
}
|
||||
|
||||
// This doesn't work
|
||||
private void next_image(){
|
||||
Sprite tex = Resources.Load($"Assets/Images/{word_i}.png") as Sprite;
|
||||
image.sprite = tex;
|
||||
}
|
||||
|
||||
// Activate by pressing the center of the screen
|
||||
public void Pause()
|
||||
{
|
||||
if (!player.isPlaying)
|
||||
{
|
||||
player.Play();
|
||||
Color col = button.image.color;
|
||||
col.a = 0;
|
||||
button.image.color = col;
|
||||
}
|
||||
else
|
||||
{
|
||||
player.Pause();
|
||||
Color col = button.image.color;
|
||||
col.a = 255;
|
||||
button.image.color = col;
|
||||
}
|
||||
}
|
||||
|
||||
// Press next-sign button for next word
|
||||
public void NextSign(){
|
||||
// Fetch next video and image from log
|
||||
// Idea : do this by numbering video's and images and using increment to find them.
|
||||
word_i++;
|
||||
word_i %= max_words;
|
||||
next_video();
|
||||
//next_image();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/StartPause.cs.meta
Normal file
11
Assets/Scripts/StartPause.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae746f332e314e84c9df74b892c75d4d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
50
Assets/Scripts/Webcam.cs
Normal file
50
Assets/Scripts/Webcam.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class Webcam : MonoBehaviour
|
||||
{
|
||||
int camdex = 0;
|
||||
WebCamTexture tex;
|
||||
|
||||
public RawImage display;
|
||||
public Button nextSignButton;
|
||||
|
||||
void Awake(){
|
||||
WebCamDevice device = WebCamTexture.devices[camdex];
|
||||
tex = new WebCamTexture(device.name);
|
||||
display.texture = tex;
|
||||
|
||||
tex.Play();
|
||||
}
|
||||
|
||||
public void SwapCam(){
|
||||
if(WebCamTexture.devices.Length > 0){
|
||||
// Stop the old camera
|
||||
display.texture = null;
|
||||
tex.Stop();
|
||||
tex = null;
|
||||
|
||||
// Find the new camera
|
||||
camdex += 1;
|
||||
camdex %= WebCamTexture.devices.Length;
|
||||
|
||||
// Start the new camera
|
||||
WebCamDevice device = WebCamTexture.devices[camdex];
|
||||
tex = new WebCamTexture(device.name);
|
||||
display.texture = tex;
|
||||
|
||||
tex.Play();
|
||||
}
|
||||
}
|
||||
// Scene changing is implemented here to avoid problems with webcam
|
||||
public void loadScene(string sceneName) {
|
||||
display.texture = null;
|
||||
tex.Stop();
|
||||
tex = null;
|
||||
|
||||
SceneManager.LoadScene(sceneName);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Webcam.cs.meta
Normal file
11
Assets/Scripts/Webcam.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a85f8bd9399680347b4be72850a56fcf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user