Decent first prototype
This commit is contained in:
8
Assets/JustSign/Prefabs.meta
Normal file
8
Assets/JustSign/Prefabs.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1dd701eefa37cbe4e9ed52960fa7a7cf
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
214
Assets/JustSign/Prefabs/Symbol.prefab
Normal file
214
Assets/JustSign/Prefabs/Symbol.prefab
Normal file
@@ -0,0 +1,214 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &4639383499500021565
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 7664190503744730416}
|
||||
- component: {fileID: 4730176006060198146}
|
||||
- component: {fileID: 1836798560195404133}
|
||||
m_Layer: 5
|
||||
m_Name: Symbol
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &7664190503744730416
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4639383499500021565}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 6279317507399066568}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 100, y: 100}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &4730176006060198146
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4639383499500021565}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!114 &1836798560195404133
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4639383499500021565}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Sprite: {fileID: 0}
|
||||
m_Type: 0
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 1
|
||||
m_FillMethod: 4
|
||||
m_FillAmount: 1
|
||||
m_FillClockwise: 1
|
||||
m_FillOrigin: 0
|
||||
m_UseSpriteMesh: 0
|
||||
m_PixelsPerUnitMultiplier: 1
|
||||
--- !u!1 &7932988193255257378
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 6279317507399066568}
|
||||
- component: {fileID: 2862254737186411956}
|
||||
- component: {fileID: 3570096111438075237}
|
||||
m_Layer: 5
|
||||
m_Name: Text (TMP)
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &6279317507399066568
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7932988193255257378}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 7664190503744730416}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &2862254737186411956
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7932988193255257378}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!114 &3570096111438075237
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7932988193255257378}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_text: A
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||
m_fontSharedMaterials: []
|
||||
m_fontMaterial: {fileID: 0}
|
||||
m_fontMaterials: []
|
||||
m_fontColor32:
|
||||
serializedVersion: 2
|
||||
rgba: 4282795590
|
||||
m_fontColor: {r: 0.27450982, g: 0.27450982, b: 0.27450982, a: 1}
|
||||
m_enableVertexGradient: 0
|
||||
m_colorMode: 3
|
||||
m_fontColorGradient:
|
||||
topLeft: {r: 1, g: 1, b: 1, a: 1}
|
||||
topRight: {r: 1, g: 1, b: 1, a: 1}
|
||||
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
|
||||
bottomRight: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_fontColorGradientPreset: {fileID: 0}
|
||||
m_spriteAsset: {fileID: 0}
|
||||
m_tintAllSprites: 0
|
||||
m_StyleSheet: {fileID: 0}
|
||||
m_TextStyleHashCode: -1183493901
|
||||
m_overrideHtmlColors: 0
|
||||
m_faceColor:
|
||||
serializedVersion: 2
|
||||
rgba: 4294967295
|
||||
m_fontSize: 32
|
||||
m_fontSizeBase: 32
|
||||
m_fontWeight: 400
|
||||
m_enableAutoSizing: 0
|
||||
m_fontSizeMin: 18
|
||||
m_fontSizeMax: 72
|
||||
m_fontStyle: 0
|
||||
m_HorizontalAlignment: 2
|
||||
m_VerticalAlignment: 512
|
||||
m_textAlignment: 65535
|
||||
m_characterSpacing: 0
|
||||
m_wordSpacing: 0
|
||||
m_lineSpacing: 0
|
||||
m_lineSpacingMax: 0
|
||||
m_paragraphSpacing: 0
|
||||
m_charWidthMaxAdj: 0
|
||||
m_enableWordWrapping: 1
|
||||
m_wordWrappingRatios: 0.4
|
||||
m_overflowMode: 0
|
||||
m_linkedTextComponent: {fileID: 0}
|
||||
parentLinkedComponent: {fileID: 0}
|
||||
m_enableKerning: 1
|
||||
m_enableExtraPadding: 0
|
||||
checkPaddingRequired: 0
|
||||
m_isRichText: 1
|
||||
m_parseCtrlCharacters: 1
|
||||
m_isOrthographic: 1
|
||||
m_isCullingEnabled: 0
|
||||
m_horizontalMapping: 0
|
||||
m_verticalMapping: 0
|
||||
m_uvLineOffset: 0
|
||||
m_geometrySortingOrder: 0
|
||||
m_IsTextObjectScaleStatic: 0
|
||||
m_VertexBufferAutoSizeReduction: 0
|
||||
m_useMaxVisibleDescender: 1
|
||||
m_pageToDisplay: 1
|
||||
m_margin: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_isUsingLegacyAnimationComponent: 0
|
||||
m_isVolumetricText: 0
|
||||
m_hasFontAssetChanged: 0
|
||||
m_baseMaterial: {fileID: 0}
|
||||
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
|
||||
@@ -1,6 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94b05c588eeb041c0bfd24fac57a77d8
|
||||
AssemblyDefinitionImporter:
|
||||
guid: f3117b0203a1342a48a95904347b03c8
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
5605
Assets/JustSign/Scenes/Game.unity
Normal file
5605
Assets/JustSign/Scenes/Game.unity
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/JustSign/Scenes/Game.unity.meta
Normal file
7
Assets/JustSign/Scenes/Game.unity.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1283017ac1c1f6226854442564bd7e3d
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -15,7 +15,7 @@ MonoBehaviour:
|
||||
index: 2
|
||||
title: Just Sign
|
||||
description: A rhythm game
|
||||
needsTheme: 1
|
||||
thumbnail: {fileID: 0}
|
||||
themeList: {fileID: 11400000, guid: a96bdbd3b1486d947a196fa1eb41d90b, type: 2}
|
||||
thumbnail: {fileID: 21300000, guid: 6d405f607ae817744b49f921f0611088, type: 3}
|
||||
minigameEntryPoint: JustSign/Scenes/Game
|
||||
controls: test
|
||||
controls: In this game, you will perform signs to the beat of the music.
|
||||
|
||||
267
Assets/JustSign/Scripts/JustSignController.cs
Normal file
267
Assets/JustSign/Scripts/JustSignController.cs
Normal file
@@ -0,0 +1,267 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Contains all game logic for the JustSign game
|
||||
/// </summary>
|
||||
public class JustSignController : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// All of the words that can be used in this session
|
||||
/// </summary>
|
||||
private List<Learnable> words = new List<Learnable>();
|
||||
|
||||
/// <summary>
|
||||
/// The canvas containing all components
|
||||
/// </summary>
|
||||
public Canvas canvas;
|
||||
|
||||
/// <summary>
|
||||
/// The input field where the user can type his or her answer
|
||||
/// </summary>
|
||||
public TMP_InputField answerField;
|
||||
|
||||
/// <summary>
|
||||
/// The feedback on the timing
|
||||
/// </summary>
|
||||
public TMP_Text feedBack;
|
||||
|
||||
/// <summary>
|
||||
/// The current score
|
||||
/// </summary>
|
||||
public TMP_Text scoreDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the minigame ScriptableObject
|
||||
/// </summary>
|
||||
public Minigame minigame;
|
||||
|
||||
/// <summary>
|
||||
/// The zone that the player should be hitting with his or her inputs
|
||||
/// </summary>
|
||||
public GameObject hitZone;
|
||||
|
||||
/// <summary>
|
||||
/// Symbol prefab
|
||||
/// </summary>
|
||||
public GameObject symbolPrefab;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to symbol prefab
|
||||
/// </summary>
|
||||
public Transform symbolContainer;
|
||||
|
||||
/// <summary>
|
||||
/// All of the available themes
|
||||
/// </summary>
|
||||
private ThemeList themeList;
|
||||
|
||||
/// <summary>
|
||||
/// The theme we are currently using
|
||||
/// </summary>
|
||||
private Theme currentTheme;
|
||||
|
||||
/// <summary>
|
||||
/// List of strings representing all words on the track
|
||||
/// </summary>
|
||||
private List<string> activeWords = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// List of objects representing all symbols on the track
|
||||
/// </summary>
|
||||
private List<GameObject> activeSymbols = new List<GameObject>();
|
||||
|
||||
/// <summary>
|
||||
/// The current score
|
||||
/// </summary>
|
||||
private int score;
|
||||
|
||||
/// <summary>
|
||||
/// Width and height of the symbols
|
||||
/// </summary>
|
||||
private int symbolSize = 280;
|
||||
|
||||
/// <summary>
|
||||
/// Controls movement speed of symbols (higher -> faster)
|
||||
/// </summary>
|
||||
private int moveSpeed = 200;
|
||||
|
||||
/// <summary>
|
||||
/// Starting X-coordinate of a symbol = (-1920 - symbolsize) / 2
|
||||
/// </summary>
|
||||
private int trackX = -1100;
|
||||
|
||||
/// <summary>
|
||||
/// Starting Y-coordinate of a symbol
|
||||
/// </summary>
|
||||
private int trackY = -200;
|
||||
|
||||
/// <summary>
|
||||
/// Max distance from hit zone to get perfect score
|
||||
/// </summary>
|
||||
private int perfectBoundary = 10;
|
||||
|
||||
/// <summary>
|
||||
/// Score obtained when getting a perfect hit
|
||||
/// </summary>
|
||||
private int perfectScore = 5;
|
||||
|
||||
/// <summary>
|
||||
/// Max distance from hit zone to get good score
|
||||
/// </summary>
|
||||
private int goodBoundary = 120;
|
||||
|
||||
/// <summary>
|
||||
/// Score obtained when getting a good hit
|
||||
/// </summary>
|
||||
private int goodScore = 3;
|
||||
|
||||
/// <summary>
|
||||
/// Max distance from hit zone to get meh score
|
||||
/// </summary>
|
||||
private int mehBoundary = 200;
|
||||
|
||||
/// <summary>
|
||||
/// Score obtained when getting a meh hit
|
||||
/// </summary>
|
||||
private int mehScore = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Score obtained when getting a terrible hit
|
||||
/// </summary>
|
||||
private int terribleScore = -3;
|
||||
|
||||
/// <summary>
|
||||
/// Score obtained when symbol goes offscreen
|
||||
/// </summary>
|
||||
private int offscreenScore = -5;
|
||||
|
||||
/// <summary>
|
||||
/// Time at which the last symbol was spawned
|
||||
/// </summary>
|
||||
private float lastSpawn;
|
||||
|
||||
/// <summary>
|
||||
/// Determines every how many seconds a symbol should spawn (will become music-dependent later on)
|
||||
/// </summary>
|
||||
private float spawnPeriod = 3.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Start is called before the first frame update
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
scoreDisplay.text = "Score: " + score.ToString();
|
||||
currentTheme = minigame.themeList.themes[minigame.themeList.currentThemeIndex];
|
||||
words.AddRange(currentTheme.learnables);
|
||||
//currentTheme = FindThemeByName(PlayerPrefs.GetString("themeName"));
|
||||
//words = currentTheme.words;
|
||||
lastSpawn = Time.time;
|
||||
SpawnNewSymbol();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update is called once per frame
|
||||
/// </summary>
|
||||
void Update()
|
||||
{
|
||||
int matchedSymbolIndex = -1;
|
||||
for (int i = 0; i < activeWords.Count; i++) {
|
||||
if (activeWords[i].ToLower() == answerField.text.ToLower()) {
|
||||
matchedSymbolIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy the oldest symbol if the current input matches it
|
||||
if (matchedSymbolIndex >= 0) {
|
||||
int difference = Math.Abs((int) (activeSymbols[matchedSymbolIndex].transform.position.x - hitZone.transform.position.x));
|
||||
if (difference < perfectBoundary) {
|
||||
feedBack.text = "Perfect!";
|
||||
score += perfectScore;
|
||||
} else if (difference < goodBoundary) {
|
||||
feedBack.text = "Good!";
|
||||
score += goodScore;
|
||||
} else if (difference < mehBoundary) {
|
||||
feedBack.text = "Meh...";
|
||||
score += mehScore;
|
||||
} else {
|
||||
feedBack.text = "Terrible!";
|
||||
score += terribleScore;
|
||||
}
|
||||
|
||||
DestroySymbolAt(matchedSymbolIndex);
|
||||
answerField.text = "";
|
||||
}
|
||||
|
||||
// Destroy the oldest symbol if it leaves the screen
|
||||
if (activeSymbols.Count > 0) {
|
||||
if (activeSymbols[0].GetComponent<RectTransform>().localPosition.x > -trackX) {
|
||||
DestroySymbolAt(0);
|
||||
score += offscreenScore;
|
||||
}
|
||||
}
|
||||
|
||||
// Spawn new symbol every spawn period
|
||||
float currentTime = Time.time;
|
||||
if (currentTime - lastSpawn > spawnPeriod) {
|
||||
lastSpawn = currentTime;
|
||||
SpawnNewSymbol();
|
||||
}
|
||||
|
||||
// Move all active symbols to the right
|
||||
foreach (GameObject symbol in activeSymbols) {
|
||||
RectTransform rectTransform = symbol.GetComponent<RectTransform>();
|
||||
rectTransform.localPosition = new Vector3(rectTransform.localPosition.x + Time.deltaTime * moveSpeed, trackY, 0);
|
||||
}
|
||||
|
||||
scoreDisplay.text = "Score: " + score.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Destroy the symbol at the given index
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the symbol to destroy</param>
|
||||
void DestroySymbolAt(int index) {
|
||||
activeWords.RemoveAt(index);
|
||||
GameObject symbol = activeSymbols[index];
|
||||
activeSymbols.RemoveAt(index);
|
||||
Destroy(symbol);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new symbol at the start of the track
|
||||
/// </summary>
|
||||
void SpawnNewSymbol() {
|
||||
// Pick a word that isn't in use yet
|
||||
List<int> unusedWordIndices = new List<int>();
|
||||
|
||||
for (int i = 0; i < words.Count; i++) {
|
||||
if (!activeWords.Contains(words[i].name)) {
|
||||
unusedWordIndices.Add(i);
|
||||
}
|
||||
}
|
||||
|
||||
Learnable newLearnable = words[unusedWordIndices[UnityEngine.Random.Range(0, unusedWordIndices.Count)]];
|
||||
string nextSymbol = newLearnable.name;
|
||||
|
||||
GameObject newSymbolObject = GameObject.Instantiate(symbolPrefab, symbolContainer);
|
||||
|
||||
// Dynamically load appearance
|
||||
Image image = newSymbolObject.GetComponent<Image>();
|
||||
image.sprite = newLearnable.image;
|
||||
image.rectTransform.sizeDelta = new Vector2(symbolSize, symbolSize);
|
||||
|
||||
// Place the word that the symbol represents under the image
|
||||
TMP_Text text = newSymbolObject.GetComponentInChildren<TMP_Text>();
|
||||
text.text = nextSymbol;
|
||||
text.color = Color.black;
|
||||
text.rectTransform.localPosition = new Vector3(0, -160, 0);
|
||||
|
||||
activeWords.Add(nextSymbol);
|
||||
activeSymbols.Add(newSymbolObject);
|
||||
}
|
||||
}
|
||||
15
Assets/JustSign/Scripts/JustSignController.cs.meta
Normal file
15
Assets/JustSign/Scripts/JustSignController.cs.meta
Normal file
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
<<<<<<<< HEAD:Assets/JustSign/Scripts/JustSignController.cs.meta
|
||||
guid: 9ede962218eda88668cd8032b921aada
|
||||
========
|
||||
guid: 40ff941e1b34847bdb160c6950f35aec
|
||||
>>>>>>>> development:Assets/MediaPipeUnity/Common/Scripts/KeypointManager.cs.meta
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"name": "JustSignScripts"
|
||||
}
|
||||
72
Assets/JustSign/Scripts/JustSignWebcam.cs
Normal file
72
Assets/JustSign/Scripts/JustSignWebcam.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Class to manage all webcam stuff inside the SpellingBee minigame
|
||||
/// </summary>
|
||||
public class JustSignWebcam : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Index of the current camera
|
||||
/// </summary>
|
||||
int camdex = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Texture to paste on the display
|
||||
/// </summary>
|
||||
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>
|
||||
/// 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();
|
||||
}
|
||||
}
|
||||
13
Assets/JustSign/Scripts/JustSignWebcam.cs.meta
Normal file
13
Assets/JustSign/Scripts/JustSignWebcam.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9291edb7593521fbb7e0a486724fd3c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- minigameList: {fileID: 11400000, guid: 51453f9b41bc72f468ba3e67ab622f8f, type: 2}
|
||||
- display: {instanceID: 0}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user