/// <summary> /// Create a ray from the camera at the given screen point. /// </summary> public static Ray ScreenPointToRay() { Vector2 LeapPosition = LeapMotion.Instance.PalmOnScreenXY(); return(SBS.StereoRay(LeapPosition != LeapMotion.NotAvailable ? new Vector3(LeapPosition.x * .5f, Screen.height - LeapPosition.y) : Input.mousePosition)); }
void Update() { HandPosition = ScreenPosition(); int FingerCount = LeapMotion.Instance.ExtendedFingers(); Tapped = FingerCount == 0 && LastFingerCount != 0; RaycastHit hit; if (Physics.Raycast(SBS.StereoRay(new Vector2(HandPosition.x, Screen.height - HandPosition.y)), out hit)) { Selectable Hovered = hit.collider.gameObject.GetComponentInChildren <Selectable>(); if (Hovered) { if (LastHovered && Hovered != LastHovered) { LastHovered.OnPointerExit(RandomPointerEventData); } Hovered.OnPointerEnter(RandomPointerEventData); LastHovered = Hovered; if (ActionDown()) { if (Hovered.GetType() == typeof(Button)) { ((Button)Hovered).OnPointerClick(RandomPointerEventData); } else if (Hovered.GetType() == typeof(Toggle)) { ((Toggle)Hovered).isOn ^= true; } else { Hovered.Select(); } } } else if (LastHovered) { LastHovered.OnPointerExit(RandomPointerEventData); } } else if (LastHovered) { LastHovered.OnPointerExit(RandomPointerEventData); } LastFingerCount = FingerCount; }