Пример #1
0
    public void StopVisualizingGaze()
    {
        Instance.OnUpdate -= VisualizeGaze;

        PupilMarker.TryToSetActive(_markerLeftEye, false);
        PupilMarker.TryToSetActive(_markerRightEye, false);
        PupilMarker.TryToSetActive(_markerGazeCenter, false);
        PupilMarker.TryToSetActive(_gaze3D, false);

        PupilTools.IsIdle = true;
        //		PupilTools.UnSubscribeFrom("gaze");
    }
Пример #2
0
 public void hideGaze()
 {
     PupilMarker.TryToSetActive(_markerGazeCenter, false);
 }
Пример #3
0
 public void showGaze()
 {
     PupilMarker.TryToSetActive(_markerGazeCenter, true);
 }
Пример #4
0
    void Update()
    {
        if (PupilTools.IsConnected && PupilTools.IsGazing && (isTraining || isStudy))
        {
            //timeManager time = new timeManager();
            if (isStudy && !Lock)
            {
                //set target to next index
                //if no target set to false and save data
                if (currentOrder < 24)
                {
                    Debug.Log("set random target for study");
                    targetclicker.setTargetActive(order[currentOrder]);
                    currentOrder++;
                    Lock = true;
                }
                else
                {
                    isStudy = false;
                    streamWriter.Close();
                    currentOrder = 0;
                    return;
                }

                //save data
            }
            else if (isTraining && !Lock)
            {
                Debug.Log("set random target for training");
                //random generate data
                int trainingIndex = UnityEngine.Random.Range(0, order.Length);
                targetclicker.setTargetActive(trainingIndex);
                Lock = true;
            }

            if (isRefining)
            {
                Vector2 deltaHead = this.transform.forward - lockHeadForward;
                gazePointCenter = lockCursor.camera.WorldToViewportPoint(lockEyeWorldPoint);
                lockCursor.UpdatePosition(gazePointCenter);
                headCursor.UpdatePosition(gazePointCenter + Vector2.Scale(scaler, deltaHead));
            }
            else
            {
                gazePointCenter = PupilData._2D.GazePosition;
            }


            //missing head point
            streamWriter.WriteLine(gazePointCenter);//save in json
            if (Input.GetKeyDown(KeyCode.R))
            {
                if (!isRefining)
                {
                    Debug.Log("Enter refinement mode.");
                    isRefining      = true;
                    lockHeadForward = this.transform.forward;
                    PupilGazeTracker.Instance.hideGaze();
                    headCursor = new PupilMarker("Head", Color.blue);
                    headCursor.UpdatePosition(gazePointCenter);
                    lockCursor = new PupilMarker("Lock", Color.red);
                    lockCursor.UpdatePosition(gazePointCenter);
                    lockEyeWorldPoint    = lockCursor.WorldPoint();
                    storedCameraRotation = Camera.main.transform.rotation;
                    timeManager.myInstance.pressRefine();
                    streamWriter.WriteLine("enter refine:" + gazePointCenter);
                    Debug.Log(gazePointCenter);
                }
            }
            else if (Input.GetKeyUp(KeyCode.R) && isRefining)
            {
                //Debug.Log(time.selectTime);
                Debug.Log("Exit refinement mode.");
                //write to Txt file
                streamWriter.WriteLine("exit refine:" + gazePointCenter);
                Debug.Log(gazePointCenter);

                // AssetDatabase.ImportAsset(path);
                // TextAsset asset = Resources.Load("test");
                isRefining = false;
                PupilGazeTracker.Instance.showGaze();
                PupilMarker.TryToSetActive(headCursor, false);
                PupilMarker.TryToSetActive(lockCursor, false);
                timeManager.myInstance.releaseRefine();
                Lock = false;
                //send request to upload movement data
            }
        }
        //change condition
        if (Input.GetKey(KeyCode.Z) && !isStudy)
        {
            Debug.Log("switch to condition1");
            conditionID  = 0;
            path         = "Assets/test" + idNum.ToString() + "_" + conditionID.ToString() + ".txt"; //txt save file
            fileStream   = new FileStream(path, FileMode.Create);
            streamWriter = new StreamWriter(fileStream);
            isTraining   = true;
            setCenter();
        }
        else if (Input.GetKey(KeyCode.X) && !isStudy)
        {
            Debug.Log("switch to condition2");
            conditionID  = 1;
            path         = "Assets/test" + idNum.ToString() + "_" + conditionID.ToString() + ".txt"; //txt save file
            fileStream   = new FileStream(path, FileMode.Create);
            streamWriter = new StreamWriter(fileStream);
            isTraining   = true;
            setCenter();
        }
        else if (Input.GetKey(KeyCode.C) && !isStudy)
        {
            Debug.Log("switch to condition3");
            conditionID  = 2;
            path         = "Assets/test" + idNum.ToString() + "_" + conditionID.ToString() + ".txt"; //txt save file
            fileStream   = new FileStream(path, FileMode.Create);
            streamWriter = new StreamWriter(fileStream);
            isTraining   = true;
            setCenter();
        }
        else if (Input.GetKey(KeyCode.V) && !isStudy)
        {
            Debug.Log("switch to condition4");
            conditionID  = 3;
            path         = "Assets/test" + idNum.ToString() + "_" + conditionID.ToString() + ".txt"; //txt save file
            fileStream   = new FileStream(path, FileMode.Create);
            streamWriter = new StreamWriter(fileStream);
            isTraining   = true;
            setCenter();
        }
        else if (Input.GetKey(KeyCode.Space))
        {
            if (isTraining)
            {
                isTraining = false;
                generateOrder();
                isStudy = true;
            }
        }
    }