public override void Process() { if (graphicRaycastCamera == null) { return; } pointerEventData.Reset(); pointerEventData.position = new Vector2(graphicRaycastCamera.pixelWidth / 2, graphicRaycastCamera.pixelHeight / 2); eventSystem.RaycastAll(pointerEventData, m_RaycastResultCache); pointerEventData.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); currentObject = pointerEventData.pointerCurrentRaycast.gameObject; m_RaycastResultCache.Clear(); HandlePointerExitAndEnter(pointerEventData, currentObject); }
public override void Process() { // Reset data and set position Data.Reset(); Data.position = new Vector2(Camera.pixelWidth / 2.0f, Camera.pixelHeight / 2.0f); // Raycast eventSystem.RaycastAll(Data, m_RaycastResultCache); Data.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); CurrentObject = Data.pointerCurrentRaycast.gameObject; // Clear the cache m_RaycastResultCache.Clear(); // Hover HandlePointerExitAndEnter(Data, CurrentObject); }
/// <summary> /// VRController pointer data(Get fitst hit object by raycaster) /// </summary> /// <returns></returns> protected virtual PointerEventData GetVRPointerEventData() { PointerEventData pointerData = new PointerEventData(eventSystem); pointerData.Reset(); var oldPos = pointerData.position; pointerData.position = GetVRPointerPosition(); pointerData.delta = pointerData.position - pointerData.position; pointerData.scrollDelta = Vector3.zero; eventSystem.RaycastAll(pointerData, m_RaycastResultCache); var raycast = FindFirstRaycast(m_RaycastResultCache); pointerData.pointerCurrentRaycast = raycast; m_RaycastResultCache.Clear(); return(pointerData); }
/// @endcond private void CastRayFromGaze() { Vector2 headPose = NormalizedCartesianToSpherical(Gaze.rotation * Vector3.forward); if (pointerData == null) { pointerData = new PointerEventData(eventSystem); lastHeadPose = headPose; } // Cast a ray into the scene pointerData.Reset(); //Unity devs comment: //We've made some changes internally to the Camera viewport rects to fix viewport issues in VR. //With this change, the Screen.width and height no longer represent the resolution of the HMD. //Screen represents the game view and the HMD resolution is now represented by VRSettings.eyeTextureWidth and VRSettings.eyeTextureHeight. pointerData.position = new Vector2(hotspot.x * Screen.width, hotspot.y * Screen.height); eventSystem.RaycastAll(pointerData, m_RaycastResultCache); RaycastResult raycastResult = FindFirstRaycast(m_RaycastResultCache); pointerData.pointerCurrentRaycast = raycastResult; if (Reticle) { Vector3 position; float distance; GetIntersectionParameters(out position, out distance); if (distance > 0.01f) { Reticle.SetPosition(position, distance); } else { Reticle.SetDefaultPosition(); } } m_RaycastResultCache.Clear(); pointerData.delta = headPose - lastHeadPose; lastHeadPose = headPose; }
// use screen midpoint as locked pointer location, enabling look location to be the "mouse" private PointerEventData GetLookPointerEventData() { VRCursorController cursor = VRCursorController.GetInstance(); Vector3 lookPosition = cursor.GetCursorRaycastPosition(RAYCAST_OFFSET); RaycastHit testRayResult = new RaycastHit(); if (m_hoverData == null) { m_hoverData = new PointerEventData(eventSystem); } m_hoverData.Reset(); m_hoverData.delta = Vector2.zero; m_hoverData.position = lookPosition; m_hoverData.scrollDelta = Vector2.zero; // Only bother trying to raycast to UI on the XY plane if (cursor.CursorPlane == VRCursorController.eCursorPlane.XYPlane) { Vector3 lookDirection = cursor.GetCursorRaycastDirection(); Ray testRay = new Ray(lookPosition, lookDirection); if (Physics.Raycast(testRay, out testRayResult, RAYCAST_OFFSET + 1.0f, UI_COLLISION_LAYER_MASK)) { RaycastResult raycastResult = new RaycastResult(); raycastResult.Clear(); raycastResult.gameObject = testRayResult.collider.gameObject; raycastResult.depth = 0; raycastResult.distance = testRayResult.distance; m_hoverData.pointerCurrentRaycast = raycastResult; } } if (m_hoverData.pointerCurrentRaycast.gameObject != null) { m_guiRaycastHit = true; } else { m_guiRaycastHit = false; } return(m_hoverData); }
// This will return all the RaycastResults under the 'screenPosition' using the specified layerMask // The first result (0) should be the top most UI element public static List <RaycastResult> RaycastGui(Vector2 screenPosition, LayerMask layerMask) { tempRaycastResults.Clear(); var currentEventSystem = EventSystem.current; if (currentEventSystem != null) { // Create point event data for this event system? if (currentEventSystem != tempEventSystem) { tempEventSystem = currentEventSystem; if (tempPointerEventData == null) { tempPointerEventData = new PointerEventData(tempEventSystem); } else { tempPointerEventData.Reset(); } } // Raycast event system at the specified point tempPointerEventData.position = screenPosition; currentEventSystem.RaycastAll(tempPointerEventData, tempRaycastResults); // Loop through all results and remove any that don't match the layer mask if (tempRaycastResults.Count > 0) { for (var i = tempRaycastResults.Count - 1; i >= 0; i--) { var raycastResult = tempRaycastResults[i]; var raycastLayer = 1 << raycastResult.gameObject.layer; if ((raycastLayer & layerMask) == 0) { tempRaycastResults.RemoveAt(i); } } } } return(tempRaycastResults); }
/// @endcond private void CastRayFromGaze() { Vector2 headPose = NormalizedCartesianToSpherical(Cardboard.SDK.HeadPose.Orientation * Vector3.forward); if (pointerData == null) { pointerData = new PointerEventData(eventSystem); lastHeadPose = headPose; } pointerData.Reset(); pointerData.position = new Vector2(hotspot.x * Screen.width, hotspot.y * Screen.height); eventSystem.RaycastAll(pointerData, m_RaycastResultCache); pointerData.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); m_RaycastResultCache.Clear(); pointerData.delta = headPose - lastHeadPose; lastHeadPose = headPose; }
public override void Process() { data.Reset(); data.position = new Vector2(camera.pixelWidth / 2, camera.pixelHeight / 2); eventSystem.RaycastAll(data, m_RaycastResultCache); data.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); currentObject = data.pointerCurrentRaycast.gameObject; m_RaycastResultCache.Clear(); HandlePointerExitAndEnter(data, currentObject); if (clickAction.GetStateDown(targetSource)) { ProcessRelease(data); } }
// get a pointer event data for a screen position private PointerEventData GetLookPointerEventData(Vector3 componentPosition) { if (_handPointerData == null) { _handPointerData = new PointerEventData(eventSystem); } _handPointerData.Reset(); _handPointerData.delta = Vector2.zero; _handPointerData.position = componentPosition; _handPointerData.scrollDelta = Vector2.zero; eventSystem.RaycastAll(_handPointerData, m_RaycastResultCache); _handPointerData.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); m_RaycastResultCache.Clear(); return(_handPointerData); }
public override void Process() { //Reset data, set camera data.Reset(); data.position = new Vector2(camera.pixelWidth / 2, camera.pixelHeight / 2); //Raycast eventSystem.RaycastAll(data, m_RaycastResultCache); data.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); currentObj = data.pointerCurrentRaycast.gameObject; //Clear m_RaycastResultCache.Clear(); //Hover HandlePointerExitAndEnter(data, currentObj); //Press //if (clickAction.GetStateDown(targetSource)) //ProcessPress(data); //Release }
public override void Process() { if (contactUIEnabled) { if (submitObject) { BaseEventData data = GetBaseEventData(); data.selectedObject = submitObject; ExecuteEvents.Execute(submitObject, data, ExecuteEvents.submitHandler); submitObject = null; } } if (pointerUIEnabled) { // reset data pointerData.Reset(); // set camera pointerData.position = new Vector2(pointerCamera.pixelWidth / 2, pointerCamera.pixelHeight / 2); // raycast eventSystem.RaycastAll(pointerData, m_RaycastResultCache); pointerData.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); pointerTargetObject = pointerData.pointerCurrentRaycast.gameObject; m_RaycastResultCache.Clear(); // hover HandlePointerExitAndEnter(pointerData, pointerTargetObject); // press if (pointerClickAction.GetStateDown(pointerTargetSource)) { processPress(pointerData); } // release if (pointerClickAction.GetStateUp(pointerTargetSource)) { processRelease(pointerData); } } }
/// @endcond protected virtual void CastRayFromGaze() { Vector2 headPose = NormalizedCartesianToSpherical(GvrViewer.Instance.HeadPose.Orientation * Vector3.forward); if (pointerData == null) { pointerData = new PointerEventData(eventSystem); lastHeadPose = headPose; } // Cast a ray into the scene pointerData.Reset(); pointerData.position = new Vector2(0.5f * Screen.width, 0.5f * Screen.height); eventSystem.RaycastAll(pointerData, m_RaycastResultCache); pointerData.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); m_RaycastResultCache.Clear(); pointerData.delta = headPose - lastHeadPose; lastHeadPose = headPose; }
public override void Process() { m_Data.Reset(); m_Data.position = new Vector2(m_Camera.pixelWidth / 2, m_Camera.pixelHeight / 2); eventSystem.RaycastAll(m_Data, m_RaycastResultCache); m_Data.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); m_CurrentObject = m_Data.pointerCurrentRaycast.gameObject; m_RaycastResultCache.Clear(); HandlePointerExitAndEnter(m_Data, m_CurrentObject); if (m_ClickAction == true) { ProcessPress(m_Data); } if (m_ClickAction == false) { ProcessRelease(m_Data); } }
/// @endcond private void CastRayFromGaze() { //Vector2 headPose = NormalizedCartesianToSpherical(GvrViewer.Instance.HeadPose.Orientation * Vector3.forward);//--------------------------------------------- if (pointerData == null) { pointerData = new PointerEventData(eventSystem); //lastHeadPose = headPose;-------------------------------------------------------------------------------------------------------------------------------- } // Cast a ray into the scene pointerData.Reset(); pointerData.position = new Vector2(hotspot.x * Screen.width, hotspot.y * Screen.height); eventSystem.RaycastAll(pointerData, m_RaycastResultCache); pointerData.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); m_RaycastResultCache.Clear(); //pointerData.delta = headPose - lastHeadPose;//------------------------------------------------------------------------------------------------------------------ //lastHeadPose = headPose;//-------------------------------------------------------------------------------------------------------------------------------------- }
// use screen midpoint as locked pointer location, enabling look location to be the "mouse" private PointerEventData GetLookPointerEventData() { Vector2 lookPosition; lookPosition.x = Screen.width / 2; lookPosition.y = Screen.height / 2; if (lookData == null) { lookData = new PointerEventData(eventSystem); } lookData.Reset(); lookData.delta = Vector2.zero; lookData.position = lookPosition; lookData.scrollDelta = Vector2.zero; eventSystem.RaycastAll(lookData, m_RaycastResultCache); lookData.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); m_RaycastResultCache.Clear(); return(lookData); }
void HandleLook() { if (controllerpointerEventData == null) { controllerpointerEventData = new PointerEventData(eventSystem); } // fake a pointer always being at the center of the screen controllerpointerEventData.Reset(); Vector3 pos = camera.WorldToScreenPoint(controllerPointer.transform.position); if (pos.x > 0 && pos.x < Screen.width && pos.y > 0 && pos.y < Screen.height) { controllerpointerEventData.position = new Vector2(pos.x, pos.y); controllerpointerEventData.delta = Vector2.zero; List <RaycastResult> controllerraycastResults = new List <RaycastResult>(); eventSystem.RaycastAll(controllerpointerEventData, controllerraycastResults); controllerCurrentRaycast = controllerpointerEventData.pointerCurrentRaycast = FindFirstRaycast(controllerraycastResults); ProcessMove(controllerpointerEventData); } }
public override void Process() { resultList = new List <RaycastResult>(); pointerData.Reset(); pointerData.position = viewportCenter; eventSystem.RaycastAll(pointerData, resultList); var enterList = resultList.Except <RaycastResult>(m_RaycastResultCache, comparer); foreach (var r in enterList) { ExecuteEvents.Execute(r.gameObject, pointerData, ExecuteEvents.pointerEnterHandler); } var exitList = m_RaycastResultCache.Except <RaycastResult>(resultList, comparer); foreach (var r in exitList) { ExecuteEvents.Execute(r.gameObject, pointerData, ExecuteEvents.pointerExitHandler); } m_RaycastResultCache = resultList; }
private void UpdateEventsAndRaycast() { if (colorTrackerPanel == null) { return; } ColorTracker tracker = colorTrackerPanel.GetColorTracker(); if (tracker == null) { return; } List <TrackerResult> colorTrackerResults = tracker.GetLatestResult(); AllocatePointerDataIfNeeded(colorTrackerResults); for (var t = 0; t < colorTrackerResults.Count; t++) { PointerEventData current = _pointerData[t]; current.Reset(); TrackerResult r = colorTrackerResults[t]; if (r.state == TrackingState.Tracked) { CoordinateMapper.ConvertInputToScreen(tracker.input, r.center, ref _reusablePosition); } else { _reusablePosition.Set(-150, -150, 0); } current.position = _reusablePosition; current.delta = r.linearVelocity; eventSystem.RaycastAll(current, m_RaycastResultCache); current.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); UpdateHoverAndExit(current); HandleTrigger(current); m_RaycastResultCache.Clear(); } }
private void CastRayFromGaze() { var headOrientation = VRManager.Viewer.Head.rotation; var headPose = NormalizedCartesianToSpherical(headOrientation * Vector3.forward); if (pointerData == null) { pointerData = new PointerEventData(eventSystem); lastHeadPose = headPose; } // Cast a ray into the scene pointerData.Reset(); pointerData.position = GetGazePointerPosition(); eventSystem.RaycastAll(pointerData, m_RaycastResultCache); pointerData.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); m_RaycastResultCache.Clear(); pointerData.delta = headPose - lastHeadPose; lastHeadPose = headPose; }
public override void Process() { try { pointerData.Reset(); // Find the gameObject which is in the ray of view pointerData.position = position; eventSystem.RaycastAll(pointerData, m_RaycastResultCache); pointerData.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); m_RaycastResultCache.Clear(); GameObject go = pointerData.pointerCurrentRaycast.gameObject; // just do update work if the game object changed. if (go != lastGameObject) { // Send enter events and update the highlight. HandlePointerExitAndEnter(pointerData, go); // Update the current selection, or clear if it is no longer the current object. var selected = ExecuteEvents.GetEventHandler <ISelectHandler>(go); if (selected == eventSystem.currentSelectedGameObject) { ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, GetBaseEventData(), ExecuteEvents.updateSelectedHandler); } else { eventSystem.SetSelectedGameObject(null, pointerData); } } // PlaceCursor(); HandleClick(); lastGameObject = go; } catch (Exception e) { MojingLog.LogError(e.ToString()); } }
/// @endcond private void CastRayFromGaze() { #if NATIVE_VR_SUPPORTED Vector2 headPose = NormalizedCartesianToSpherical(GameObject.FindWithTag("MainCamera").transform.rotation *Vector3.forward); #else Vector2 headPose = NormalizedCartesianToSpherical(Cardboard.SDK.HeadPose.Orientation * Vector3.forward); #endif if (pointerData == null) { pointerData = new PointerEventData(eventSystem); lastHeadPose = headPose; } pointerData.Reset(); pointerData.position = new Vector2(hotspot.x * Screen.width, hotspot.y * Screen.height); eventSystem.RaycastAll(pointerData, m_RaycastResultCache); pointerData.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); m_RaycastResultCache.Clear(); pointerData.delta = headPose - lastHeadPose; lastHeadPose = headPose; }
private void CastToCenterOfScreen() { if (pointerData == null) { pointerData = new PointerEventData(eventSystem); } pointerData.Reset(); pointerData.position = new Vector2(0.5f * Screen.width, 0.5f * Screen.height); // center of screen if (Head != null) { Camera _event_camera = Head.GetComponent <Camera> (); GraphicRaycast(_event_camera); if (pointerData.pointerCurrentRaycast.gameObject == null) { PhysicsRaycaster _raycaster = Head.GetComponent <PhysicsRaycaster> (); PhysicRaycast(_raycaster); } } }
public void OnEndDrag(PointerEventData eventData) { eventData.Reset(); if (icon != null) { Destroy(icon); // Destroy icon on item drop } MakeVisible(true); // Make item visible in cell if (OnItemDragEndEvent != null) { OnItemDragEndEvent(this); // Notify all cells about item drag end } //빈 공간에 드래그 앤 드롭 했을시 if (eventData.pointerCurrentRaycast.gameObject.tag != "SkillPanel" && sourceCell.cellType == DragAndDropCell_Training.CellType.Swap) { sourceCell.RemoveItem(); TrainingManager.TMInstance.DragEndAction(sourceCell.GetCellNumber(), null, this.IndexNum); } draggedItem = null; icon = null; sourceCell = null; }
public override void Process() { UpdatePosition(); if (m_Data != null) { m_Data.Reset(); } m_Data.position = new Vector2(m_Camera.pixelWidth / 2, m_Camera.pixelHeight / 2); eventSystem.RaycastAll(m_Data, m_RaycastResultCache); m_Data.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); m_CurrentGameObject = m_Data.pointerCurrentRaycast.gameObject; m_RaycastResultCache.Clear(); HandlePointerExitAndEnter(m_Data, m_CurrentGameObject); if (m_ClickAction.GetStateDown(m_TargetSource)) { ProcessPress(m_Data); } if (m_ClickAction.GetStateUp(m_TargetSource)) { ProcessRelease(m_Data); } }
public override void OnPointerClick(PointerEventData eventData) { if (!this.enabled) { return; } m_ClickPosition = eventData.position; base.OnPointerClick(eventData); if (!eventClicker.UF_OnDoubleClick(this)) { eventClicker.UF_OnClick(this); } if (ingoreMask) { eventData.Reset(); UF_OnIngoreMask(eventData); } }
/// @endcond private void CastRayFromGaze() { Vector2 headPose = NormalizedCartesianToSpherical(GvrViewer.Instance.HeadPose.Orientation * Vector3.forward); if (pointerData == null) { pointerData = new PointerEventData(eventSystem); lastHeadPose = headPose; } // Cast a ray into the scene pointerData.Reset(); //if we use google cardboard pointerData.position = new Vector2(hotspot.x * Screen.width, hotspot.y * Screen.height); //what we will use on gearVR //pointerData.position = new Vector2(VRSettings.eyeTextureWidth / 2, VRSettings.eyeTextureHeight / 2); eventSystem.RaycastAll(pointerData, m_RaycastResultCache); pointerData.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); m_RaycastResultCache.Clear(); pointerData.delta = headPose - lastHeadPose; lastHeadPose = headPose; }
/// <summary> /// VRController pointer data(Get fitst hit object by raycaster) /// </summary> /// <returns></returns> protected virtual PointerEventData GetVRPointerEventData() { PointerEventData pointerData = new PointerEventData(eventSystem); pointerData.Reset(); foreach (var guiOverlay in guiOverlays) { if (guiOverlay.showCursor == false) { continue; } var oldPos = pointerData.position; pointerData.position = new Vector2(guiOverlay.overlay.texture.width * guiOverlay.cursorPosition.x, guiOverlay.overlay.texture.height * (1.0f - guiOverlay.cursorPosition.y)); pointerData.delta = pointerData.position - oldPos; pointerData.scrollDelta = Vector3.zero; eventSystem.RaycastAll(pointerData, m_RaycastResultCache); var raycast = FindFirstRaycast(m_RaycastResultCache); pointerData.pointerCurrentRaycast = raycast; m_RaycastResultCache.Clear(); } return(pointerData); }
public override void Process() { //Reset data, set Camera m_Data.Reset(); m_Data.position = new Vector2(m_Camera.pixelWidth / 2, m_Camera.pixelHeight / 2); //Raycast eventSystem.RaycastAll(m_Data, m_RaycastResultCache); m_Data.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); m_CurrentObject = m_Data.pointerCurrentRaycast.gameObject; //clear m_RaycastResultCache.Clear(); //Havor HandlePointerExitAndEnter(m_Data, m_CurrentObject); //Press if (m_ClickAction.GetStateDown(m_TargetSouce)) { ProcessRelease(m_Data); } }
private void Clear(PointerEventData pointerEventData) { uiRaycastPointerData.Reset(); uiRaycastPointerData.button = PointerEventData.InputButton.Left; uiRaycastPointerData.clickCount = 0; uiRaycastPointerData.clickTime = 0; uiRaycastPointerData.delta = Vector2.zero; uiRaycastPointerData.dragging = false; uiRaycastPointerData.eligibleForClick = false; uiRaycastPointerData.pointerCurrentRaycast = default(RaycastResult); uiRaycastPointerData.pointerDrag = null; uiRaycastPointerData.pointerEnter = null; uiRaycastPointerData.pointerId = 0; uiRaycastPointerData.pointerPress = null; uiRaycastPointerData.pointerPressRaycast = default(RaycastResult); uiRaycastPointerData.position = Vector2.zero; uiRaycastPointerData.pressPosition = Vector2.zero; uiRaycastPointerData.rawPointerPress = null; uiRaycastPointerData.scrollDelta = Vector2.zero; uiRaycastPointerData.selectedObject = null; uiRaycastPointerData.useDragThreshold = false; }
private void CastRayFromGaze() { Quaternion headOrientation; headOrientation = Camera.main.transform.rotation; Vector2 headPose = NormalizedCartesianToSpherical(headOrientation * Vector3.forward); if (pointerData == null) { pointerData = new PointerEventData(eventSystem); lastHeadPose = headPose; } // Cast a ray into the scene pointerData.Reset(); pointerData.position = centerOfScreen; eventSystem.RaycastAll(pointerData, m_RaycastResultCache); pointerData.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); m_RaycastResultCache.Clear(); pointerData.delta = headPose - lastHeadPose; lastHeadPose = headPose; //Debug.DrawLine(Camera.main.transform.position, pointerData.pointerCurrentRaycast.worldPosition, Color.red, 10f); }