/// <summary>
    ///
    /// </summary>
    void Start()
    {
        textManagerObject = GameObject.Find("TextManager");
        textManagerScript = textManagerObject.GetComponent <TextManager>();

        instantiatorController = instantiator.GetComponent <InstantiatorController>();
        boxCount = 0;
    }
Example #2
0
    /// <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;
        }
    }