void TapScreen(Vector2 screenPoint) { var info = new ObjectSelectionInfo(); if (m_PreviousScreenPoint.HasValue && (screenPoint - m_PreviousScreenPoint.Value).magnitude <= m_Tolerance) { info.selectedObjects = m_CurrentObjectSelectionInfo.selectedObjects; info.currentIndex = m_CurrentObjectSelectionInfo.selectedObjects.Count == 0 ? 0 : (m_CurrentObjectSelectionInfo.currentIndex + 1) % m_CurrentObjectSelectionInfo.selectedObjects.Count; } else { if (m_Camera == null || !m_Camera.gameObject.activeInHierarchy) { m_Camera = Camera.main; if (m_Camera == null) { Debug.LogError($"[{nameof(UISelectionController)}] active main camera not found!"); return; } } m_ObjectPicker.Pick(m_Camera.ScreenPointToRay(screenPoint), m_Results); // send a copy of the list to preserve previous selection info info.selectedObjects = m_Results.Select(x => x.Item1).ToList(); info.currentIndex = 0; } m_PreviousScreenPoint = screenPoint; UIStateManager.current.Dispatcher.Dispatch(Payload <ActionTypes> .From(ActionTypes.SelectObjects, info)); }
void UpdateTarget() { var nbPoints = 0; if (!m_XrRayInteractor.GetLinePoints(ref m_LinePoints, ref nbPoints)) { Debug.LogError($"[{nameof(VRTeleporter)}] XRRayInteractor.GetLinePoints failed!"); return; } // disable the target first so it doesn't interfere with the raycasts m_TeleportationTarget.gameObject.SetActive(false); // pick m_Results.Clear(); m_ObjectPicker.Pick(m_LinePoints, nbPoints, m_Results); // enable the target if there is a valid hit if (m_Results.Count == 0) { return; } m_TeleportationTarget.transform.position = m_Results[0].Item2.point; m_TeleportationTarget.gameObject.SetActive(true); }
void UpdateTarget() { if (!m_XrRayInteractor.GetLinePoints(ref m_LinePoints, out var nbPoints)) { Debug.LogError($"[{nameof(VRTeleporter)}] XRRayInteractor.GetLinePoints failed!"); return; } // disable the target first so it doesn't interfere with the raycasts m_TeleportationTarget.gameObject.SetActive(false); // pick m_Results.Clear(); m_ObjectPicker?.Pick(m_LinePoints, nbPoints, m_Results); // enable the target if there is a valid hit if (m_Results.Count == 0) { return; } m_TeleportationTarget.transform.position = m_Results[0].Item2.point; m_TeleportationTarget.gameObject.SetActive(true); // This help to keep a curve for the teleport line SetTeleportCurve(1.5f * Vector3.Distance(m_MainCamera.position, m_TeleportationTarget.transform.position)); }
public Vector3 GetTeleportTarget(Vector2 position) { m_TeleportPicker?.Pick(m_Camera.ScreenPointToRay(position), m_Results); if (m_Results.Count == 0) { return(Vector3.zero); } var hitInfo = m_Results[0].Item2; var point = hitInfo.point; var target = point; target.y += 0.001f; return(target); }
void OnPointerClick(BaseEventData data) { if (!m_SelectMode) { return; } var screenPoint = data.currentInputModule.input.mousePosition; var info = new ObjectSelectionInfo(); info.userId = m_CurrentUserId; if (m_PreviousScreenPoint.HasValue && (screenPoint - m_PreviousScreenPoint.Value).magnitude <= m_Tolerance) { info.selectedObjects = m_CurrentObjectSelectionInfo.selectedObjects; info.currentIndex = m_CurrentObjectSelectionInfo.selectedObjects.Count == 0 ? 0 : (m_CurrentObjectSelectionInfo.currentIndex + 1) % m_CurrentObjectSelectionInfo.selectedObjects.Count; } else { if (m_Camera == null || !m_Camera.gameObject.activeInHierarchy) { m_Camera = Camera.main; if (m_Camera == null) { Debug.LogError($"[{nameof(UISelectionController)}] active main camera not found!"); return; } } m_ObjectPicker.Pick(m_Camera.ScreenPointToRay(screenPoint), m_Results); // send a copy of the list to preserve previous selection info info.selectedObjects = m_Results.Select(x => x.Item1).Where(x => x.layer != MetadataFilter.k_OtherLayer).ToList(); info.currentIndex = 0; info.colorId = 0; } m_PreviousScreenPoint = screenPoint; Dispatcher.Dispatch(Payload <ActionTypes> .From(ActionTypes.SelectObjects, info)); }
void UpdateTarget() { m_Ray.origin = m_ControllerTransform.position; m_Ray.direction = m_ControllerTransform.forward; // disable the target first so it doesn't interfere with the raycasts m_SelectionTarget.gameObject.SetActive(false); // pick m_Results.Clear(); m_ObjectPicker.Pick(m_Ray, m_Results); // enable the target if there is a valid hit if (m_Results.Count == 0) { return; } m_SelectionTarget.transform.position = m_Results[0].Item2.point; m_SelectionTarget.gameObject.SetActive(true); }
// called in UI event public void TriggerTeleport(Vector2 position) { if (m_IsTeleporting) { return; } m_TeleportPicker.Pick(m_Camera.ScreenPointToRay(position), m_Results); if (m_Results.Count == 0) { return; } var hitInfo = m_Results[0].Item2; var point = hitInfo.point; var normal = hitInfo.normal; var target = point + m_ArrivalOffsetFixed + m_ArrivalOffsetNormal * normal + m_ArrivalOffsetRelative * (m_Source - point).normalized; UIStateManager.current.Dispatcher.Dispatch(Payload <ActionTypes> .From(ActionTypes.Teleport, target)); }