Exemplo n.º 1
0
 void OnTrackpadInteracted(GazeObject sender)
 {
     if (sender.IsActivated)
     {
         StreamController.Instance.EnableDrivingMode();
     }
 }
    /// <summary>
    /// Raycast/Sphercast way to detect mementos
    /// </summary>

    /*
     * void FixedUpdate()
     * {
     *  Ray ray = new Ray(Eye.position, Eye.forward);
     *  RaycastHit hit;
     *
     *  //if (Physics.Raycast(ray, out hit, Mathf.Infinity, GazeLayer))
     *  if(Physics.SphereCast(ray, 2.5f, out hit, Mathf.Infinity, GazeLayer))
     *  {
     *      // If there is no current gazed object, set gazed object to the hit
     *      if (!gazedObject)
     *          gazedObject = hit.collider.GetComponent<GazeObject>();
     *
     *      // If there is previous gazed object
     *      if (gazedObject)
     *      {
     *          // If the previous game object is not the same as the new hit
     *          if (gazedObject != hit.collider.GetComponent<GazeObject>())
     *          {
     *              gazedObject.OnGazeExit();
     *              gazedObject = hit.collider.GetComponent<GazeObject>();
     *              gazedObject.OnGazeStart();
     *          }
     *          else // If the previous game object is the same as the new hit
     *          {
     *              gazedObject.OnGazeStart();
     *              Debug.Log(gazedObject.name);
     *          }
     *      }
     *
     *  }
     *
     *  // If not gazing at anything
     *  if (!Physics.Raycast(ray, out hit, Mathf.Infinity, GazeLayer))
     *  {
     *      if (gazedObject)
     *      {
     *          gazedObject.OnGazeExit();
     *          //gazedObject = null;
     *      }
     *  }
     *
     * }
     */
    #endregion

    #region Attached to Capsule under Camera (eye)

    /// <summary>
    /// Pinocchio Nose Da Wae
    /// </summary>
    /// <param name="other"></param>
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("GazeObject"))
        {
            // If there is no current gazed object, set gazed object to the hit
            if (!gazedObject)
            {
                gazedObject = other.GetComponent <GazeObject>();
            }

            // If there is previous gazed object
            if (gazedObject)
            {
                // If the previous game object is not the same as the new hit
                if (gazedObject != other.GetComponent <GazeObject>())
                {
                    gazedObject.OnGazeExit();
                    gazedObject = other.GetComponent <GazeObject>();
                    gazedObject.OnGazeStart();
                }
                else // If the previous game object is the same as the new hit
                {
                    gazedObject.OnGazeStart();
                }
            }
        }
    }
Exemplo n.º 3
0
        private void Start()
        {
            audio                = GetComponent <AudioSource>();
            gaze                 = GetComponent <GazeObject>();
            gaze.GazeEvent      += GazeEvent;
            gaze.GazeEnterEvent += GazeEnter;
            gaze.GazeExitEvent  += GazeExit;

            //glow.Play();
        }
Exemplo n.º 4
0
 private void Start()
 {
     walker = GetComponent <SplineWalker>();
     gaze   = GetComponent <GazeObject>();
     ResetInteractable();
     GameFlowManager.Instance.Register(GameState.COCOON, () => ResetInteractable());
     GameFlowManager.Instance.Register(GameState.FRUIT, () => ResetInteractable());
     GameFlowManager.Instance.Register(GameState.BIRD, () => ResetInteractable());
     GameFlowManager.Instance.Register(GameState.DOG, () => ResetInteractable());
     GameFlowManager.Instance.Register(GameState.PINWHEEL, () => Destroy(gameObject));
 }
Exemplo n.º 5
0
    private void Update()
    {
        Vector3 dir = transform.forward;

        RaycastHit[] hits = Physics.RaycastAll(transform.position, dir, 100);
        GazeObject   g    = hits.Length > 0 ? hits[0].collider.GetComponent <GazeObject>() : null;

        // Update currently gazed and events
        if (g != gazed)
        {
            // Exit old gaze object
            if (gazed != null)
            {
                gazed.OnGazeExit();
            }

            // Enter new gaze object
            if (g != null)
            {
                g.OnGazeEnter();
            }

            // Gazed could now be null or a new object
            gazed = g;
        }
        else
        {
            // Stay in same gaze object (or no gaze object)
            if (g != null)
            {
                g.OnGazeStay();
            }
        }


        // Reticle
        if (reticle != null)
        {
            if (g == null)
            {
                //reticle.gameObject.SetActive(false);
                reticle.position = transform.position + dir * default_distance;
            }
            else
            {
                //reticle.gameObject.SetActive(true);
                reticle.position = hits[0].point - dir * reticle_offset;
            }

            reticle.rotation = Quaternion.LookRotation(dir);
        }
    }
