/// <summary> /// Cast a Ray from the Gazepoint into the Scene /// Call the OnObjectHit(), if a Object was in the Gaze of the User. /// (Use MonoBehaviorWithGazeComponent to integrate your own GazeInteraction) /// </summary> private void rayCastGazeRay() { Ray raygaze; RaycastHit hit; //CheckInput if (gazeModel.isEyeTrackerRunning) { Vector2 gazePos = (gazeModel.posGazeLeft + gazeModel.posGazeRight) * 0.5f; gazePos.y = Screen.height - gazePos.y; raygaze = Camera.main.ScreenPointToRay(gazePos); } //Usee the MouseInput as a DebugInput, if no EyeTracker runs else { raygaze = Camera.main.ScreenPointToRay(Input.mousePosition); } //Cast a Ray from the Gazepoint into the scene if (Physics.Raycast(raygaze, out hit)) { //Only React when a Object has a Monobehabvior with GazeComponent MonoBehaviourWithGazeComponent hitMono = hit.collider.gameObject.GetComponent<MonoBehaviourWithGazeComponent>(); if (hitMono != null) { // Save the OldSelection if (oldSelection == null) oldSelection = hitMono; // Call from the oldSelection the GazeExit() Function else if (hitMono != oldSelection) { oldSelection.OnObjectExit(); oldSelection = hitMono; } // Invoke Start and Update of the GazeEvent hitMono.OnObjectHit(hit); } else { if (oldSelection != null) { oldSelection.OnObjectExit(); oldSelection = null; } } } else { // Call from the oldSelection the GazeExit() Function if (oldSelection != null) { oldSelection.OnObjectExit(); oldSelection = null; } } }
/// <summary> /// Cast a Ray from the Gazepoint into the Scene /// Call the OnObjectHit(), if a Object was in the Gaze of the User. /// (Use MonoBehaviorWithGazeComponent to integrate your own GazeInteraction) /// </summary> private void rayCastGazeRay() { Ray raygaze; Vector2 gazePos = Vector2.zero; //CheckInput if (gazeModel.isEyeTrackerRunning) { gazePos = (gazeModel.posGazeLeft + gazeModel.posGazeRight) * 0.5f; gazePos.y = Screen.height - gazePos.y; raygaze = Camera.main.ScreenPointToRay(gazePos); } //Usee the MouseInput as a DebugInput, if no EyeTracker runs else { raygaze = Camera.main.ScreenPointToRay(Input.mousePosition); } //Cast a Ray from the Gazepoint into the scene //RaycastHit2D hit = Physics2D.Raycast(Camera.main.transform,gazePos,1000f); Vector2 cameraPos = Camera.main.transform.position; gazePos = Camera.main.ScreenToWorldPoint(gazePos); RaycastHit2D hit = Physics2D.Raycast(gazePos, Vector2.zero, 0); if (hit) { //Debug.Log("HIT:" + hit.collider.name); //Only React when a Object has a Monobehabvior with GazeComponent MonoBehaviourWithGazeComponent hitMono = hit.collider.gameObject.GetComponent <MonoBehaviourWithGazeComponent>(); if (hitMono != null) { // Save the OldSelection if (oldSelection == null) { oldSelection = hitMono; } // Call from the oldSelection the GazeExit() Function else if (hitMono != oldSelection) { oldSelection.OnObjectExit(); oldSelection = hitMono; } // Invoke Start and Update of the GazeEvent hitMono.OnObjectHit(hit); } else { if (oldSelection != null) { oldSelection.OnObjectExit(); oldSelection = null; } } } else { // Call from the oldSelection the GazeExit() Function if (oldSelection != null) { oldSelection.OnObjectExit(); oldSelection = null; } } }
/// <summary> /// Cast a Ray from the Gazepoint into the Scene /// Call the OnObjectHit(), if a Object was in the Gaze of the User. /// (Use MonoBehaviorWithGazeComponent to integrate your own GazeInteraction) /// </summary> private void rayCastGazeRay() { Ray raygaze; RaycastHit hit; //CheckInput if (gazeModel.isEyeTrackerRunning) { Vector2 gazePos = (gazeModel.posGazeLeft + gazeModel.posGazeRight) * 0.5f; gazePos.y = Screen.height - gazePos.y; raygaze = Camera.main.ScreenPointToRay(gazePos); } //Usee the MouseInput as a DebugInput, if no EyeTracker runs else { raygaze = Camera.main.ScreenPointToRay(Input.mousePosition); } //Cast a Ray from the Gazepoint into the scene if (Physics.Raycast(raygaze, out hit)) { //Only React when a Object has a Monobehabvior with GazeComponent MonoBehaviourWithGazeComponent hitMono = hit.collider.gameObject.GetComponent <MonoBehaviourWithGazeComponent>(); if (hitMono != null) { // Save the OldSelection if (oldSelection == null) { oldSelection = hitMono; } // Call from the oldSelection the GazeExit() Function else if (hitMono != oldSelection) { oldSelection.OnObjectExit(); oldSelection = hitMono; } // Invoke Start and Update of the GazeEvent hitMono.OnObjectHit(hit); } else { if (oldSelection != null) { oldSelection.OnObjectExit(); oldSelection = null; } } } else { // Call from the oldSelection the GazeExit() Function if (oldSelection != null) { oldSelection.OnObjectExit(); oldSelection = null; } } }
/// <summary> /// Cast a Ray from the Gazepoint into the Scene /// Call the OnObjectHit(), if a Object was in the Gaze of the User. /// (Use MonoBehaviorWithGazeComponent to integrate your own GazeInteraction) /// </summary> private void rayCastGazeRay() { Ray raygaze; Vector2 gazePos = Vector2.zero; //CheckInput if (gazeModel.isEyeTrackerRunning) { gazePos = (gazeModel.posGazeLeft + gazeModel.posGazeRight) * 0.5f; gazePos.y = Screen.height - gazePos.y; raygaze = Camera.main.ScreenPointToRay(gazePos); } //Usee the MouseInput as a DebugInput, if no EyeTracker runs else { raygaze = Camera.main.ScreenPointToRay(Input.mousePosition); } //Cast a Ray from the Gazepoint into the scene //RaycastHit2D hit = Physics2D.Raycast(Camera.main.transform,gazePos,1000f); Vector2 cameraPos = Camera.main.transform.position; gazePos = Camera.main.ScreenToWorldPoint(gazePos); RaycastHit2D hit = Physics2D.Raycast(gazePos, Vector2.zero, 0); if (hit) { //Debug.Log("HIT:" + hit.collider.name); //Only React when a Object has a Monobehabvior with GazeComponent MonoBehaviourWithGazeComponent hitMono = hit.collider.gameObject.GetComponent<MonoBehaviourWithGazeComponent>(); if (hitMono != null) { // Save the OldSelection if (oldSelection == null) oldSelection = hitMono; // Call from the oldSelection the GazeExit() Function else if (hitMono != oldSelection) { oldSelection.OnObjectExit(); oldSelection = hitMono; } // Invoke Start and Update of the GazeEvent hitMono.OnObjectHit(hit); } else { if (oldSelection != null) { oldSelection.OnObjectExit(); oldSelection = null; } } } else { // Call from the oldSelection the GazeExit() Function if (oldSelection != null) { oldSelection.OnObjectExit(); oldSelection = null; } } }