Example #1
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++;
        }
    }
    // 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++;

        }
    }
    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        if (Input.GetKeyDown(KeyCode.A))
        {
            Debug.Log("Running Angle");
            if (tutorialIndex < 0)
            {
                RunAngle();
            }
        }

        if (timer < 3.0f && Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log(timer + ", " + tutorialIndex);
        }

        float[] angles = new float[4];
        angles[0] = -45.0f;
        angles[1] = -15.0f;
        angles[2] = 15.0f;
        angles[3] = 45.0f;
        //Add more positions if necessary, default z position for the viz is
        //1.16, change the tenths place for useful differences.
        float[] positions = new float[4];
        positions[1] = .76f;
        positions[2] = .96f;
        positions[3] = 1.36f;
        positions[4] = 1.56f;

        if ((Input.GetKeyDown(KeyCode.Space) || OVRInput.Get(OVRInput.Button.One)) && tutorialIndex >= 0 && timer > 1.0f)
        {
            Debug.Log("Switch Logged.");
            timer = 0.0f;

            int           barOne, barTwo;
            System.Random rand = new System.Random();
            string[]      temp;
            string        result = "";

            string tempStr = controller.GenerateBar(9, (tutorialIndex % 5) + 1, rand);
            Debug.Log(tempStr);
            temp = tempStr.Split('|');

            controller.WriteDataFile("tutorial", temp[0]);
            barOne = Int32.Parse(temp[1]);
            barTwo = Int32.Parse(temp[2]);
            ratios[tutorialIndex - 4] = (barOne > barTwo) ? barTwo / barOne : barOne / barTwo;

            controller.UpdateVis("Tutorial_Spec.json");
            result += temp[0] + "," + temp[1] + "," + temp[2];

            ScaleObject.SetActive(false);

            //ROTATE

            VisualizationObject.transform.Rotate(Vector3.right * (angles[tutorialIndex % 4]));
            //Line for changing the position, my unity is malfunctioning so cannot
            //100% verif if it is correct, but it should compile.
            VisualizationObject.transform.position = new Vector3(-.024f, 1.23f, positions[tutorialIndex % 4]);
            tutorialIndex++;

            if (tutorialIndex == 20)
            {
                tutorialIndex = -1;
                instructionPanel.SetActive(false);
                VisualizationObject.SetActive(false);
                ScaleObject.SetActive(false);
            }
        }
    }