// Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        globalTimer += Time.deltaTime;

        if (Input.GetKeyDown(KeyCode.P))
        {
            if (pilotIndex < 0)
            {
                RunPilot();
            }
        }

        // Doesn't check input if not enough time has elapsed since last input
        if (timer < TIMER_THRESHOLD || pilotIndex < 0)
        {
            return;
        }



        if ((Input.GetKeyDown(KeyCode.Z) || Input.GetKeyDown(KeyCode.X) || OVRInput.Get(OVRInput.Button.One) || OVRInput.Get(OVRInput.Button.Three)))
        {
            //Only triggers for every other, in order to save data
            if (pilotIndex > 5 && pilotIndex < 24 && pilotIndex % 2 == 0)
            {
                if (fileName == "" || type == "" || barChosen == -1 || responseRatio == -1)
                {
                    Debug.Log("ERROR - Attempted to record incomplete info.");
                    return;
                }
            }


            // This triggers for all of the experimental steps
            if (pilotIndex >= PREAMBLE_LEN - 1 && pilotIndex < (2 * NUM_EXPERIMENTS) + PREAMBLE_LEN)
            {
                

                if (pilotIndex % 2 == 0)
                {
                    // This section records the previous step
                    if (pilotIndex > PREAMBLE_LEN + 1)
                    {
                        responseRatio = meter.GetNum() / 100.0f;

                        // Logs the past entry
                        // NOTE: DOES NOT SAVE TO DISK. Use logger.CloseFile() to save all logged entries. 
                        logger.RecordResults(type, deltaSecsInit, fileName,
                            head.transform.position, head.transform.rotation,
                            VisualizationObject.transform.position, VisualizationObject.transform.rotation,
                            barChosen, responseRatio, timer);
                    }

                    int i = (pilotIndex - PREAMBLE_LEN) / 2;

                    fileName = fileNames[i];

                    Vector3 personalDeltaPos = headObjInitPos - head.transform.position,
                        personalDeltaRot = headObjInitRot - head.transform.rotation.eulerAngles;


                    VisualizationObject.transform.rotation = Quaternion.Euler(vizObjInitRot + rotations[i] + personalDeltaRot);
                    VisualizationObject.transform.position = vizObjInitPos + translations[i] + personalDeltaPos;


                    // This section shows the upcoming step
                    instructionTextMesh.text = textArray[PREAMBLE_LEN];


                    controller.WriteSpecFile(fileName + "Spec", templateString[0] + fileName + templateString[1]);
                    controller.UpdateVis(fileName + "Spec.json");
                    remainingCounterTextMesh.text = (((pilotIndex - PREAMBLE_LEN) / 2) + 1) + "/" + NUM_EXPERIMENTS;

                    meter.SetStatus(false);
                }
                else
                {
                    // This section records the previous step
                    barChosen = Input.GetKeyDown(KeyCode.Z) || OVRInput.Get(OVRInput.Button.Three) ? 0 : 1;
                    deltaSecsInit = timer;

                    // This section shows the upcoming step
                    instructionTextMesh.text = textArray[PREAMBLE_LEN + 1];

                    meter.SetStatus(true);
                }
            }

            // Triggers only on the last slide
            else if (pilotIndex == (2 * NUM_EXPERIMENTS) + PREAMBLE_LEN)
            {
                responseRatio = meter.GetNum() / 100.0f;

                // Logs the past entry
                // NOTE: DOES NOT SAVE TO DISK. Use logger.CloseFile() to save all logged entries. 
                logger.RecordResults(type, deltaSecsInit, fileName,
                    head.transform.position, head.transform.rotation,
                    VisualizationObject.transform.position, VisualizationObject.transform.rotation,
                    barChosen, responseRatio, timer);

                instructionTextMesh.text = textArray[PREAMBLE_LEN + 2];

                VisualizationObject.SetActive(false);
                meter.SetStatus(false);
            }

            // Triggers after the last slide - closes and saves everything
            else if (pilotIndex > (2 * NUM_EXPERIMENTS) + PREAMBLE_LEN)
            {
                pilotIndex = -1;

                logger.CloseFile();

                instructionPanel.SetActive(false);
                return; //neccesary so it doesn't increment index again
            }

            // Triggers for the preamble slides
            if (pilotIndex == 0)
            {
                VisualizationObject.SetActive(true);
                counterText.SetActive(true);
            }

            logger.LogPose(globalTimer, head.transform.position, head.transform.rotation.eulerAngles);
            timer = 0;
            pilotIndex++;

        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;

        if (Input.GetKeyDown(KeyCode.T))
        {
            Debug.Log("Running Tutorial");
            if (tutorialIndex < 0)
            {
                RunTutorial();
            }
        }

        // Doesn't check input if not enough time has elapsed since last input
        if (timer < TIMER_THRESHOLD || tutorialIndex < 0)
        {
            return;
        }



        if ((Input.GetKeyDown(KeyCode.Z) || Input.GetKeyDown(KeyCode.X) || OVRInput.Get(OVRInput.Button.One) || OVRInput.Get(OVRInput.Button.Three)))
        {
            Debug.Log("input recieved");

            // This triggers for all of the experimental steps
            if (tutorialIndex >= PREAMBLE_LEN - 1 && tutorialIndex < (2 * NUM_EXPERIMENTS) + PREAMBLE_LEN - 1)
            {
                //Triggers for the first part of a plot experiment, i.e. which bar is smaller
                if (tutorialIndex % 2 == 0)
                {
                    // This section records the previous step
                    if (tutorialIndex > PREAMBLE_LEN + 1)
                    {
                        responseRatio = (float)meter.GetNum() / 100.0f;

                        // Logs the past entry
                        // NOTE: DOES NOT SAVE TO DISK. Use logger.CloseFile() to save all logged entries.
                        logger.RecordResults(type, deltaSecsInit, fileName,
                                             head.transform.position, head.transform.rotation,
                                             vizObjInitPos, vizObjInitRot,
                                             barChosen, responseRatio, timer);
                    }


                    // This section shows the upcoming step
                    instructionTextMesh.text = textArray[PREAMBLE_LEN];


                    if ((tutorialIndex - PREAMBLE_LEN) < NUM_EXPERIMENTS)
                    {
                        type = "1";
                    }
                    else
                    {
                        type = "3";
                    }
                    exampleIndex = "" + (tutorialIndex % 4);
                    fileName     = "2D_T" + type + "_" + exampleIndex;

                    controller.WriteSpecFile(fileName + "_Spec", templateString[0] + fileName + templateString[1]);
                    controller.UpdateVis(fileName + "_Spec.json");

                    meter.SetStatus(false);
                }

                //Triggers for the ratio estimation portion
                else
                {
                    // This section records the previous step
                    barChosen     = Input.GetKeyDown(KeyCode.Z) || OVRInput.Get(OVRInput.Button.Three) ? 0 : 1;
                    deltaSecsInit = timer;

                    // This section shows the upcoming step
                    instructionTextMesh.text = textArray[PREAMBLE_LEN + 1];
                    meter.SetStatus(true);
                }
            }

            // Triggers only on the last slide
            else if (tutorialIndex == (2 * NUM_EXPERIMENTS) + PREAMBLE_LEN - 1)
            {
                responseRatio = (float)meter.GetNum() / 100.0f;

                // Logs the past entry
                // NOTE: DOES NOT SAVE TO DISK. Use logger.CloseFile() to save all logged entries.
                logger.RecordResults(type, deltaSecsInit, fileName,
                                     head.transform.position, head.transform.rotation,
                                     vizObjInitPos, vizObjInitRot,
                                     barChosen, responseRatio, timer);

                VisualizationObject.SetActive(false);

                instructionTextMesh.text = textArray[PREAMBLE_LEN + 2];
            }

            // Triggers after the last slide - closes and saves everything
            else if (tutorialIndex >= (2 * NUM_EXPERIMENTS) + PREAMBLE_LEN)
            {
                tutorialIndex = -1;

                logger.CloseFile();

                instructionPanel.SetActive(false);
                meter.SetStatus(false);
                return; //neccesary so it doesn't increment index again
            }

            //Handles the preamble slides individually
            else
            {
                switch (tutorialIndex)
                {
                case 1:
                    if ((Input.GetKeyDown(KeyCode.Z) || OVRInput.Get(OVRInput.Button.Three)))
                    {
                        return;
                    }

                    break;

                case 2:
                    if ((Input.GetKeyDown(KeyCode.X) || OVRInput.Get(OVRInput.Button.One)))
                    {
                        return;
                    }

                    meter.SetStatus(true);
                    break;

                case 3:
                    if ((Input.GetKeyDown(KeyCode.Z) || OVRInput.Get(OVRInput.Button.Three)))
                    {
                        return;
                    }
                    meter.SetStatus(false);
                    exampleArray.SetActive(true);


                    break;

                case 4:
                    if ((Input.GetKeyDown(KeyCode.Z) || OVRInput.Get(OVRInput.Button.Three)))
                    {
                        return;
                    }
                    exampleArray.SetActive(false);

                    break;

                case 5:
                    if ((Input.GetKeyDown(KeyCode.Z) || OVRInput.Get(OVRInput.Button.Three)))
                    {
                        return;
                    }

                    break;

                case 6:
                    VisualizationObject.SetActive(true);

                    break;
                }

                instructionTextMesh.text = textArray[tutorialIndex + 1];
            }

            timer = 0;
            tutorialIndex++;
        }
    }