コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        try
        {
            if (transitioning)
            {
                return;
            }

            // Test currently running.
            if (state == RunState.TestRunning)
            {
                if (!tutorialActive && searchTimeLimit > 0 && (Time.time - stateStartTime) > searchTimeLimit)
                {
                    EndTest();
                    if (tests.Count > 0)
                    {
                        StartCoroutine(WaitThenActivate(0.5f, GetNextTest(), ShowRealVal, null));
                    }
                    else
                    {
                        StartCoroutine(WaitThenActivate(0.5f, null, EndTestPass));
                    }
                }

                //Activate/Deactivate applicable tooltips.
                if (selectionHandler.IsPointing())
                {
                    A_Button_Tooltip.SetActive(true);
                }
                else
                {
                    A_Button_Tooltip.SetActive(false);
                }

                if (selectionHandler.HasSelected())
                {
                    X_Button_Tooltip.SetActive(true);
                }
                else
                {
                    X_Button_Tooltip.SetActive(false);
                }

                //Lock in the answer and transition to the next test.
                if (OVRInput.GetUp(lockinButton) && (skippingAllowed || selectionHandler.HasSelected()))
                {
                    EndTest();

                    if (tutorialActive)
                    {
                        if (tutorialTests.Count > 0)
                        {
                            StartCoroutine(WaitThenActivate(0.5f, GetNextTest(), ShowRealVal, null));
                        }
                        else
                        {
                            StartCoroutine(WaitThenActivate(0.5f, null, EndTutorial));
                        }
                    }

                    else
                    {
                        if (tests.Count > 0)
                        {
                            StartCoroutine(WaitThenActivate(0.5f, GetNextTest(), ShowRealVal, null));
                        }
                        else
                        {
                            StartCoroutine(WaitThenActivate(0.5f, null, EndTestPass));
                        }
                    }
                }
            }

            // Real value currently shown.
            if (state == RunState.RealValue)
            {
                if (!tutorialActive && exposureTimeLimit > 0 && (Time.time - stateStartTime) > exposureTimeLimit)
                {
                    StartCoroutine(WaitThenActivate(0.5f, currentTest, PrepareTest, StartTest));
                }

                //Change view to the running test.
                if (OVRInput.GetUp(lockinButton))
                {
                    StartCoroutine(WaitThenActivate(0.5f, currentTest, PrepareTest, StartTest));
                }
            }

            if (state == RunState.TutorialFinished)
            {
                //Start tutorial again
                if (OVRInput.GetUp(lockinButton))
                {
                    if (tutorialEndStart < 0)
                    {
                        tutorialEndStart = Time.time;
                    }
                    float timeHeld = Time.time - tutorialEndStart;
                    if (timeHeld > timeToHold)
                    {
                        //End tutorial
                        tutorialActive = false;
                        StartCoroutine(WaitThenActivate(0.5f, GetNextTest(), ShowRealVal, null));
                    }
                    else
                    {
                        tutorialEndIsHeld = false;
                        StartCoroutine(WaitThenActivate(0.5f, GetNextTest(), ShowRealVal, null));
                    }
                }

                if (OVRInput.Get(lockinButton))
                {
                    if (!tutorialEndIsHeld)
                    {
                        tutorialEndIsHeld = true;
                        tutorialEndStart  = Time.time;
                    }
                    logger.SetLog("Time Held: " + (Time.time - tutorialEndStart));
                }
                else
                {
                    tutorialEndIsHeld = false;
                }
            }

            // Initial state still active, neither test nor real value yet shown.
            // Any tutorial will be started from this stage.
            if (state == RunState.NotBegun)
            {
                if (OVRInput.GetUp(lockinButton))
                {
                    if (tests.Count != 0)
                    {
                        StartCoroutine(WaitThenActivate(0f, GetNextTest(), ShowRealVal));
                        startTime = DateTime.Now;
                    }
                }
            }

            // Final state when all testpasses are completed.
            // Any surveys or thank yous will be started from this stage.
            if (state == RunState.Finished)
            {
            }

            //LogDebugInfo();
        }
        catch (Exception e)
        {
            //Log any exception thrown.
            logger.gameObject.SetActive(true);
            logger.Log("Exception caught: " + e.GetType().Name);
            logger.Log(e.Message);
            logger.Log(e.StackTrace);
            throw e;
        }
    }