private void Raycast3DScene() { Ray rayGaze = Camera.main.ScreenPointToRay(SMIGazeController.Instance.GetSample().averagedEye.gazePosInUnityScreenCoords()); RaycastHit hit; //Raycast from the Gazeposition on the Screen if (Physics.Raycast(rayGaze, out hit)) { GazeSelectableItem item = hit.collider.gameObject.GetComponent <GazeSelectableItem>(); if (item != null) { if (oldSelection == null) { oldSelection = hit.collider.gameObject; } else if (hit.collider.gameObject != oldSelection) { oldSelection.GetComponent <GazeSelectableItem>().OnGazeExit(); oldSelection = hit.collider.gameObject; } oldSelection.GetComponent <GazeSelectableItem>().OnGazeEnter(selectedScaleFactor); } else { if (oldSelection != null) { oldSelection.GetComponent <GazeSelectableItem>().OnGazeExit(); oldSelection = null; } } } // no result --> Check if there is an older Selection saved else { if (oldSelection != null) { oldSelection.GetComponent <GazeSelectableItem>().OnGazeExit(); oldSelection = null; } } }
private void RayCastFromGazeTo2DCanvas() { //Create A PointerEvent for a Screenspace Canvas PointerEventData pointer = new PointerEventData(EventSystem.current); pointer.position = SMIGazeController.Instance.GetSample().averagedEye.gazePosInUnityScreenCoords(); //Safe the Raycast var raycastResults = new List <RaycastResult>(); EventSystem.current.RaycastAll(pointer, raycastResults); if (raycastResults.Count > 0) { if (oldSelection == null) { oldSelection = raycastResults[0].gameObject.GetComponent <GazeSelectableItem>(); } else if (raycastResults[0].gameObject != oldSelection) { oldSelection.GetComponent <GazeSelectableItem>().OnGazeExit(); oldSelection = raycastResults[0].gameObject.GetComponent <GazeSelectableItem>(); } GazeSelectableItem item = raycastResults[0].gameObject.GetComponent <GazeSelectableItem>(); if (item) { item.OnGazeEnter(selectedScaleFactor); } } else { if (oldSelection != null) { oldSelection.GetComponent <GazeSelectableItem>().OnGazeExit(); oldSelection = null; } } }