コード例 #1
0
    private void Update()
    {
        if (!started && triggerScript.getStatusTriggerRight())
        {
            Debug.Log("recording started");
            fw.StartRecording();
            started = true;
        }
        if (newtrial)
        {
            // reset all variables from the old trial
            for (int i = 0; i <= feedbackmodel.Count - 1; i++)
            {
                feedbackmodel[i].Gameobject.GetComponent <MeshRenderer>().enabled = false;
            }

            feedbackmodel = new List <FeedbackModel>();
            //passwordmodel = new PasswordModel(new List<String>() { "POS1", "POS2", "POS3", "POS4" }, 4);
            userPassword.Clear();
            if (trials <= 7)
            {
                // rotate back to original position

                trials++;
                newtrial = false;
            }
            else if (trials == 8)
            {
                GameObject.Find("tiger_idle").transform.Rotate(0, 90, 0);
                trials++;
                newtrial = false;
            }
            else if (trials == 9)
            {
                GameObject.Find("tiger_idle").transform.Rotate(0, 270, 0);
                trials++;
                newtrial = false;
            }
            else if (trials == 10)
            {
                GameObject.Find("tiger_idle").transform.Rotate(0, 180, 0);
                trials++;
                newtrial = false;
            }
            else
            {
                SceneManager.LoadScene(sceneName: "playground");
            }
        }
        // show 3D model and start recording (see DataHandler)
        if (Input.GetKeyDown(KeyCode.R))
        {
            newtrial = true;
            //Debug.Log("lets go");
            GameObject.Find("Tiger_Mesh").GetComponent <SkinnedMeshRenderer>().enabled = true;
            GameObject.Find("Collider").SetActive(true);
        }
        //current_time += Time.deltaTime;
        if (feedbackmodel.Count >= 0)
        {
            for (int i = 0; i <= feedbackmodel.Count - 1; i++)
            {
                feedbackmodel[i].Time -= Time.deltaTime;
                if (feedbackmodel[i].Time <= 0)
                {
                    feedbackmodel[i].Gameobject.GetComponent <MeshRenderer>().enabled = false;
                    feedbackmodel.RemoveAt(i);
                }
            }
        }

        //if (triggerScript.getStatusTriggerLeft())
        //{
        //Debug.Log("rotate graphical password");
        //  GameObject.Find("tiger_idle").transform.Rotate(0, 90, 0);
        // }


        if (_eyeTracker.Connected)
        {
            // Reset any priviously set active object and remove its highlight
            if (_highlightInfo.HighlightedObject != null)
            {
                var renderer = _highlightInfo.HighlightedObject.GetComponent <MeshRenderer>();
                _highlightInfo.HighlightedObject      = null;
                _highlightInfo.OriginalObjectMaterial = null;
            }
            var latestHitObject = _gazeTrail.LatestHitObject;
            if (latestHitObject != null)
            {
                if (latestHitObject.gameObject != _highlightInfo.HighlightedObject &&
                    latestHitObject.name.StartsWith("POS") && triggerScript.getStatusTriggerRight())

                {
                    feedbackmodel.Add(new FeedbackModel(latestHitObject.gameObject, latestHitObject.gameObject.GetComponent <MeshRenderer>().material, feedback_time));
                    passwordmodel.backupInput(latestHitObject.gameObject.name);
                    // Debug.Log("selected via gaze and trigger");
                    MeshRenderer renderer = latestHitObject.gameObject.GetComponent <MeshRenderer>();
                    renderer.enabled  = true;
                    renderer.material = _highlightMaterial;

                    userPassword.Add(latestHitObject.name);
                    // Debug.Log(latestHitObject.name);

                    if (userPassword.Count == 4)
                    {
                        Debug.Log("recording stopped");

                        fw.StopRecording();
                        Debug.Log("ok count 4");
                        Debug.Log(userPassword[0]);
                        Debug.Log(userPassword[1]);
                        Debug.Log(userPassword[2]);
                        Debug.Log(userPassword[3]);

                        PINS = GameObject.FindGameObjectsWithTag("PIN");
                        if (passwordmodel.checkPassword(userPassword))
                        {
                            Debug.Log("correct");
                            for (int i = 0; i <= PINS.Length - 1; i++)
                            {
                                PINS[i].GetComponent <MeshRenderer>().enabled = true;

                                PINS[i].GetComponent <MeshRenderer>().material = _inputcorrect;
                            }
                        }
                        else
                        {
                            Debug.Log("feedback wrong");

                            for (int i = 0; i <= PINS.Length - 1; i++)
                            {
                                PINS[i].GetComponent <MeshRenderer>().enabled = true;

                                PINS[i].GetComponent <MeshRenderer>().material = _inputwrong;
                            }
                        }

                        passwordmodel.entryError(userPassword);
                        manouver_time -= Time.deltaTime;
                        if (manouver_time <= 0)
                        {
                            newtrial      = true;
                            manouver_time = 2;
                        }
                        // Debug.Log("new run");
                        //Debug.Log("number of errors " + passwordmodel.getErrors());
                        // Debug.Log(passwordmodel.checkPassword(userPassword));
                    }
                }
                _gazeTrail.ParticleColor = Color.blue;
            }
        }
    }