Introduced Hangman in DEV-compatible branch
This commit is contained in:
committed by
Tibe Habils
parent
b5328d0b9d
commit
e23de9a2d3
95
Assets/Hangman/Scripts/WebCam.cs
Normal file
95
Assets/Hangman/Scripts/WebCam.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine;
|
||||
|
||||
public class WebCam : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Index of the current camera
|
||||
/// </summary>
|
||||
protected int camdex = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Texture to paste on the display
|
||||
/// </summary>
|
||||
protected WebCamTexture tex;
|
||||
|
||||
/// <summary>
|
||||
/// Display for the video feed
|
||||
/// </summary>
|
||||
public RawImage display;
|
||||
|
||||
/// <summary>
|
||||
/// Setup the webcam correctly
|
||||
/// </summary>
|
||||
void Awake()
|
||||
{
|
||||
WebCamDevice device = WebCamTexture.devices[camdex];
|
||||
tex = new WebCamTexture(device.name);
|
||||
display.texture = tex;
|
||||
|
||||
tex.Play();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function to toggle between stopping and starting
|
||||
/// </summary>
|
||||
/*
|
||||
public void toggle()
|
||||
{
|
||||
if (tex.isPlaying)
|
||||
{
|
||||
tex.Stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
tex.Play();
|
||||
}
|
||||
}
|
||||
*/
|
||||
public void PlayCam()
|
||||
{
|
||||
if (!tex.isPlaying) tex.Play();
|
||||
}
|
||||
|
||||
public void StopCam()
|
||||
{
|
||||
if (tex.isPlaying) tex.Stop();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Swap webcam by cycling through the `WebCamTexture.devices` list
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scene changing is implemented here to avoid problems with webcam
|
||||
/// </summary>
|
||||
public void GotoThemeSelection()
|
||||
{
|
||||
display.texture = null;
|
||||
tex.Stop();
|
||||
tex = null;
|
||||
|
||||
SystemController.GetInstance().BackToPreviousScene();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user