// Use this for initialization /// <summary> /// define all the keywords to look out for. /// </summary> void Start() { textManager = textManagerObject.GetComponent <TextManager>(); offsetFix = controller.GetComponent <OffsetFix>(); boxCounter = counter.GetComponent <BoxCounter>(); controllerMesh = controllerObject.GetComponent <Renderer>(); controllerMesh.enabled = true; keywords.Add("align", () => { if (textManager.gameState == GameState.AlignArm) { offsetFix.AlignAxes(); textManager.gameState = GameState.ArmAligned; controllerMesh.enabled = false; } }); keywords.Add("start", () => { if (textManager.gameState == GameState.ArmAligned) { textManager.gameState = GameState.TimerStarted; } }); keywords.Add("left", () => { if (textManager.gameState == GameState.StartMenu) { textManager.saidLeft = true; } }); keywords.Add("right", () => { if (textManager.gameState == GameState.StartMenu) { textManager.saidRight = true; } }); keywords.Add("again", () => { if (textManager.gameState == GameState.TimerEnded) { textManager.saidRestart = true; } }); //create the keyword recognizer and tell it what to recognize keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray()); //register for the OnPhraseRecognized event keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized; keywordRecognizer.Start(); }
// Use this for initialization void Start() { countdown.text = "press 's' to start timer,\nyou have 60 seconds"; boxCounter = GetComponent <BoxCounter>(); }
/// <summary> /// check which game state the game is in and execute code specific to the game state. /// </summary> void Update() { switch (gameState) { case GameState.StartMenu: // Wait for user to select a hand. Once selected, start mapping the room #if !UNITY_EDITOR InstructionTextMesh.text = "Welcome to HoloLens Prosthesis Trainer!\nPlease select which arm the prosthesis is on.\n(say 'left' or 'right')"; #else InstructionTextMesh.text = "Welcome to HoloLens Prosthesis Trainer!\nPlease select which arm the prosthesis is on.\n(press 'l' or 'r')"; #endif if (Input.GetKeyDown("l") || saidLeft) { rightHand = false; StartMapping(); } else if (Input.GetKeyDown("r") || saidRight) { rightHand = true; StartMapping(); } break; case GameState.RoomScan: // Call ScanText() while room is being scanned. ScanText(); break; case GameState.DoneScan: // Scan is complete, game state will be updated in TapAndPlace.cs InstructionTextMesh.text = "Scan done.\nSelect a sphere to place box and blocks test."; break; case GameState.BoxPlaced: // Box and blocks has been placed. Stop spatial mapping from updating the mesh of the room. // disable spatial understanding to get rid of the mesh of the scanned room. SpatialMappingManager.Instance.StopObserver(); spatialUnderstanding.SetActive(false); EnableObjectsForTest(); break; case GameState.AlignArm: // Arm is aligned, waits for either voice input or keyboard and game state will be updated by either // OffsetFix.cs or VoiceManager.cs #if !UNITY_EDITOR InstructionTextMesh.text = "align controller with hologram and say 'align'"; #else InstructionTextMesh.text = "align controller with hologram and press 'space'"; #endif break; case GameState.ArmAligned: // wait until timer is started. Game state updated when s pressed, or by VoiceManager.cs when // user says 'start' #if !UNITY_EDITOR InstructionTextMesh.text = "When ready, say 'start' to start test.\nYou have 60 seconds."; #else InstructionTextMesh.text = "When ready, press 's' to start test.\nYou have 60 seconds."; #endif if (Input.GetKeyDown("s")) { gameState = GameState.TimerStarted; } break; case GameState.TimerStarted: // counts down until test time is up. When time is up advance to next game state. if (countTime > 0) { countTime -= Time.deltaTime; InstructionTextMesh.text = countTime.ToString(); } else { countTrigger = GameObject.Find("CountTrigger"); boxCounter = countTrigger.GetComponent <BoxCounter>(); numBlocks = boxCounter.boxCount; gameState = GameState.TimerEnded; } break; case GameState.TimerEnded: // displays text for when the timer is up. Shows how many blocks had been successfully transferred. // waits for user to either restart the test or exit the game. If restarted, resets all the prefabs // and changed back to ArmAlign state. #if !UNITY_EDITOR InstructionTextMesh.text = "Time's up! You successfully moved " + numBlocks + " blocks.\n Would you like to try again?\n(say 'again' to try again, or do the bloom gesture to end the game.)"; #else InstructionTextMesh.text = "Time's up! You successfully moved " + numBlocks + " blocks.\n Would you like to try again?\n(press 'r' to try again, or do the bloom gesture to end the game.)"; #endif if (Input.GetKeyDown("r") || saidRestart) { saidRestart = false; boxCounter.boxCount = 0; countTime = 20; gameState = GameState.ArmAligned; GameObject pickupInstantiator = GameObject.Find("PickUpInstatiator"); instantiatorController = pickupInstantiator.GetComponent <InstantiatorController>(); instantiatorController.ResetPrefabs(); } break; } }