Exemplo n.º 6
0
 private void Start()
 {
     gaze = GetComponent <GazeObject>();
     Register(WHEELSTATE.IDLE, () => {
         gaze.GazeEvent += Rotate;
         rotateCoroutine = StartCoroutine(Rotate());
         particle.Play();
     });
     Register(WHEELSTATE.INTERACTABLE, () => {
         gaze.GazeEvent -= Rotate;
         gaze.focusTime  = 0;
         particle.Stop();
     });
     //GameFlowManager.Instance.Register(GameState.PETALFLY, () => NextState());
 }
Exemplo n.º 7
0
    private void ResetHoveredObject()
    {
        if (_hoveredGazeObject != null)
        {
            _hoveredGazeObject.OnUnhover();
        }
        _hoveredGazeObject = null;
        if (RobotInterface.Instance)
        {
            RobotInterface.Instance.StopRobot();
        }

        if (VirtualUnityController.Instance)
        {
            VirtualUnityController.Instance.StopRobot();
        }
    }
Exemplo n.º 8
0
 private void Start()
 {
     gaze = GetComponent <GazeObject>();
     Register(DOGSTATE.IDLE, () => {
         gaze.GazeEvent += Waking;
         particle.Play();
     });
     Register(DOGSTATE.INTERACTABLE, () => {
         gaze.GazeEvent -= Waking;
         gaze.focusTime  = 0;
         particle.Stop();
         // StartCoroutine(PetalFlyCoroutine());
     });
     Register(DOGSTATE.RUNNING, () => {
         GameProgress.Instance.InteractedCount++;
     });
     //GameFlowManager.Instance.Register(GameState.PETALFLY, () => NextState());
 }
    // Update is called once per frame
    void Update()
    {
        RaycastHit hit;

        Debug.DrawLine(transform.position, transform.forward * lookDistance);
        if (Physics.Raycast(transform.position, transform.forward, out hit, lookDistance))
        {
            Debug.Log("hit");
            timer += Time.deltaTime;
            if (timer > detectTime)
            {
                GazeObject gazeObject = hit.collider.GetComponent <GazeObject>();
                if (gazeObject && (!detectedObject || gazeObject == detectedObject))
                {
                    detectedObject = gazeObject;
                    Debug.Log("detect");
                    gazeObject.OnDetect();
                    if (timer > focusTime)
                    {
                        Debug.Log("focus");
                        gazeObject.OnFocus();
                    }
                }
                else
                {
                    timer = 0;
                    if (detectedObject)
                    {
                        detectedObject.OnDetectExit();
                        detectedObject = null;
                    }
                }
            }
        }
        else
        {
            timer = 0;
            if (detectedObject)
            {
                detectedObject.OnDetectExit();
                detectedObject = null;
            }
        }
    }
Exemplo n.º 10
0
        /*
         * private void StartFly() {
         *  standWing.SetActive(false);
         *  flyWing.SetActive(true);
         *  animator.SetTrigger("Fly");
         *  StartCoroutine(FlyCoroutine());
         * }
         */

        private void Start()
        {
            gaze = GetComponent <GazeObject>();
            Register(BIRDSTATE.IDLE, () => {
                gaze.GazeEvent += Tweeting;
                particle.Play();
            });
            Register(BIRDSTATE.INTERACTABLE, () => {
                gaze.GazeEvent -= Tweeting;
                gaze.focusTime  = 0;
                particle.Stop();
                // StartFly();
                // TODO: Petals should start to fly back;
            });
            Register(BIRDSTATE.FLYBACK, () => {
                GameProgress.Instance.InteractedCount++;
            });
            //GameFlowManager.Instance.Register(GameState.PETALFLY, () => NextState());
        }
