/// <summary> /// Convenience function for cloning PointerEventData /// </summary> /// <param name="from">Copy this value</param> /// <param name="to">to this object</param> protected void CopyFromTo(OVRRayPointerEventData @from, OVRRayPointerEventData @to) { @to.position = @from.position; @to.delta = @from.delta; @to.scrollDelta = @from.scrollDelta; @to.pointerCurrentRaycast = @from.pointerCurrentRaycast; @to.pointerEnter = @from.pointerEnter; @to.worldSpaceRay = @from.worldSpaceRay; }
/// <summary> /// Performs a raycast using eventData.worldSpaceRay /// </summary> /// <param name="eventData"></param> /// <param name="resultAppendList"></param> public override void Raycast(UnityEngine.EventSystems.PointerEventData eventData, List <UnityEngine.EventSystems.RaycastResult> resultAppendList) { OVRRayPointerEventData rayPointerEventData = eventData as OVRRayPointerEventData; if (rayPointerEventData != null) { Raycast(eventData, resultAppendList, rayPointerEventData.worldSpaceRay, true); } }
/// <summary> /// The purpose of this function is to allow us to switch between using the standard IsPointerMoving /// method for mouse driven pointers, but to always return true when it's a ray based pointer. /// All real-world ray-based input devices are always moving so for simplicity we just return true /// for them. /// /// If PointerEventData.IsPointerMoving was virtual we could just override that in /// OVRRayPointerEventData. /// </summary> /// <param name="pointerEvent"></param> /// <returns></returns> static bool IsPointerMoving(UnityEngine.EventSystems.PointerEventData pointerEvent) { OVRRayPointerEventData rayPointerEventData = pointerEvent as OVRRayPointerEventData; if (rayPointerEventData != null) { return(true); } else { return(pointerEvent.IsPointerMoving()); } }
/// <summary> /// Perform a raycast using the worldSpaceRay in eventData. /// </summary> /// <param name="eventData"></param> /// <param name="resultAppendList"></param> public override void Raycast(UnityEngine.EventSystems.PointerEventData eventData, List <UnityEngine.EventSystems.RaycastResult> resultAppendList) { // This function is closely based on PhysicsRaycaster.Raycast if (eventCamera == null) { return; } OVRRayPointerEventData rayPointerEventData = eventData as OVRRayPointerEventData; if (rayPointerEventData == null) { return; } var ray = rayPointerEventData.worldSpaceRay; //float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane; float dist = 10.0f; RaycastHit hit; Physics.Raycast(ray.origin, ray.direction, out hit, dist, finalEventMask); PointerVisualizer.instance.SetPointer(hit); if (hit.collider != null && Controller.instance.pointerMode == PointerMode.SELECT) { // var hit = Physics.RaycastAll(ray, dist, finalEventMask); // if (hits.Length > 1) // System.Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance)); // lastHitDistance = 0; // if (hits.Length != 0) // { // lastHitDistance = hits[0].distance; // for (int b = 0, bmax = hits.Length; b < bmax; ++b) // { var result = new UnityEngine.EventSystems.RaycastResult { gameObject = hit.collider.gameObject, module = this, distance = hit.distance, index = resultAppendList.Count, worldPosition = hit.point, worldNormal = hit.normal, }; resultAppendList.Add(result); // } // } } }
protected bool GetPointerData(int id, out OVRRayPointerEventData data, bool create) { if (!m_VRRayPointerData.TryGetValue(id, out data) && create) { data = new OVRRayPointerEventData(eventSystem) { pointerId = id, }; m_VRRayPointerData.Add(id, data); return(true); } return(false); }
protected bool GetPointerData(int id, out OVRRayPointerEventData data, bool create, bool isLeft) { var rayPointerData = isLeft ? m_VRRayPointerDataLeft : m_VRRayPointerDataRight; if (!rayPointerData.TryGetValue(id, out data) && create) { data = new OVRRayPointerEventData(eventSystem) { pointerId = id, }; rayPointerData.Add(id, data); return(true); } return(false); }
/// <summary> /// Perform a raycast using the worldSpaceRay in eventData. /// </summary> /// <param name="eventData"></param> /// <param name="resultAppendList"></param> public override void Raycast(UnityEngine.EventSystems.PointerEventData eventData, List <UnityEngine.EventSystems.RaycastResult> resultAppendList) { // This function is closely based on PhysicsRaycaster.Raycast if (eventCamera == null) { return; } OVRRayPointerEventData rayPointerEventData = eventData as OVRRayPointerEventData; if (rayPointerEventData == null) { return; } var ray = rayPointerEventData.worldSpaceRay; float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane; var hits = Physics.RaycastAll(ray, dist, finalEventMask); if (hits.Length > 1) { System.Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance)); } if (hits.Length != 0) { for (int b = 0, bmax = hits.Length; b < bmax; ++b) { var result = new UnityEngine.EventSystems.RaycastResult { gameObject = hits[b].collider.gameObject, module = this, distance = hits[b].distance, index = resultAppendList.Count, worldPosition = hits[0].point, worldNormal = hits[0].normal, }; resultAppendList.Add(result); } } }
public void OnGroundClick(BaseEventData data) { OVRRayPointerEventData pData = (OVRRayPointerEventData)data; Vector3 destinationPosition = Vector3.zero; NavMeshHit hit; if (NavMesh.SamplePosition(pData.pointerCurrentRaycast.worldPosition, out hit, navMeshSampleDistance, NavMesh.AllAreas)) { destinationPosition = hit.position; } else { destinationPosition = pData.pointerCurrentRaycast.worldPosition; } agent.isStopped = true; agent.SetDestination(destinationPosition); agent.isStopped = false; if (outText != null) { outText.text = "<b>Last Interaction:</b>\nNavigate to: (" + destinationPosition.x + ", " + destinationPosition.y + ", " + destinationPosition.z + ")"; } }