Exemplo n.º 11
0
 private void Start()
 {
     gaze = GetComponent <GazeObject>();
     Register(TREESTATE.IDLE, () => {
         gaze.GazeEvent += Shaking;
         animator.SetTrigger("Shake");
         particle.Play();
     });
     Register(TREESTATE.INTERACTABLE, () => {
         animator.SetTrigger("StopShake");
         gaze.GazeEvent -= Shaking;
         gaze.focusTime  = 0;
         particle.Stop();
         // TODO: Petals should start to fly back;
         // StartCoroutine(PetalFlyCoroutine());
     });
     Register(TREESTATE.PETALFLY, () => {
         GameProgress.Instance.InteractedCount++;
     });
     //GameFlowManager.Instance.Register(GameState.PETALFLY, () => NextState());
 }
Exemplo n.º 12
0
    //Gets point where user is looking every frame and interacts with any intersecting gazeobjects if possible
    void Update()
    {
        if (!_initialized)
        {
            return;
        }
        if (Input.GetKeyDown(KeyCode.H))
        {
            CenterHead();
        }
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }


        Ray ray = new Ray();

        switch (_selectedControlType)
        {
        case StreamController.ControlType.Head:
            ray = new Ray(Head.position, Head.forward * 1000);
            break;

        case StreamController.ControlType.Eyes_Mouse:

        case StreamController.ControlType.Mouse:
            if (Input.GetMouseButtonDown(1))
            {
            }
            if (Input.GetMouseButton(1))
            {
                Head.Rotate(Vector3.up, Input.GetAxis("Mouse X") * _mouseRotationSpeed, Space.Self);
                Head.Rotate(Vector3.right, -Input.GetAxis("Mouse Y") * _mouseRotationSpeed, Space.Self);
                Head.localRotation = Quaternion.Euler(Head.localEulerAngles.x, Head.localEulerAngles.y, 0);
            }

            if (Input.GetMouseButton(0) || _selectedControlType == StreamController.ControlType.Eyes_Mouse)
            {
                ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            }
            else
            {
                ResetHoveredObject();
                return;
            }
            break;

        //both of the code for the two input cases was moved further down, since we want gaze data to be recorded for both inputs.
        case StreamController.ControlType.Eyes:

            //List<Vector3> eyeDirections = new List<Vector3>();
            //FoveInterfaceBase.EyeRays rays = _foveInterface.GetGazeRays();
            //EFVR_Eye eyeClosed = FoveInterface.CheckEyesClosed();
            //if (eyeClosed != EFVR_Eye.Both && eyeClosed != EFVR_Eye.Left)
            //    eyeDirections.Add(rays.left.direction);
            //if (eyeClosed != EFVR_Eye.Both && eyeClosed != EFVR_Eye.Right)
            //    eyeDirections.Add(rays.right.direction);
            //Vector3 direction = Vector3.zero;

            //foreach (Vector3 eyeDirection in eyeDirections)
            //{
            //    direction += eyeDirection;
            //}
            //direction = direction / eyeDirections.Count;

            //ray = new Ray(Head.transform.position, direction * 1000);
            break;

        case StreamController.ControlType.Joystick:
        {
            // //   Joystick input
            //Vector2 JoyInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));

            ////if the virtual environment is on, send the command to the VirtualUnityController
            //if (StreamController.Instance.VirtualEnvironment)
            //{
            //    if (VirtualUnityController.Instance.IsActive)
            //    {

            //        VirtualUnityController.Instance.JoystickCommand(JoyInput);
            //    }
            //}
            //// Othewise send it to the robotinterface
            //else
            //{
            //    if (RobotInterface.Instance.IsConnected)
            //    {
            //        RobotInterface.Instance.DirectCommandRobot(JoyInput);
            //    }

            //}

            break;
        }
        }

        //--Eye direction calculation for all occasions
        List <Vector3> eyeDirections = new List <Vector3>();


        FoveInterfaceBase.EyeRays rays = _foveInterface.GetGazeRays();
        EFVR_Eye eyeClosed             = FoveInterface.CheckEyesClosed();

        if (eyeClosed != EFVR_Eye.Both && eyeClosed != EFVR_Eye.Left)
        {
            eyeDirections.Add(rays.left.direction);
        }
        if (eyeClosed != EFVR_Eye.Both && eyeClosed != EFVR_Eye.Right)
        {
            eyeDirections.Add(rays.right.direction);
        }
        Vector3 direction = Vector3.zero;

        foreach (Vector3 eyeDirection in eyeDirections)
        {
            direction += eyeDirection;
        }
        direction = direction / eyeDirections.Count;

        ray = new Ray(Head.transform.position, direction * 1000);
        //---------------------------------------------------------

        //Positioning of the cursor
        _cursorCanvas.position = Head.position + ray.direction * _cursorDistance;

        Debug.DrawRay(ray.origin, ray.direction);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            GazeObject gazeObject = hit.collider.GetComponent <GazeObject>();
            if (gazeObject == null)
            {
                ResetHoveredObject();
                return;
            }

            // For this reason we also check if the tag of the gazeobject is the correct one
            RobotControlTrackPad robotControl = gazeObject.GetComponent <RobotControlTrackPad>();
            if (robotControl != null && gazeObject.CompareTag("EyeControlPanel"))
            {
                //Control result is provided on hit. This is updated for both cases of input
                controlResult = robotControl.GetControlResult(hit.point);

                //If the robotcontrols are activated and the eye tracking is used for motion then send the command to the appropriate controller
                if (robotControl.IsActivated & !robotControl.IsExternallyDisabled() &&
                    _selectedControlType == StreamController.ControlType.Eyes)
                {
                    if (StreamController.Instance.VirtualEnvironment)
                    {
                        if (VirtualUnityController.Instance.IsActive)
                        {
                            // Debug.Log("Sending gaze command to robot");
                            VirtualUnityController.Instance.GazeCommand(controlResult);
                        }
                        else
                        {
                            Debug.Log("VirtualUnityController is not connected");
                        }
                    }
                    // Othewise send it to the robotinterface
                    else
                    {
                        if (RobotInterface.Instance.IsConnected)
                        {
                            RobotInterface.Instance.SendCommand(controlResult);
                        }
                        else
                        {
                            Debug.Log("RobotInterface controller is not connected");
                        }
                    }
                    //Instead of robotinterface here
                }

                //---Joystick Input---
                else if (robotControl.IsActivated & !robotControl.IsExternallyDisabled() &&
                         _selectedControlType == StreamController.ControlType.Joystick)
                {
                    //   Joystick input
                    Vector2 JoyInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));

                    //if the virtual environment is on, send the command to the VirtualUnityController
                    if (StreamController.Instance.VirtualEnvironment)
                    {
                        if (VirtualUnityController.Instance.IsActive)
                        {
                            VirtualUnityController.Instance.JoystickCommand(JoyInput);
                        }
                    }
                    // Othewise send it to the robotinterface
                    else
                    {
                        if (RobotInterface.Instance.IsConnected)
                        {
                            RobotInterface.Instance.DirectCommandRobot(JoyInput);
                        }
                    }
                }
            }
            else
            {
                //this result means not staring at panel.
                controlResult = new Vector2(-2, -2);
                //TODO : SendStopCommandToRobot instead of a zero vector. The zero vector is filtered and still adds movemenet to the robot
                // RobotInterface.Instance.SendCommand(Vector2.zero);
            }
            if (gazeObject == _hoveredGazeObject)
            {
                return;
            }
            if (_hoveredGazeObject != null)
            {
                _hoveredGazeObject.OnUnhover();
            }
            gazeObject.OnHover();
            _hoveredGazeObject = gazeObject;
        }
        else
        {
            ResetHoveredObject();
        }
    }
Exemplo n.º 13
0
 private void ShowTooltip(GazeObject button)
 {
     _container.gameObject.SetActive(true);
 }
Exemplo n.º 14
0
 void OnTrackpadUnhovered(GazeObject sender)
 {
     StreamController.Instance.DisableDrivingMode();
 }
Exemplo n.º 15
0
 private void HideTooltip(GazeObject button)
 {
     _container.gameObject.SetActive(false);
 }
Exemplo n.º 16
0
 void OnToggleControlOverlayActivated(GazeObject sender)
 {
     _robotControlTrackPad.SetOverlayVisibility(sender.IsActivated);
 }
Exemplo n.º 17
0
 void OnToggleViewportActivated(GazeObject sender)
 {
     StreamController.Instance.SetViewportVisibility(sender.IsActivated);
 }
Exemplo n.º 18
0
 void OnRobotParkingBrakeActivated(GazeObject sender)
 {
     RobotInterface.Instance.SetParkingBrake(sender.IsActivated);
 }