public override void Process() { if (eventSystem.currentSelectedGameObject != null) { ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, GetBaseEventData(), ExecuteEvents.updateSelectedHandler); } PointerEventData eventData; GetPointerData(kMouseLeftId, out eventData, true); eventData.Reset(); eventData.scrollDelta = Input.mouseScrollDelta; if (graphicRaycaster) { graphicRaycaster.Raycast(eventData, m_RaycastResultCache); eventData.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); m_RaycastResultCache.Clear(); } MouseState mouseState = new MouseState(); mouseState.SetButtonState(PointerEventData.InputButton.Left, StateForMouseButton(0), eventData); MouseButtonEventData buttonData = mouseState.GetButtonState(PointerEventData.InputButton.Left).eventData; PointerEventData pointerEvent = buttonData.buttonData; GameObject currentGO = pointerEvent.pointerCurrentRaycast.gameObject; // mouse pointer down if (buttonData.PressedThisFrame()) { pointerEvent.eligibleForClick = true; pointerEvent.delta = Vector2.zero; pointerEvent.pressPosition = pointerEvent.position; pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast; DeselectIfSelectionChanged(currentGO, pointerEvent); GameObject pressedGO = ExecuteEvents.ExecuteHierarchy(currentGO, pointerEvent, ExecuteEvents.pointerDownHandler); if (pressedGO == null) { pressedGO = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentGO); } pointerEvent.clickCount = 1; pointerEvent.pointerPress = pressedGO; pointerEvent.rawPointerPress = currentGO; pointerEvent.clickTime = Time.unscaledTime; } // mouse pointer up if (buttonData.ReleasedThisFrame()) { ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler); GameObject pointerUpHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentGO); if (pointerEvent.pointerPress == pointerUpHandler && pointerEvent.eligibleForClick) { ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler); } if (currentGO != pointerEvent.pointerEnter) { HandlePointerExitAndEnter(pointerEvent, null); HandlePointerExitAndEnter(pointerEvent, currentGO); } } // scroll wheel if (!Mathf.Approximately(buttonData.buttonData.scrollDelta.sqrMagnitude, 0.0f)) { GameObject scrollHandler = ExecuteEvents.GetEventHandler <IScrollHandler>(buttonData.buttonData.pointerCurrentRaycast.gameObject); ExecuteEvents.ExecuteHierarchy(scrollHandler, buttonData.buttonData, ExecuteEvents.scrollHandler); } }
public virtual void ProcessReleased(object sender, PointerEventArgs pointerEventArgs) { uiSampler.Begin(); var pointers = pointerEventArgs.Pointers; var count = pointers.Count; for (var i = 0; i < count; i++) { var pointer = pointers[i]; var press = pointer.GetPressData(); // Don't update the pointer if it is was not pressed over an UI element if (press.Type != HitData.HitType.UI) { continue; } var over = pointer.GetOverData(); PointerEventData data; GetPointerData(pointer.Id, out data, true); var target = over.Target; var currentOverGo = target == null ? null : target.gameObject; ExecuteEvents.Execute(data.pointerPress, data, ExecuteEvents.pointerUpHandler); var pointerUpHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo); if (data.pointerPress == pointerUpHandler && data.eligibleForClick) { ExecuteEvents.Execute(data.pointerPress, data, ExecuteEvents.pointerClickHandler); } else if (data.pointerDrag != null && data.dragging) { ExecuteEvents.ExecuteHierarchy(currentOverGo, data, ExecuteEvents.dropHandler); } data.eligibleForClick = false; data.pointerPress = null; data.rawPointerPress = null; if (data.pointerDrag != null && data.dragging) { ExecuteEvents.Execute(data.pointerDrag, data, ExecuteEvents.endDragHandler); } data.dragging = false; data.pointerDrag = null; // send exit events as we need to simulate this on touch up on touch device ExecuteEvents.ExecuteHierarchy(data.pointerEnter, data, ExecuteEvents.pointerExitHandler); data.pointerEnter = null; // redo pointer enter / exit to refresh state // so that if we moused over somethign that ignored it before // due to having pressed on something else // it now gets it. if (currentOverGo != data.pointerEnter) { input.HandlePointerExitAndEnter(data, null); input.HandlePointerExitAndEnter(data, currentOverGo); } } uiSampler.End(); }
// Update is called once per frame private void Update() { //TODO uncomment this in order to get the isPressed from the according controller // curently I only set it via the Inspector //isPressed = OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger); // Initially the dist is the maximum pointer distance var dist = maxPointerDistance; // create the ray from the laserpointer origin var ray = new Ray(_holder.position, _holder.forward); var hit = new RaycastHit(); // If using a Collider we have to ignore the Collider of the LaserPointer itself if (useCollider) { var hits = Physics.RaycastAll(ray, maxPointerDistance); hit = hits.FirstOrDefault(h => h.transform != _laser.transform); } else { Physics.Raycast(ray, out hit, maxPointerDistance); } // Are we hitting something? if (hit.transform) { // ignore if still pressing the trigger if (!isPressed) { // Are we hitting something different to what we hit before? if (_currentlyHovered && _currentlyHovered != hit.transform) { ExecuteEvents.ExecuteHierarchy(_currentlyHovered.gameObject, _pointerEventData, ExecuteEvents.pointerExitHandler); _currentlyHovered = null; } // Are we hitting something new? if (_currentlyHovered != hit.transform) { ExecuteEvents.ExecuteHierarchy(hit.transform.gameObject, _pointerEventData, ExecuteEvents.pointerEnterHandler); _currentlyHovered = hit.transform; } } if (_currentlyHovered == hit.transform) { // If we are hitting something correct the dist value if (hit.distance < maxPointerDistance) { dist = hit.distance; } if (isPressed) { HandlePointerDown(hit.transform); } else { HandlePointerUp(hit.transform); } } } else { if (!isPressed && _currentlyHovered) { HandlePointerUp(_currentlyHovered, true); ExecuteEvents.ExecuteHierarchy(_currentlyHovered.gameObject, _pointerEventData, ExecuteEvents.pointerExitHandler); _currentlyHovered = null; } } // Apply changes in the thickness and set the laser dimensions using the dist var thickness = !changeThickness || !isPressed ? idleThickness : pressedThickness; _laser.transform.localScale = new Vector3(thickness, thickness, dist); _laser.transform.localPosition = new Vector3(0f, 0f, dist / 2f); // Apply color changes if (changeColor) { _laserMaterial.color = isPressed ? pressedColor : idleColor; } // Update the pointerEventData pointerPosition3D = _laser.transform.position + _laser.transform.forward * dist / 2f; pointerPosition2D = _camera.WorldToScreenPoint(pointerPosition3D); _pointerEventData.position = pointerPosition2D; _pointerEventData.delta = _pointerEventData.position - _lastPointerPosition; _lastPointerPosition = _pointerEventData.position; _lastPressed = isPressed; }
protected void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released) { RaycastResult pointerCurrentRaycast = pointerEvent.get_pointerCurrentRaycast(); GameObject gameObject1 = ((RaycastResult) ref pointerCurrentRaycast).get_gameObject(); if (pressed) { pointerEvent.set_eligibleForClick(true); pointerEvent.set_delta(Vector2.get_zero()); pointerEvent.set_dragging(false); pointerEvent.set_useDragThreshold(true); pointerEvent.set_pressPosition(pointerEvent.get_position()); pointerEvent.set_pointerPressRaycast(pointerEvent.get_pointerCurrentRaycast()); this.DeselectIfSelectionChanged(gameObject1, (BaseEventData)pointerEvent); if (Object.op_Inequality((Object)pointerEvent.get_pointerEnter(), (Object)gameObject1)) { ((BaseInputModule)this).HandlePointerExitAndEnter(pointerEvent, gameObject1); pointerEvent.set_pointerEnter(gameObject1); } GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy <IPointerDownHandler>(gameObject1, (BaseEventData)pointerEvent, (ExecuteEvents.EventFunction <M0>)ExecuteEvents.get_pointerDownHandler()); if (Object.op_Equality((Object)gameObject2, (Object)null)) { gameObject2 = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject1); } float unscaledTime = Time.get_unscaledTime(); if (Object.op_Equality((Object)gameObject2, (Object)pointerEvent.get_lastPress())) { if ((double)(unscaledTime - pointerEvent.get_clickTime()) < 0.3) { PointerEventData pointerEventData = pointerEvent; pointerEventData.set_clickTime(pointerEventData.get_clickTime() + 1f); } else { pointerEvent.set_clickCount(1); } pointerEvent.set_clickTime(unscaledTime); } else { pointerEvent.set_clickCount(1); } pointerEvent.set_pointerPress(gameObject2); pointerEvent.set_rawPointerPress(gameObject1); pointerEvent.set_clickTime(unscaledTime); pointerEvent.set_pointerDrag(ExecuteEvents.GetEventHandler <IDragHandler>(gameObject1)); if (Object.op_Inequality((Object)pointerEvent.get_pointerDrag(), (Object)null)) { ExecuteEvents.Execute <IInitializePotentialDragHandler>(pointerEvent.get_pointerDrag(), (BaseEventData)pointerEvent, (ExecuteEvents.EventFunction <M0>)ExecuteEvents.get_initializePotentialDrag()); } } if (!released) { return; } ExecuteEvents.Execute <IPointerUpHandler>(pointerEvent.get_pointerPress(), (BaseEventData)pointerEvent, (ExecuteEvents.EventFunction <M0>)ExecuteEvents.get_pointerUpHandler()); GameObject eventHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject1); if (Object.op_Equality((Object)pointerEvent.get_pointerPress(), (Object)eventHandler) && pointerEvent.get_eligibleForClick()) { ExecuteEvents.Execute <IPointerClickHandler>(pointerEvent.get_pointerPress(), (BaseEventData)pointerEvent, (ExecuteEvents.EventFunction <M0>)ExecuteEvents.get_pointerClickHandler()); } else if (Object.op_Inequality((Object)pointerEvent.get_pointerDrag(), (Object)null) && pointerEvent.get_dragging()) { ExecuteEvents.ExecuteHierarchy <IDropHandler>(gameObject1, (BaseEventData)pointerEvent, (ExecuteEvents.EventFunction <M0>)ExecuteEvents.get_dropHandler()); } pointerEvent.set_eligibleForClick(false); pointerEvent.set_pointerPress((GameObject)null); pointerEvent.set_rawPointerPress((GameObject)null); if (Object.op_Inequality((Object)pointerEvent.get_pointerDrag(), (Object)null) && pointerEvent.get_dragging()) { ExecuteEvents.Execute <IEndDragHandler>(pointerEvent.get_pointerDrag(), (BaseEventData)pointerEvent, (ExecuteEvents.EventFunction <M0>)ExecuteEvents.get_endDragHandler()); } pointerEvent.set_dragging(false); pointerEvent.set_pointerDrag((GameObject)null); ExecuteEvents.ExecuteHierarchy <IPointerExitHandler>(pointerEvent.get_pointerEnter(), (BaseEventData)pointerEvent, (ExecuteEvents.EventFunction <M0>)ExecuteEvents.get_pointerExitHandler()); pointerEvent.set_pointerEnter((GameObject)null); }
public virtual void ProcessUpdated(object sender, PointerEventArgs pointerEventArgs) { uiSampler.Begin(); var pointers = pointerEventArgs.Pointers; var raycast = new RaycastResult(); var count = pointers.Count; for (var i = 0; i < count; i++) { var pointer = pointers[i]; // Don't update the pointer if it is pressed not over an UI element if ((pointer.Buttons & Pointer.PointerButtonState.AnyButtonPressed) > 0) { var press = pointer.GetPressData(); if (press.Type != HitData.HitType.UI) { continue; } } var over = pointer.GetOverData(); // Don't update the pointer if it is not over an UI element if (over.Type != HitData.HitType.UI) { continue; } PointerEventData data; GetPointerData(pointer.Id, out data, true); data.Reset(); var target = over.Target; var currentOverGo = target == null ? null : target.gameObject; data.position = pointer.Position; data.delta = pointer.Position - pointer.PreviousPosition; convertRaycast(over.RaycastHitUI, ref raycast); raycast.screenPosition = data.position; data.pointerCurrentRaycast = raycast; input.HandlePointerExitAndEnter(data, currentOverGo); bool moving = data.IsPointerMoving(); if (moving && data.pointerDrag != null && !data.dragging && ShouldStartDrag(data.pressPosition, data.position, input.eventSystem.pixelDragThreshold, data.useDragThreshold)) { ExecuteEvents.Execute(data.pointerDrag, data, ExecuteEvents.beginDragHandler); data.dragging = true; } // Drag notification if (data.dragging && moving && data.pointerDrag != null) { // Before doing drag we should cancel any pointer down state // And clear selection! if (data.pointerPress != data.pointerDrag) { ExecuteEvents.Execute(data.pointerPress, data, ExecuteEvents.pointerUpHandler); data.eligibleForClick = false; data.pointerPress = null; data.rawPointerPress = null; } ExecuteEvents.Execute(data.pointerDrag, data, ExecuteEvents.dragHandler); } var mousePointer = pointer as MousePointer; if (mousePointer != null && !Mathf.Approximately(mousePointer.ScrollDelta.sqrMagnitude, 0.0f)) { data.scrollDelta = mousePointer.ScrollDelta; var scrollHandler = ExecuteEvents.GetEventHandler <IScrollHandler>(currentOverGo); ExecuteEvents.ExecuteHierarchy(scrollHandler, data, ExecuteEvents.scrollHandler); } } uiSampler.End(); }
public override void Process() { raycaster.eventMask = layerMask; foreach (var pair in _controllerData) { IUILaserPointer controller = pair.Key; ControllerData data = pair.Value; // Test if UICamera is looking at a GUI element UpdateCameraPosition(controller); if (data.pointerEvent == null) { data.pointerEvent = new LaserPointerEventData(eventSystem); } else { data.pointerEvent.Reset(); } data.pointerEvent.controller = controller; data.pointerEvent.delta = Vector2.zero; data.pointerEvent.position = new Vector2(UICamera.pixelWidth * 0.5f, UICamera.pixelHeight * 0.5f); //data.pointerEvent.scrollDelta = Vector2.zero; // trigger a raycast eventSystem.RaycastAll(data.pointerEvent, m_RaycastResultCache); data.pointerEvent.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); m_RaycastResultCache.Clear(); // make sure our controller knows about the raycast result // we add 0.01 because that is the near plane distance of our camera and we want the correct distance if (data.pointerEvent.pointerCurrentRaycast.distance > 0.0f) { controller.LimitLaserDistance(data.pointerEvent.pointerCurrentRaycast.distance + 0.01f); } // stop if no UI element was hit //if(pointerEvent.pointerCurrentRaycast.gameObject == null) //return; // Send control enter and exit events to our controller var hitControl = data.pointerEvent.pointerCurrentRaycast.gameObject; if (data.currentPoint != hitControl) { if (data.currentPoint != null) { controller.OnExitControl(data.currentPoint); } if (hitControl != null) { controller.OnEnterControl(hitControl); } } data.currentPoint = hitControl; // Handle enter and exit events on the GUI controlls that are hit base.HandlePointerExitAndEnter(data.pointerEvent, data.currentPoint); if (controller.ButtonDown()) { ClearSelection(); data.pointerEvent.pressPosition = data.pointerEvent.position; data.pointerEvent.pointerPressRaycast = data.pointerEvent.pointerCurrentRaycast; data.pointerEvent.pointerPress = null; // update current pressed if the curser is over an element if (data.currentPoint != null) { data.currentPressed = data.currentPoint; data.pointerEvent.current = data.currentPressed; GameObject newPressed = ExecuteEvents.ExecuteHierarchy(data.currentPressed, data.pointerEvent, ExecuteEvents.pointerDownHandler); ExecuteEvents.Execute(controller.gameObject, data.pointerEvent, ExecuteEvents.pointerDownHandler); if (newPressed == null) { // some UI elements might only have click handler and not pointer down handler newPressed = ExecuteEvents.ExecuteHierarchy(data.currentPressed, data.pointerEvent, ExecuteEvents.pointerClickHandler); ExecuteEvents.Execute(controller.gameObject, data.pointerEvent, ExecuteEvents.pointerClickHandler); if (newPressed != null) { data.currentPressed = newPressed; } } else { data.currentPressed = newPressed; // we want to do click on button down at same time, unlike regular mouse processing // which does click when mouse goes up over same object it went down on // reason to do this is head tracking might be jittery and this makes it easier to click buttons ExecuteEvents.Execute(newPressed, data.pointerEvent, ExecuteEvents.pointerClickHandler); ExecuteEvents.Execute(controller.gameObject, data.pointerEvent, ExecuteEvents.pointerClickHandler); } if (newPressed != null) { data.pointerEvent.pointerPress = newPressed; data.currentPressed = newPressed; Select(data.currentPressed); } ExecuteEvents.Execute(data.currentPressed, data.pointerEvent, ExecuteEvents.beginDragHandler); ExecuteEvents.Execute(controller.gameObject, data.pointerEvent, ExecuteEvents.beginDragHandler); data.pointerEvent.pointerDrag = data.currentPressed; data.currentDragging = data.currentPressed; } }// button down end if (controller.ButtonUp()) { if (data.currentDragging != null) { data.pointerEvent.current = data.currentDragging; ExecuteEvents.Execute(data.currentDragging, data.pointerEvent, ExecuteEvents.endDragHandler); ExecuteEvents.Execute(controller.gameObject, data.pointerEvent, ExecuteEvents.endDragHandler); if (data.currentPoint != null) { ExecuteEvents.ExecuteHierarchy(data.currentPoint, data.pointerEvent, ExecuteEvents.dropHandler); } data.pointerEvent.pointerDrag = null; data.currentDragging = null; } if (data.currentPressed) { data.pointerEvent.current = data.currentPressed; ExecuteEvents.Execute(data.currentPressed, data.pointerEvent, ExecuteEvents.pointerUpHandler); ExecuteEvents.Execute(controller.gameObject, data.pointerEvent, ExecuteEvents.pointerUpHandler); data.pointerEvent.rawPointerPress = null; data.pointerEvent.pointerPress = null; data.currentPressed = null; } } // drag handling if (data.currentDragging != null) { data.pointerEvent.current = data.currentPressed; ExecuteEvents.Execute(data.currentDragging, data.pointerEvent, ExecuteEvents.dragHandler); ExecuteEvents.Execute(controller.gameObject, data.pointerEvent, ExecuteEvents.dragHandler); } // update selected element for keyboard focus if (base.eventSystem.currentSelectedGameObject != null) { data.pointerEvent.current = eventSystem.currentSelectedGameObject; ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, GetBaseEventData(), ExecuteEvents.updateSelectedHandler); //ExecuteEvents.Execute(controller.gameObject, GetBaseEventData(), ExecuteEvents.updateSelectedHandler); } } }
private void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released) { var currentOverGo = pointerEvent.pointerCurrentRaycast.gameObject; // PointerDown notification if (pressed) { pointerEvent.eligibleForClick = true; pointerEvent.delta = Vector2.zero; pointerEvent.dragging = false; pointerEvent.useDragThreshold = true; pointerEvent.pressPosition = pointerEvent.position; pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast; DeselectIfSelectionChanged(currentOverGo, pointerEvent); if (pointerEvent.pointerEnter != currentOverGo) { // send a pointer enter to the touched element if it isn't the one to select... HandlePointerExitAndEnter(pointerEvent, currentOverGo); pointerEvent.pointerEnter = currentOverGo; } // search for the control that will receive the press // if we can't find a press handler set the press // handler to be what would receive a click. var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.pointerDownHandler); // didnt find a press handler... search for a click handler if (newPressed == null) { newPressed = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo); } // Debug.Log("Pressed: " + newPressed); float time = Time.unscaledTime; if (newPressed == pointerEvent.lastPress) { var diffTime = time - pointerEvent.clickTime; if (diffTime < 0.3f) { ++pointerEvent.clickCount; } else { pointerEvent.clickCount = 1; } pointerEvent.clickTime = time; } else { pointerEvent.clickCount = 1; } pointerEvent.pointerPress = newPressed; pointerEvent.rawPointerPress = currentOverGo; pointerEvent.clickTime = time; // Save the drag handler as well pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(currentOverGo); if (pointerEvent.pointerDrag != null) { ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag); } } // PointerUp notification if (released) { // Debug.Log("Executing pressup on: " + pointer.pointerPress); ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler); // Debug.Log("KeyCode: " + pointer.eventData.keyCode); // see if we mouse up on the same element that we clicked on... var pointerUpHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo); // PointerClick and Drop events if (pointerEvent.pointerPress == pointerUpHandler && pointerEvent.eligibleForClick) { ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler); } else if (pointerEvent.pointerDrag != null) { ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.dropHandler); } pointerEvent.eligibleForClick = false; pointerEvent.pointerPress = null; pointerEvent.rawPointerPress = null; if (pointerEvent.pointerDrag != null && pointerEvent.dragging) { ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler); } pointerEvent.dragging = false; pointerEvent.pointerDrag = null; if (pointerEvent.pointerDrag != null) { ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler); } pointerEvent.pointerDrag = null; // send exit events as we need to simulate this on touch up on touch device ExecuteEvents.ExecuteHierarchy(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler); pointerEvent.pointerEnter = null; } }
public void HandleEvent <T>(BaseEventData eventData, ExecuteEvents.EventFunction <T> eventHandler) where T : IEventSystemHandler { if (!Instance.enabled || disabledRefCount > 0) { return; } // Use focused object when OverrideFocusedObject is null. GameObject focusedObject = (OverrideFocusedObject == null) ? GazeManager.Instance.HitObject : OverrideFocusedObject; // Send the event to global listeners for (int i = 0; i < globalListeners.Count; i++) { // Global listeners should only get events on themselves, as opposed to their hierarchy ExecuteEvents.Execute(globalListeners[i], eventData, eventHandler); } // Handle modal input if one exists if (modalInputStack.Count > 0) { GameObject modalInput = modalInputStack.Peek(); /* * // If there is a focused object in the hierarchy of the modal handler, start the event * // bubble there * if (focusedObject != null && focusedObject.transform.IsChildOf(modalInput.transform)) * { * * if (ExecuteEvents.ExecuteHierarchy(focusedObject, eventData, eventHandler)) * { * return; * } * } * // Otherwise, just invoke the event on the modal handler itself * else * { */ if (ExecuteEvents.ExecuteHierarchy(modalInput, eventData, eventHandler)) { return; } //} } // If event was not handled by modal, pass it on to the current focused object if (focusedObject != null) { bool eventHandled = ExecuteEvents.ExecuteHierarchy(focusedObject, eventData, eventHandler); if (eventHandled) { return; } } // If event was not handled by the focused object, pass it on to any fallback handlers if (fallbackInputStack.Count > 0) { GameObject fallbackInput = fallbackInputStack.Peek(); ExecuteEvents.ExecuteHierarchy(fallbackInput, eventData, eventHandler); } }
//------------------------------------------------------------------------------------------------------------------------------------------// public override void Process() { //public void Update(){ //コントローラからトリガの情報を取得 isSldrBtnClickedLeft = myControllerLeft.isSldrBtnClicked; isSldrBtnClickedRight = myControllerRight.isSldrBtnClicked; if (isSldrBtnClickedLeft || isSldrBtnClickedRight) { // 全UIキャンバスとレーザーのヒットテスト for (int index = 0; index < lasers.Length; index++) { // 現在選択中のUIの選択を解除 ClearSelection(); // レイキャスト & ヒットテストを行う bool hit = GUIRaycast(index); if (hit == false) { lasers[index].AdjustLaserDistance(0); continue; } // ヒットしたオブジェクトを保持 hitObjects[index] = pointEvents[index].pointerCurrentRaycast.gameObject; base.HandlePointerExitAndEnter(pointEvents[index], hitObjects[index]); // レーザーの長さを調整 if (pointEvents[index].pointerCurrentRaycast.distance > 0.0f) { lasers[index].AdjustLaserDistance(pointEvents[index].pointerCurrentRaycast.distance); } // プレスダウンをトラック if (IsPressDown(index)) { pointEvents[index].pressPosition = pointEvents[index].position; pointEvents[index].pointerPressRaycast = pointEvents[index].pointerCurrentRaycast; pointEvents[index].pointerPress = null; if (hitObjects[index] != null) { //プレス開始イベントの発行 pressedObjects[index] = hitObjects[index]; GameObject newPressed = ExecuteEvents.ExecuteHierarchy(pressedObjects[index], pointEvents[index], ExecuteEvents.pointerDownHandler); if (newPressed == null) { // プレスに反応しないUI用にクリック開始イベントを発行 newPressed = ExecuteEvents.ExecuteHierarchy(pressedObjects[index], pointEvents[index], ExecuteEvents.pointerClickHandler); pressedObjects[index] = newPressed; } else { //クリック開始イベントの発行 pressedObjects[index] = newPressed; ExecuteEvents.Execute(newPressed, pointEvents[index], ExecuteEvents.pointerClickHandler); } // 新しく押下したUIを保持する if (newPressed != null) { pointEvents[index].pointerPress = newPressed; pressedObjects[index] = newPressed; Select(pressedObjects[index]); } // ドラッグ開始イベントの発行 ExecuteEvents.Execute(pressedObjects[index], pointEvents[index], ExecuteEvents.beginDragHandler); pointEvents[index].pointerDrag = pressedObjects[index]; dragObjects[index] = pressedObjects[index]; } } //ドラッグ中イベントの発行 if (dragObjects[index] != null) { ExecuteEvents.Execute(dragObjects[index], pointEvents[index], ExecuteEvents.dragHandler); } // プレスアップをトラック if (IsPressUp(index)) { //ドラッグ終了イベントを発行 if (dragObjects[index]) { ExecuteEvents.Execute(dragObjects[index], pointEvents[index], ExecuteEvents.endDragHandler); if (hitObjects[index] != null) { ExecuteEvents.ExecuteHierarchy(hitObjects[index], pointEvents[index], ExecuteEvents.dropHandler); } pointEvents[index].pointerDrag = null; dragObjects[index] = null; } //プレス終了イベントを発行 if (pressedObjects[index]) { ExecuteEvents.Execute(pressedObjects[index], pointEvents[index], ExecuteEvents.pointerUpHandler); pointEvents[index].rawPointerPress = null; pointEvents[index].pointerPress = null; pressedObjects[index] = null; hitObjects[index] = null; } } } //// 全UIキャンバスとレーザーのヒットテスト for } //if isSldrBtnClicked } //Process()
private void OnTriggeGaze() { UpdateReticle(preGazeObject, pointerData); // The gameobject to which raycast positions var curGazeObject = pointerData.pointerCurrentRaycast.gameObject; bool isInteractive = pointerData.pointerPress != null || ExecuteEvents.GetEventHandler <IPointerClickHandler>(curGazeObject) != null; bool sendEvent = false; this.HmdEnterPressDown = WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Head).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Enter); if (this.HmdEnterPressDown) { sendEvent = true; } EnterExitGraphicObject(); EnterExitPhysicsObject(); if (preGazeObject != curGazeObject) { DEBUG("preGazeObject: " + (preGazeObject != null ? preGazeObject.name : "null") + ", curGazeObject: " + (curGazeObject != null ? curGazeObject.name : "null")); if (curGazeObject != null) { gazeTime = this.currUnscaledTime; } } else { if (curGazeObject != null) { if (useWaveVRReticle && gazePointer != null) { gazePointer.triggerProgressBar(true); } if (this.TimerControl) { if (this.currUnscaledTime - gazeTime > TimeToGaze) { sendEvent = true; gazeTime = this.currUnscaledTime; } float rate = ((this.currUnscaledTime - gazeTime) / TimeToGaze) * 100; if (useWaveVRReticle && gazePointer != null) { gazePointer.setProgressBarTime(rate); } else { if (ringMesh != null) { ringMesh.RingPercent = isInteractive ? (int)rate : 0; } } } if (this.ButtonControl) { if (!this.TimerControl) { if (useWaveVRReticle && gazePointer != null) { gazePointer.triggerProgressBar(false); } else { if (ringMesh != null) { ringMesh.RingPercent = 0; } } } UpdateButtonStates(); if (btnPressDown) { sendEvent = true; this.gazeTime = this.currUnscaledTime; } } } else { if (useWaveVRReticle && gazePointer != null) { gazePointer.triggerProgressBar(false); } else { if (ringMesh != null) { ringMesh.RingPercent = 0; } } } } // Standalone Input Module information pointerData.delta = Vector2.zero; pointerData.dragging = false; DeselectIfSelectionChanged(curGazeObject, pointerData); if (sendEvent) { DEBUG("OnTriggeGaze() selected " + curGazeObject.name); if (InputEvent == EGazeInputEvent.PointerClick) { ExecuteEvents.ExecuteHierarchy(curGazeObject, pointerData, ExecuteEvents.pointerClickHandler); pointerData.clickTime = this.currUnscaledTime; } else if (InputEvent == EGazeInputEvent.PointerDown) { // like "mouse" action, press->release soon, do NOT keep the pointerPressRaycast cause do NOT need to controll "down" object while not gazing. pointerData.pressPosition = pointerData.position; pointerData.pointerPressRaycast = pointerData.pointerCurrentRaycast; var _pointerDownGO = ExecuteEvents.ExecuteHierarchy(curGazeObject, pointerData, ExecuteEvents.pointerDownHandler); ExecuteEvents.ExecuteHierarchy(_pointerDownGO, pointerData, ExecuteEvents.pointerUpHandler); } else if (InputEvent == EGazeInputEvent.PointerSubmit) { ExecuteEvents.ExecuteHierarchy(curGazeObject, pointerData, ExecuteEvents.submitHandler); } } }
/// <summary> /// Called by a BaseInputModule when a drag is ended. /// </summary> /// <param name="eventData">Current event data.</param> public void OnEndDrag(PointerEventData eventData) { if (m_CurrentDragIsHorizontal) { if (m_CombineLeftAndRight) { if (m_HorizontalTargetObject != null) { ExecuteEvents.ExecuteHierarchy(m_HorizontalTargetObject, eventData, ExecuteEvents.endDragHandler); } } else { m_CurrentDragIsLeft = eventData.delta.x < 0; if (m_CurrentDragIsLeft) { if (m_LeftTargetObject != null) { ExecuteEvents.ExecuteHierarchy(m_LeftTargetObject, eventData, ExecuteEvents.endDragHandler); } } else { if (m_RightTargetObject != null) { ExecuteEvents.ExecuteHierarchy(m_RightTargetObject, eventData, ExecuteEvents.endDragHandler); } } } } else { if (m_CombineUpAndDown) { if (m_VerticalTargetObject != null) { ExecuteEvents.ExecuteHierarchy(m_VerticalTargetObject, eventData, ExecuteEvents.endDragHandler); } } else { m_CurrentDragIsUp = eventData.delta.y > 0; if (m_CurrentDragIsUp) { if (m_UpTargetObject != null) { ExecuteEvents.ExecuteHierarchy(m_UpTargetObject, eventData, ExecuteEvents.endDragHandler); } } else { if (m_DownTargetObject != null) { ExecuteEvents.ExecuteHierarchy(m_DownTargetObject, eventData, ExecuteEvents.endDragHandler); } } } } if (m_AnyDirectionTargetObject != null) { ExecuteEvents.ExecuteHierarchy(m_AnyDirectionTargetObject, eventData, ExecuteEvents.endDragHandler); } }
// Process is called by UI system to process events public override void Process() { VRCursorController cursor = VRCursorController.GetInstance(); // Bail if where not on the UI plane if (cursor.CursorPlane != VRCursorController.eCursorPlane.XYPlane) { ClearSelection(); return; } // send update events if there is a selected object - this is important for InputField to receive keyboard events SendUpdateEventToSelectedObject(); // see if there is a UI element that is currently being looked at PointerEventData lookData = GetLookPointerEventData(); m_currentHoverObject = lookData.pointerCurrentRaycast.gameObject; // handle enter and exit events (highlight) // using the function that is already defined in BaseInputModule HandlePointerExitAndEnter(lookData, m_currentHoverObject); // Cursor Pressed Handling if (cursor.GetCursorPressed()) { ClearSelection(); lookData.pressPosition = lookData.position; lookData.pointerPressRaycast = lookData.pointerCurrentRaycast; lookData.pointerPress = null; if (m_currentHoverObject != null) { GameObject newPressed = null; m_currentPressedObject = m_currentHoverObject; newPressed = ExecuteEvents.ExecuteHierarchy(m_currentPressedObject, lookData, ExecuteEvents.pointerDownHandler); if (newPressed == null) { // some UI elements might only have click handler and not pointer down handler newPressed = ExecuteEvents.ExecuteHierarchy(m_currentPressedObject, lookData, ExecuteEvents.pointerClickHandler); if (newPressed != null) { m_currentPressedObject = newPressed; } } else { m_currentPressedObject = newPressed; // we want to do click on button down at same time, unlike regular mouse processing // which does click when mouse goes up over same object it went down on // reason to do this is head tracking might be jittery and this makes it easier to click buttons ExecuteEvents.Execute(newPressed, lookData, ExecuteEvents.pointerClickHandler); } if (newPressed != null) { lookData.pointerPress = newPressed; m_currentPressedObject = newPressed; Select(m_currentPressedObject); } if (ExecuteEvents.Execute(m_currentPressedObject, lookData, ExecuteEvents.beginDragHandler)) { lookData.pointerDrag = m_currentPressedObject; m_currentDraggingObject = m_currentPressedObject; } } } // Cursor release handling if (cursor.GetCursorReleased()) { if (m_currentDraggingObject) { ExecuteEvents.Execute(m_currentDraggingObject, lookData, ExecuteEvents.endDragHandler); if (m_currentHoverObject != null) { ExecuteEvents.ExecuteHierarchy(m_currentHoverObject, lookData, ExecuteEvents.dropHandler); } lookData.pointerDrag = null; m_currentDraggingObject = null; } if (m_currentPressedObject) { ExecuteEvents.Execute(m_currentPressedObject, lookData, ExecuteEvents.pointerUpHandler); lookData.rawPointerPress = null; lookData.pointerPress = null; m_currentPressedObject = null; } } // Drag handling if (m_currentDraggingObject != null) { ExecuteEvents.Execute(m_currentDraggingObject, lookData, ExecuteEvents.dragHandler); } // Scroll Handling if (eventSystem.currentSelectedGameObject != null) { float scrollAmount = cursor.GetCursorScroll(); if (scrollAmount > 0.01f || scrollAmount < -0.01f) { Slider slider = eventSystem.currentSelectedGameObject.GetComponent <Slider>(); if (slider != null) { float multiplier = slider.maxValue - slider.minValue; slider.value += scrollAmount * ScrollSpeedMultiplier * multiplier; } else { Scrollbar scrollBar = eventSystem.currentSelectedGameObject.GetComponent <Scrollbar>(); if (scrollBar != null) { scrollBar.value += scrollAmount * ScrollSpeedMultiplier; } } } } // Tab Handling if (eventSystem.currentSelectedGameObject != null && Input.GetKeyUp(KeyCode.Tab)) { AxisEventData axisData = new AxisEventData(this.eventSystem); axisData.moveDir = MoveDirection.Down; ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, axisData, ExecuteEvents.moveHandler); } }
private void HandleShooting() { if (Time.time > fireRate + lastShot && clipSize > 0) { clipSize--; lastShot = Time.time; if (isHitScanWeapon == true) { if (currentWeapon != null) { ParticleSystem particleSystem = currentWeapon.GetComponentInChildren <ParticleSystem>(); AudioSource weaponSound = currentWeapon.GetComponent <AudioSource>(); Animator weaponAnimation = currentWeapon.GetComponent <Animator>(); if (weaponSound != null) { weaponSound.Play(); } if (weaponAnimation != null) { weaponAnimation.SetTrigger("Shoot"); } if (particleSystem != null) { particleSystem.Play(); } else { Debug.LogError("The CurrentWeapons ParticleSystem is null, add it in the Inspector!"); } } else { Debug.LogError("The CurrentWeapon GameObject is empty, check that your weapon sets the CurrentWeapon GameObject in OnEnable()"); } if (Physics.Raycast(CheckRay(), out hitInfo, Mathf.Infinity)) { ExecuteEvents.ExecuteHierarchy(hitInfo.collider.gameObject, damageEventData, DamageEventData.OnDamageHandler); if (impactEffect != null) { GameObject impactEffectGO = GameObject.Instantiate(impactEffect, hitInfo.point, Quaternion.LookRotation(hitInfo.normal)); GameObject.Destroy(impactEffectGO, 0.35f); } if (hitInfo.rigidbody != null) { //hitInfo.rigidbody.AddForceAtPosition(hitForce, hitInfo.point, ForceMode.Impulse); hitInfo.rigidbody.AddForce(hitForce); } } } else { Debug.Log("Now you are shooting a projectile weapon"); } } }
// Process is called by UI system to process events public override void Process() { OnCanvas = false; CanvasUsed = false; // send update events if there is a selected object - this is important for InputField to receive keyboard events SendUpdateEventToSelectedObject(); // see if there is a UI element that is currently being looked at for (int index = 0; index < Cursors.Length; index++) { if (NVRPlayer.Instance.Hands[index].gameObject.activeInHierarchy == false) { if (Cursors[index].gameObject.activeInHierarchy == true) { Cursors[index].gameObject.SetActive(false); } continue; } UpdateCameraPosition(index); bool hit = GetLookPointerEventData(index); if (hit == false) { continue; } CurrentPoint[index] = PointEvents[index].pointerCurrentRaycast.gameObject; // handle enter and exit events (highlight) base.HandlePointerExitAndEnter(PointEvents[index], CurrentPoint[index]); // update cursor UpdateCursor(index, PointEvents[index]); if (NVRPlayer.Instance.Hands[index] != null) { if (ButtonDown(index)) { ClearSelection(); PointEvents[index].pressPosition = PointEvents[index].position; PointEvents[index].pointerPressRaycast = PointEvents[index].pointerCurrentRaycast; PointEvents[index].pointerPress = null; if (CurrentPoint[index] != null) { CurrentPressed[index] = CurrentPoint[index]; GameObject newPressed = ExecuteEvents.ExecuteHierarchy(CurrentPressed[index], PointEvents[index], ExecuteEvents.pointerDownHandler); if (newPressed == null) { // some UI elements might only have click handler and not pointer down handler newPressed = ExecuteEvents.ExecuteHierarchy(CurrentPressed[index], PointEvents[index], ExecuteEvents.pointerClickHandler); if (newPressed != null) { CurrentPressed[index] = newPressed; } } else { CurrentPressed[index] = newPressed; // we want to do click on button down at same time, unlike regular mouse processing // which does click when mouse goes up over same object it went down on // reason to do this is head tracking might be jittery and this makes it easier to click buttons ExecuteEvents.Execute(newPressed, PointEvents[index], ExecuteEvents.pointerClickHandler); } if (newPressed != null) { PointEvents[index].pointerPress = newPressed; CurrentPressed[index] = newPressed; Select(CurrentPressed[index]); CanvasUsed = true; } ExecuteEvents.Execute(CurrentPressed[index], PointEvents[index], ExecuteEvents.beginDragHandler); PointEvents[index].pointerDrag = CurrentPressed[index]; CurrentDragging[index] = CurrentPressed[index]; } } if (ButtonUp(index)) { if (CurrentDragging[index]) { ExecuteEvents.Execute(CurrentDragging[index], PointEvents[index], ExecuteEvents.endDragHandler); if (CurrentPoint[index] != null) { ExecuteEvents.ExecuteHierarchy(CurrentPoint[index], PointEvents[index], ExecuteEvents.dropHandler); } PointEvents[index].pointerDrag = null; CurrentDragging[index] = null; } if (CurrentPressed[index]) { ExecuteEvents.Execute(CurrentPressed[index], PointEvents[index], ExecuteEvents.pointerUpHandler); PointEvents[index].rawPointerPress = null; PointEvents[index].pointerPress = null; CurrentPressed[index] = null; } } // drag handling if (CurrentDragging[index] != null) { ExecuteEvents.Execute(CurrentDragging[index], PointEvents[index], ExecuteEvents.dragHandler); } } } }
public static void Inject(this MonoBehaviour script) { ExecuteEvents.ExecuteHierarchy <IMonoInjectionHandler>(script.gameObject, null, (target, data) => target.InjectDependencies(script)); }
private void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released) { GameObject gameObject = pointerEvent.pointerCurrentRaycast.gameObject; if (pressed) { pointerEvent.eligibleForClick = true; pointerEvent.delta = Vector2.zero; pointerEvent.dragging = false; pointerEvent.useDragThreshold = true; pointerEvent.pressPosition = pointerEvent.position; pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast; base.DeselectIfSelectionChanged(gameObject, pointerEvent); if (pointerEvent.pointerEnter != gameObject) { base.HandlePointerExitAndEnter(pointerEvent, gameObject); pointerEvent.pointerEnter = gameObject; } GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy <IPointerDownHandler>(gameObject, pointerEvent, ExecuteEvents.pointerDownHandler); if (gameObject2 == null) { gameObject2 = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject); } float unscaledTime = Time.unscaledTime; if (gameObject2 == pointerEvent.lastPress) { float num = unscaledTime - pointerEvent.clickTime; if (num < 0.3f) { pointerEvent.clickCount++; } else { pointerEvent.clickCount = 1; } pointerEvent.clickTime = unscaledTime; } else { pointerEvent.clickCount = 1; } pointerEvent.pointerPress = gameObject2; pointerEvent.rawPointerPress = gameObject; pointerEvent.clickTime = unscaledTime; pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(gameObject); if (pointerEvent.pointerDrag != null) { ExecuteEvents.Execute <IInitializePotentialDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag); } } if (released) { ExecuteEvents.Execute <IPointerUpHandler>(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler); GameObject eventHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject); if (pointerEvent.pointerPress == eventHandler && pointerEvent.eligibleForClick) { ExecuteEvents.Execute <IPointerClickHandler>(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler); } else if (pointerEvent.pointerDrag != null && pointerEvent.dragging) { ExecuteEvents.ExecuteHierarchy <IDropHandler>(gameObject, pointerEvent, ExecuteEvents.dropHandler); } pointerEvent.eligibleForClick = false; pointerEvent.pointerPress = null; pointerEvent.rawPointerPress = null; if (pointerEvent.pointerDrag != null && pointerEvent.dragging) { ExecuteEvents.Execute <IEndDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler); } pointerEvent.dragging = false; pointerEvent.pointerDrag = null; if (pointerEvent.pointerDrag != null) { ExecuteEvents.Execute <IEndDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler); } pointerEvent.pointerDrag = null; ExecuteEvents.ExecuteHierarchy <IPointerExitHandler>(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler); pointerEvent.pointerEnter = null; } }
public void OnPointerClick(BaseEventData eventData) { // Handle event here AND in ancestors ExecuteEvents.ExecuteHierarchy(transform.parent.gameObject, eventData, ExecuteEvents.pointerClickHandler); }
public void OnDrop(PointerEventData eventData) //東西放下去的時候會自動呼叫 { if (!item) // 若沒子物件,則現在馬上設定拖拉的物件變成這個slot的子物件 { TutorialChuteDrag.itemBeingDragged.transform.SetParent(transform); ExecuteEvents.ExecuteHierarchy <IHasChanged>(gameObject, null, (x, y) => x.HasChanged()); } if (TutorialChuteDrag.itemBeingDragged.GetComponent <TutorialChuteDrag>().ID == correctID) //比對看看放上來的box是否是自己在等的正確ID(答案),是的話往下執行綠色動畫 { tube[3].SetBool("Correct1", true); putAnswer.SetBool("NumberMove", true); AudioManager.instance.soundAudioSource2.clip = AudioManager.instance.soundClip[2]; AudioManager.instance.soundAudioSource2.Play(); StartCoroutine(WaitCorrectAnimation(0.5f)); StartCoroutine(BoxMoveBack(0.75f)); GameObject.FindObjectOfType <TutorialChutes>().CorrectResultDialogue(); StartCoroutine(PlayParticle(0.85f)); scoreText.text = 200.ToString(); } else //不是的話執行紅色表示答錯的動畫 { AudioManager.instance.soundAudioSource2.clip = AudioManager.instance.soundClip[2]; AudioManager.instance.soundAudioSource2.Play(); switch (tubeNumber) { case 1: tube[0].SetBool("Wrong1", true); putAnswer.SetBool("NumberMove", true); GameObject.FindObjectOfType <TutorialChutes>().FalseResultDialogue(); //顯示出Opps, almost there, 這個script在Bubbletext_image下面的text上 StartCoroutine(WaitWrongAnimation(0.5f, 0)); StartCoroutine(BoxMoveBack(0.75f)); break; case 2: tube[1].SetBool("Wrong1", true); putAnswer.SetBool("NumberMove", true); GameObject.FindObjectOfType <TutorialChutes>().FalseResultDialogue(); StartCoroutine(WaitWrongAnimation(0.5f, 1)); StartCoroutine(BoxMoveBack(0.75f)); break; case 3: tube[2].SetBool("Wrong1", true); putAnswer.SetBool("NumberMove", true); GameObject.FindObjectOfType <TutorialChutes>().FalseResultDialogue(); StartCoroutine(WaitWrongAnimation(0.5f, 2)); StartCoroutine(BoxMoveBack(0.75f)); break; case 4: tube[3].SetBool("Wrong1", true); putAnswer.SetBool("NumberMove", true); GameObject.FindObjectOfType <TutorialChutes>().FalseResultDialogue(); StartCoroutine(WaitWrongAnimation(0.5f, 3)); StartCoroutine(BoxMoveBack(0.75f)); break; } } }
protected virtual void Hover(VRTK_UIPointer pointer, List <RaycastResult> results) { if (pointer.pointerEventData.pointerEnter != null) { CheckPointerHoverClick(pointer, results); if (!ValidElement(pointer.pointerEventData.pointerEnter)) { pointer.pointerEventData.pointerEnter = null; return; } if (NoValidCollision(pointer, results)) { ExecuteEvents.ExecuteHierarchy(pointer.pointerEventData.pointerEnter, pointer.pointerEventData, ExecuteEvents.pointerExitHandler); pointer.pointerEventData.hovered.Remove(pointer.pointerEventData.pointerEnter); pointer.pointerEventData.pointerEnter = null; } } else { for (int i = 0; i < results.Count; i++) { RaycastResult result = results[i]; if (!ValidElement(result.gameObject)) { continue; } GameObject target = ExecuteEvents.ExecuteHierarchy(result.gameObject, pointer.pointerEventData, ExecuteEvents.pointerEnterHandler); target = (target == null ? result.gameObject : target); if (target != null) { Selectable selectable = target.GetComponent <Selectable>(); if (selectable != null) { Navigation noNavigation = new Navigation(); noNavigation.mode = Navigation.Mode.None; selectable.navigation = noNavigation; } if (pointer.hoveringElement != null && pointer.hoveringElement != target) { pointer.OnUIPointerElementExit(pointer.SetUIPointerEvent(result, null, pointer.hoveringElement)); } pointer.OnUIPointerElementEnter(pointer.SetUIPointerEvent(result, target, pointer.hoveringElement)); pointer.hoveringElement = target; pointer.pointerEventData.pointerCurrentRaycast = result; pointer.pointerEventData.pointerEnter = target; pointer.pointerEventData.hovered.Add(pointer.pointerEventData.pointerEnter); break; } if (result.gameObject != pointer.hoveringElement) { pointer.OnUIPointerElementEnter(pointer.SetUIPointerEvent(result, result.gameObject, pointer.hoveringElement)); } pointer.hoveringElement = result.gameObject; } if (pointer.hoveringElement && results.Count == 0) { pointer.OnUIPointerElementExit(pointer.SetUIPointerEvent(new RaycastResult(), null, pointer.hoveringElement)); pointer.hoveringElement = null; } } }
protected void ProcessMousePress(MouseButtonEventData data) { var pointerEvent = data.buttonData; var currentOverGo = pointerEvent.pointerCurrentRaycast.gameObject; // PointerDown notification if (data.PressedThisFrame()) { pointerEvent.eligibleForClick = true; pointerEvent.delta = Vector2.zero; pointerEvent.dragging = false; pointerEvent.useDragThreshold = true; pointerEvent.pressPosition = pointerEvent.position; pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast; DeselectIfSelectionChanged(currentOverGo, pointerEvent); var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.pointerDownHandler); // didnt find a press handler... search for a click handler if ((System.Object)newPressed == null) { newPressed = ExecuteEvents.GetEventHandler <IPointerClickHandler> (currentOverGo); } // Debug.Log("Pressed: " + newPressed); var time = Time.unscaledTime; if (newPressed == pointerEvent.lastPress) { var diffTime = time - pointerEvent.clickTime; if (diffTime < 0.3f) { pointerEvent.clickCount++; } else { pointerEvent.clickCount = 1; } // pointerEvent.clickTime = time; } else { pointerEvent.clickCount = 1; } pointerEvent.pointerPress = newPressed; pointerEvent.rawPointerPress = currentOverGo; pointerEvent.clickTime = time; // Save the drag handler as well pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler> (currentOverGo); if (pointerEvent.pointerDrag != null) { ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag); } } // PointerUp notification if (data.ReleasedThisFrame()) { // Debug.Log("Executing pressup on: " + pointer.pointerPress); ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler); var pointerUpHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler> (currentOverGo); if (pointerEvent.pointerPress == pointerUpHandler && pointerEvent.eligibleForClick) { ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler); } else { if (pointerEvent.pointerDrag != null && pointerEvent.dragging) { ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.dropHandler); } } pointerEvent.eligibleForClick = false; pointerEvent.pointerPress = null; pointerEvent.rawPointerPress = null; if (pointerEvent.pointerDrag != null && pointerEvent.dragging) { ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler); } pointerEvent.dragging = false; pointerEvent.pointerDrag = null; if (currentOverGo != pointerEvent.pointerEnter) { HandlePointerExitAndEnter(pointerEvent, null); HandlePointerExitAndEnter(pointerEvent, currentOverGo); } } }
// Process is called by UI system to process events public override void Process() { // send update events if there is a selected object - this is important for InputField to receive keyboard events SendUpdateEventToSelectedObject(); // see if there is a UI element that is currently being looked at for (int index = 0; index < controllerData.Length; index++) { ControllerData ctrl = controllerData[index]; if (ctrl.transform.gameObject.activeInHierarchy == false) { // if (Cursors[index].gameObject.activeInHierarchy == true) { // Cursors[index].gameObject.SetActive(false); } continue; } UpdateCameraPosition(ref ctrl); GetLookPointerEventData(ref ctrl); // what object are we pointing at? ctrl.currentPoint = ctrl.eventData.pointerCurrentRaycast.gameObject; // is the pointer ray inactive? if ((ctrl.ray != null) && !ctrl.ray.rayEnabled) { // yes > no active object ctrl.currentPoint = null; } // handle enter and exit events (highlight) base.HandlePointerExitAndEnter(ctrl.eventData, ctrl.currentPoint); // update cursor UpdateCursor(ref ctrl); if (ctrl.actionHandler.IsActivated()) { ClearSelection(); ctrl.eventData.pressPosition = ctrl.eventData.position; ctrl.eventData.pointerPressRaycast = ctrl.eventData.pointerCurrentRaycast; ctrl.eventData.pointerPress = null; if (ctrl.currentPoint != null) { ctrl.currentPressed = ctrl.currentPoint; GameObject newPressed = ExecuteEvents.ExecuteHierarchy(ctrl.currentPressed, ctrl.eventData, ExecuteEvents.pointerDownHandler); if (newPressed == null) { // some UI elements might only have click handler and not pointer down handler newPressed = ExecuteEvents.ExecuteHierarchy(ctrl.currentPressed, ctrl.eventData, ExecuteEvents.pointerClickHandler); if (newPressed != null) { ctrl.currentPressed = newPressed; } } else { ctrl.currentPressed = newPressed; // we want to do click on button down at same time, unlike regular mouse processing // which does click when mouse goes up over same object it went down on // reason to do this is head tracking might be jittery and this makes it easier to click buttons ExecuteEvents.Execute(newPressed, ctrl.eventData, ExecuteEvents.pointerClickHandler); } if (newPressed != null) { ctrl.eventData.pointerPress = newPressed; ctrl.currentPressed = newPressed; Select(ctrl.currentPressed); } ExecuteEvents.Execute(ctrl.currentPressed, ctrl.eventData, ExecuteEvents.beginDragHandler); ctrl.eventData.pointerDrag = ctrl.currentPressed; ctrl.currentDragging = ctrl.currentPressed; } } if (ctrl.actionHandler.IsDeactivated()) { if (ctrl.currentDragging) { ExecuteEvents.Execute(ctrl.currentDragging, ctrl.eventData, ExecuteEvents.endDragHandler); if (ctrl.currentPoint != null) { ExecuteEvents.ExecuteHierarchy(ctrl.currentPoint, ctrl.eventData, ExecuteEvents.dropHandler); } ctrl.eventData.pointerDrag = null; ctrl.currentDragging = null; } if (ctrl.currentPressed) { ExecuteEvents.Execute(ctrl.currentPressed, ctrl.eventData, ExecuteEvents.pointerUpHandler); ctrl.eventData.rawPointerPress = null; ctrl.eventData.pointerPress = null; ctrl.currentPressed = null; } ClearSelection(); } // drag handling if (ctrl.currentDragging != null) { ExecuteEvents.Execute(ctrl.currentDragging, ctrl.eventData, ExecuteEvents.dragHandler); } } }
public override void Process() { for (int i = _controllerData.Count - 1; i >= 0; i--) { ILaserPointer controller = _controllerData.ElementAt(i).Key; ControllerData data = _controllerData.ElementAt(i).Value; // Test if UICamera is looking at a GUI element UpdateCameraPosition(controller); if (data.pointerEvent == null) { data.pointerEvent = new PointerEventData(eventSystem); } else { data.pointerEvent.Reset(); } data.pointerEvent.delta = Vector2.zero; data.pointerEvent.position = new Vector2(Screen.width * 0.5f, Screen.height * 0.5f); data.pointerEvent.scrollDelta = Vector2.zero; // trigger a raycast eventSystem.RaycastAll(data.pointerEvent, m_RaycastResultCache); data.pointerEvent.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); m_RaycastResultCache.Clear(); // make sure our controller knows about the raycast result // we add 0.0001 because that is the near plane distance of our camera and we want the correct distance if (data.pointerEvent.pointerCurrentRaycast.distance > 0.0f) { controller.LimitLaserDistance(data.pointerEvent.pointerCurrentRaycast.distance + .001f); } // stop if no UI element was hit //if(pointerEvent.pointerCurrentRaycast.gameObject == null) //return; // Send control enter and exit events to our controller var hitControl = data.pointerEvent.pointerCurrentRaycast.gameObject; if (data.currentPoint != hitControl) { if (data.currentPoint != null) { controller.OnExitControl(data.currentPoint); } if (hitControl != null) { controller.OnEnterControl(hitControl); } } if (hitControl != null) { controller.OnUpdateControl(hitControl, data.pointerEvent); } data.currentPoint = hitControl; // Handle enter and exit events on the GUI controlls that are hit base.HandlePointerExitAndEnter(data.pointerEvent, data.currentPoint); // button down begin if (controller.ButtonDown() || UnityEngine.Input.GetKeyDown(KeyCode.D)) { ClearSelection(); data.pointerEvent.pressPosition = data.pointerEvent.position; eventSystem.RaycastAll(data.pointerEvent, m_RaycastResultCache); data.pointerEvent.pointerPressRaycast = FindFirstRaycast(m_RaycastResultCache); data.pointerEvent.pointerPress = null; /* * Ray mouseRay = Camera.main.ScreenPointToRay(UnityEngine.Input.mousePosition); * Debug.DrawRay(mouseRay.origin, mouseRay.direction * 10, Color.green, 50); * RaycastHit hit; * if (Physics.Raycast(mouseRay, out hit)) * { * Debug.Log("Object hit: " + hit.transform.gameObject.name); * } */ data.pointerEvent.pressPosition = UnityEngine.Input.mousePosition; eventSystem.RaycastAll(data.pointerEvent, m_RaycastResultCache); data.pointerEvent.pointerPressRaycast = FindFirstRaycast(m_RaycastResultCache); data.pointerEvent.pointerPress = null; // update current pressed if the curser is over an element if (data.currentPoint != null) { data.currentPressed = data.currentPoint; GameObject newPressed = ExecuteEvents.ExecuteHierarchy(data.currentPressed, data.pointerEvent, ExecuteEvents.pointerDownHandler); if (newPressed == null) { // some UI elements might only have click handler and not pointer down handler newPressed = ExecuteEvents.ExecuteHierarchy(data.currentPressed, data.pointerEvent, ExecuteEvents.pointerClickHandler); if (newPressed != null) { data.currentPressed = newPressed; } } else { data.currentPressed = newPressed; // we want to do click on button down at same time, unlike regular mouse processing // which does click when mouse goes up over same object it went down on // reason to do this is head tracking might be jittery and this makes it easier to click buttons ExecuteEvents.Execute(newPressed, data.pointerEvent, ExecuteEvents.pointerClickHandler); } if (newPressed != null) { data.pointerEvent.pointerPress = newPressed; data.currentPressed = newPressed; Select(data.currentPressed); } ExecuteEvents.Execute(data.currentPressed, data.pointerEvent, ExecuteEvents.beginDragHandler); data.pointerEvent.pointerDrag = data.currentPressed; data.currentDragging = data.currentPressed; } } // button down end // button up begin if (controller.ButtonUp() || UnityEngine.Input.GetKeyUp(KeyCode.D)) { if (data.currentDragging != null) { ExecuteEvents.Execute(data.currentDragging, data.pointerEvent, ExecuteEvents.endDragHandler); if (data.currentPoint != null) { ExecuteEvents.ExecuteHierarchy(data.currentPoint, data.pointerEvent, ExecuteEvents.dropHandler); } data.pointerEvent.pointerDrag = null; data.currentDragging = null; } if (data.currentPressed) { ExecuteEvents.Execute(data.currentPressed, data.pointerEvent, ExecuteEvents.pointerUpHandler); data.pointerEvent.rawPointerPress = null; data.pointerEvent.pointerPress = null; data.currentPressed = null; } } // button up end // drag handling if (data.currentDragging != null) { ExecuteEvents.Execute(data.currentDragging, data.pointerEvent, ExecuteEvents.dragHandler); } } }
protected void ProcessMousePress(PointerInputModule.MouseButtonEventData data) { PointerEventData buttonData = (PointerEventData)data.buttonData; RaycastResult pointerCurrentRaycast = buttonData.get_pointerCurrentRaycast(); GameObject gameObject1 = ((RaycastResult) ref pointerCurrentRaycast).get_gameObject(); if (data.PressedThisFrame()) { buttonData.set_eligibleForClick(true); buttonData.set_delta(Vector2.get_zero()); buttonData.set_dragging(false); buttonData.set_useDragThreshold(true); buttonData.set_pressPosition(buttonData.get_position()); buttonData.set_pointerPressRaycast(buttonData.get_pointerCurrentRaycast()); this.DeselectIfSelectionChanged(gameObject1, (BaseEventData)buttonData); GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy <IPointerDownHandler>(gameObject1, (BaseEventData)buttonData, (ExecuteEvents.EventFunction <M0>)ExecuteEvents.get_pointerDownHandler()); if (Object.op_Equality((Object)gameObject2, (Object)null)) { gameObject2 = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject1); } float unscaledTime = Time.get_unscaledTime(); if (Object.op_Equality((Object)gameObject2, (Object)buttonData.get_lastPress())) { if ((double)(unscaledTime - buttonData.get_clickTime()) < 0.300000011920929) { PointerEventData pointerEventData = buttonData; pointerEventData.set_clickCount(pointerEventData.get_clickCount() + 1); } else { buttonData.set_clickCount(1); } buttonData.set_clickTime(unscaledTime); } else { buttonData.set_clickCount(1); } buttonData.set_pointerPress(gameObject2); buttonData.set_rawPointerPress(gameObject1); buttonData.set_clickTime(unscaledTime); buttonData.set_pointerDrag(ExecuteEvents.GetEventHandler <IDragHandler>(gameObject1)); if (Object.op_Inequality((Object)buttonData.get_pointerDrag(), (Object)null)) { ExecuteEvents.Execute <IInitializePotentialDragHandler>(buttonData.get_pointerDrag(), (BaseEventData)buttonData, (ExecuteEvents.EventFunction <M0>)ExecuteEvents.get_initializePotentialDrag()); } } if (!data.ReleasedThisFrame()) { return; } ExecuteEvents.Execute <IPointerUpHandler>(buttonData.get_pointerPress(), (BaseEventData)buttonData, (ExecuteEvents.EventFunction <M0>)ExecuteEvents.get_pointerUpHandler()); GameObject eventHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject1); if (Object.op_Equality((Object)buttonData.get_pointerPress(), (Object)eventHandler) && buttonData.get_eligibleForClick()) { ExecuteEvents.Execute <IPointerClickHandler>(buttonData.get_pointerPress(), (BaseEventData)buttonData, (ExecuteEvents.EventFunction <M0>)ExecuteEvents.get_pointerClickHandler()); } else if (Object.op_Inequality((Object)buttonData.get_pointerDrag(), (Object)null) && buttonData.get_dragging()) { ExecuteEvents.ExecuteHierarchy <IDropHandler>(gameObject1, (BaseEventData)buttonData, (ExecuteEvents.EventFunction <M0>)ExecuteEvents.get_dropHandler()); } buttonData.set_eligibleForClick(false); buttonData.set_pointerPress((GameObject)null); buttonData.set_rawPointerPress((GameObject)null); if (Object.op_Inequality((Object)buttonData.get_pointerDrag(), (Object)null) && buttonData.get_dragging()) { ExecuteEvents.Execute <IEndDragHandler>(buttonData.get_pointerDrag(), (BaseEventData)buttonData, (ExecuteEvents.EventFunction <M0>)ExecuteEvents.get_endDragHandler()); } buttonData.set_dragging(false); buttonData.set_pointerDrag((GameObject)null); if (!Object.op_Inequality((Object)gameObject1, (Object)buttonData.get_pointerEnter())) { return; } ((BaseInputModule)this).HandlePointerExitAndEnter(buttonData, (GameObject)null); ((BaseInputModule)this).HandlePointerExitAndEnter(buttonData, gameObject1); }
// Process is called by UI system to process events public override void Process() { _singleton = this; // send update events if there is a selected object - this is important for InputField to receive keyboard events SendUpdateEventToSelectedObject(); // see if there is a UI element that is currently being looked at PointerEventData lookData = GetLookPointerEventData(); currentLook = lookData.pointerCurrentRaycast.gameObject; // deselect when look away if (deselectWhenLookAway && currentLook == null) { ClearSelection(); } // handle enter and exit events (highlight) // using the function that is already defined in BaseInputModule HandlePointerExitAndEnter(lookData, currentLook); // update cursor UpdateCursor(lookData); if (!ignoreInputsWhenLookAway || ignoreInputsWhenLookAway && currentLook != null) { // button down handling _buttonUsed = false; if (Input.GetButtonDown(submitButtonName)) { ClearSelection(); lookData.pressPosition = lookData.position; lookData.pointerPressRaycast = lookData.pointerCurrentRaycast; lookData.pointerPress = null; if (currentLook != null) { currentPressed = currentLook; GameObject newPressed = null; if (mode == Mode.Pointer) { newPressed = ExecuteEvents.ExecuteHierarchy(currentPressed, lookData, ExecuteEvents.pointerDownHandler); if (newPressed == null) { // some UI elements might only have click handler and not pointer down handler newPressed = ExecuteEvents.ExecuteHierarchy(currentPressed, lookData, ExecuteEvents.pointerClickHandler); if (newPressed != null) { currentPressed = newPressed; } } else { currentPressed = newPressed; // we want to do click on button down at same time, unlike regular mouse processing // which does click when mouse goes up over same object it went down on // reason to do this is head tracking might be jittery and this makes it easier to click buttons ExecuteEvents.Execute(newPressed, lookData, ExecuteEvents.pointerClickHandler); } } else if (mode == Mode.Submit) { newPressed = ExecuteEvents.ExecuteHierarchy(currentPressed, lookData, ExecuteEvents.submitHandler); if (newPressed == null) { // try select handler instead newPressed = ExecuteEvents.ExecuteHierarchy(currentPressed, lookData, ExecuteEvents.selectHandler); } } if (newPressed != null) { lookData.pointerPress = newPressed; currentPressed = newPressed; Select(currentPressed); _buttonUsed = true; } if (mode == Mode.Pointer) { if (useLookDrag) { bool useLookTest = true; if (!useLookDragSlider && currentPressed.GetComponent <Slider>()) { useLookTest = false; } else if (!useLookDragScrollbar && currentPressed.GetComponent <Scrollbar>()) { useLookTest = false; // the following is for scrollbars to work right // apparently they go into an odd drag mode when pointerDownHandler is called // a begin/end drag fixes that if (ExecuteEvents.Execute(currentPressed, lookData, ExecuteEvents.beginDragHandler)) { ExecuteEvents.Execute(currentPressed, lookData, ExecuteEvents.endDragHandler); } } if (useLookTest) { if (ExecuteEvents.Execute(currentPressed, lookData, ExecuteEvents.beginDragHandler)) { lookData.pointerDrag = currentPressed; currentDragging = currentPressed; } } } else { // the following is for scrollbars to work right // apparently they go into an odd drag mode when pointerDownHandler is called // a begin/end drag fixes that if (ExecuteEvents.Execute(currentPressed, lookData, ExecuteEvents.beginDragHandler)) { ExecuteEvents.Execute(currentPressed, lookData, ExecuteEvents.endDragHandler); } } } } } } // have to handle button up even if looking away if (Input.GetButtonUp(submitButtonName)) { if (currentDragging) { ExecuteEvents.Execute(currentDragging, lookData, ExecuteEvents.endDragHandler); if (currentLook != null) { ExecuteEvents.ExecuteHierarchy(currentLook, lookData, ExecuteEvents.dropHandler); } lookData.pointerDrag = null; currentDragging = null; } if (currentPressed) { ExecuteEvents.Execute(currentPressed, lookData, ExecuteEvents.pointerUpHandler); lookData.rawPointerPress = null; lookData.pointerPress = null; currentPressed = null; } } // drag handling if (currentDragging != null) { ExecuteEvents.Execute(currentDragging, lookData, ExecuteEvents.dragHandler); } if (!ignoreInputsWhenLookAway || ignoreInputsWhenLookAway && currentLook != null) { // control axis handling _controlAxisUsed = false; if (eventSystem.currentSelectedGameObject && controlAxisName != null && controlAxisName != "") { float newVal = Input.GetAxis(controlAxisName); if (newVal > 0.01f || newVal < -0.01f) { if (useSmoothAxis) { Slider sl = eventSystem.currentSelectedGameObject.GetComponent <Slider>(); if (sl != null) { float mult = sl.maxValue - sl.minValue; sl.value += newVal * smoothAxisMultiplier * mult; _controlAxisUsed = true; } else { Scrollbar sb = eventSystem.currentSelectedGameObject.GetComponent <Scrollbar>(); if (sb != null) { sb.value += newVal * smoothAxisMultiplier; _controlAxisUsed = true; } } } else { _controlAxisUsed = true; float time = Time.unscaledTime; if (time > nextAxisActionTime) { nextAxisActionTime = time + 1f / steppedAxisStepsPerSecond; AxisEventData axisData = GetAxisEventData(newVal, 0.0f, 0.0f); if (!ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, axisData, ExecuteEvents.moveHandler)) { _controlAxisUsed = false; } } } } } } }
public virtual void ProcessPressed(object sender, PointerEventArgs pointerEventArgs) { uiSampler.Begin(); var pointers = pointerEventArgs.Pointers; var count = pointers.Count; for (var i = 0; i < count; i++) { var pointer = pointers[i]; var over = pointer.GetOverData(); // Don't update the pointer if it is not over an UI element if (over.Type != HitData.HitType.UI) { continue; } PointerEventData data; GetPointerData(pointer.Id, out data, true); var target = over.Target; var currentOverGo = target == null ? null : target.gameObject; data.eligibleForClick = true; data.delta = Vector2.zero; data.dragging = false; data.useDragThreshold = true; data.pressPosition = pointer.Position; data.pointerPressRaycast = data.pointerCurrentRaycast; DeselectIfSelectionChanged(currentOverGo, data); if (data.pointerEnter != currentOverGo) { // send a pointer enter to the touched element if it isn't the one to select... input.HandlePointerExitAndEnter(data, currentOverGo); data.pointerEnter = currentOverGo; } // search for the control that will receive the press // if we can't find a press handler set the press // handler to be what would receive a click. var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, data, ExecuteEvents.pointerDownHandler); // didnt find a press handler... search for a click handler if (newPressed == null) { newPressed = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo); } // Debug.Log("Pressed: " + newPressed); float time = Time.unscaledTime; if (newPressed == data.lastPress) // ? { var diffTime = time - data.clickTime; if (diffTime < 0.3f) { ++data.clickCount; } else { data.clickCount = 1; } data.clickTime = time; } else { data.clickCount = 1; } data.pointerPress = newPressed; data.rawPointerPress = currentOverGo; data.clickTime = time; // Save the drag handler as well data.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(currentOverGo); if (data.pointerDrag != null) { ExecuteEvents.Execute(data.pointerDrag, data, ExecuteEvents.initializePotentialDrag); } } uiSampler.End(); }
/// <summary> /// Process the current mouse press. /// </summary> protected void ProcessMousePress(MouseButtonEventData data) { var pointerEvent = data.buttonData; var currentOverGo = pointerEvent.pointerCurrentRaycast.gameObject; // PointerDown notification if (data.PressedThisFrame()) { pointerEvent.eligibleForClick = true; pointerEvent.delta = Vector2.zero; pointerEvent.dragging = false; pointerEvent.useDragThreshold = true; pointerEvent.pressPosition = pointerEvent.position; pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast; DeselectIfSelectionChanged(currentOverGo, pointerEvent); // search for the control that will receive the press // if we can't find a press handler set the press // handler to be what would receive a click. var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.pointerDownHandler); // didnt find a press handler... search for a click handler if (newPressed == null) { newPressed = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo); } // Debug.Log("Pressed: " + newPressed); float time = Time.unscaledTime; if (newPressed == pointerEvent.lastPress) { var diffTime = time - pointerEvent.clickTime; if (diffTime < 0.3f) { ++pointerEvent.clickCount; } else { pointerEvent.clickCount = 1; } pointerEvent.clickTime = time; } else { pointerEvent.clickCount = 1; } pointerEvent.pointerPress = newPressed; pointerEvent.rawPointerPress = currentOverGo; pointerEvent.clickTime = time; // Save the drag handler as well pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(currentOverGo); if (pointerEvent.pointerDrag != null) { ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag); } } // PointerUp notification if (data.ReleasedThisFrame()) { // Debug.Log("Executing pressup on: " + pointer.pointerPress); ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler); // Debug.Log("KeyCode: " + pointer.eventData.keyCode); // see if we mouse up on the same element that we clicked on... var pointerUpHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo); // PointerClick and Drop events if (pointerEvent.pointerPress == pointerUpHandler && pointerEvent.eligibleForClick) { ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler); } else if (pointerEvent.pointerDrag != null && pointerEvent.dragging) { ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.dropHandler); } pointerEvent.eligibleForClick = false; pointerEvent.pointerPress = null; pointerEvent.rawPointerPress = null; if (pointerEvent.pointerDrag != null && pointerEvent.dragging) { ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler); } pointerEvent.dragging = false; pointerEvent.pointerDrag = null; // redo pointer enter / exit to refresh state // so that if we moused over somethign that ignored it before // due to having pressed on something else // it now gets it. if (currentOverGo != pointerEvent.pointerEnter) { HandlePointerExitAndEnter(pointerEvent, null); HandlePointerExitAndEnter(pointerEvent, currentOverGo); } } }
public void HandleEvent <T>(BaseEventData eventData, ExecuteEvents.EventFunction <T> eventHandler) where T : IEventSystemHandler { if (!Instance.enabled || disabledRefCount > 0) { return; } Debug.Assert(!eventData.used); // Use focused object when OverrideFocusedObject is null. GameObject focusedObject = (OverrideFocusedObject == null) ? FocusManager.Instance.TryGetFocusedObject(eventData) : OverrideFocusedObject; // Send the event to global listeners for (int i = 0; i < globalListeners.Count; i++) { // Global listeners should only get events on themselves, as opposed to their hierarchy. ExecuteEvents.Execute(globalListeners[i], eventData, eventHandler); } if (eventData.used) { // All global listeners get a chance to see the event, but if any of them marked it used, we stop // the event from going any further. return; } // TODO: robertes: consider whether modal and fallback input should flow to each handler until used // or it should flow to just the topmost handler on the stack as it does today. // Handle modal input if one exists if (modalInputStack.Count > 0) { GameObject modalInput = modalInputStack.Peek(); // If there is a focused object in the hierarchy of the modal handler, start the event // bubble there if (focusedObject != null && modalInput != null && focusedObject.transform.IsChildOf(modalInput.transform)) { if (ExecuteEvents.ExecuteHierarchy(focusedObject, eventData, eventHandler) && eventData.used) { return; } } // Otherwise, just invoke the event on the modal handler itself else { if (ExecuteEvents.ExecuteHierarchy(modalInput, eventData, eventHandler) && eventData.used) { return; } } } // If event was not handled by modal, pass it on to the current focused object if (focusedObject != null) { if (ExecuteEvents.ExecuteHierarchy(focusedObject, eventData, eventHandler) && eventData.used) { return; } } // If event was not handled by the focused object, pass it on to any fallback handlers if (fallbackInputStack.Count > 0) { GameObject fallbackInput = fallbackInputStack.Peek(); if (ExecuteEvents.ExecuteHierarchy(fallbackInput, eventData, eventHandler) && eventData.used) { return; } } }
public override void Process() { GetPointerData(kMouseLeftId, out var leftData, true); leftData.Reset(); //NOTE(Simon): There could be more than 1 inputdevice (VR controllers for example), so store them all in a list directions.Clear(); if (XRGeneralSettings.Instance.Manager.activeLoader != null) { if (!VRDevices.hasNoControllers) { if (VRDevices.hasRightController) { directions.Add(rightControllerId, rightController.GetComponent <Controller>().CastRay().direction); } if (VRDevices.hasLeftController) { directions.Add(leftControllerId, leftController.GetComponent <Controller>().CastRay().direction); } } } if (Input.mousePresent) { directions.Add(kMouseLeftId, camera.ScreenPointToRay((Vector2)Input.mousePosition).direction); } positions.Clear(); float positionOffsetPx = offset / 360 * uiTexture.width; foreach (var direction in directions) { positions.Add(direction.Key, new Vector2 { x = (uiTexture.width * (0.5f - Mathf.Atan2(direction.Value.z, direction.Value.x) / (2f * Mathf.PI)) - positionOffsetPx) % uiTexture.width, y = uiTexture.height * (Mathf.Asin(direction.Value.y) / Mathf.PI + 0.5f) }); } raycastResults.Clear(); positionResults.Clear(); foreach (var position in positions) { var tempData = new PointerEventData(eventSystem); tempData.Reset(); tempData.position = position.Value; eventSystem.RaycastAll(tempData, m_RaycastResultCache); var result = FindFirstRaycast(m_RaycastResultCache); if (result.isValid) { raycastResults.Add(position.Key, result); positionResults.Add(position.Key, position.Value); } m_RaycastResultCache.Clear(); } pointers.Clear(); foreach (var kvp in raycastResults) { GetPointerData(kvp.Key, out var prevData, true); pointers.Add(kvp.Key, new PointerEventData(eventSystem) { delta = positionResults[kvp.Key] - prevData.position, position = positionResults[kvp.Key], scrollDelta = Input.mouseScrollDelta, button = PointerEventData.InputButton.Left, pointerCurrentRaycast = raycastResults[kvp.Key], pointerId = kvp.Key, }); } //TODO(Simon): Add hover clickstate determination clickStates.Clear(); clickStates.Add(leftControllerId, StateForControllerTrigger(leftController)); clickStates.Add(rightControllerId, StateForControllerTrigger(rightController)); clickStates.Add(kMouseLeftId, StateForMouseButton(0)); foreach (var kvp in pointers) { if (!previousHovers.ContainsKey(kvp.Key)) { previousHovers.Add(kvp.Key, null); } if (kvp.Value.pointerCurrentRaycast.gameObject != previousHovers[kvp.Key]) { ExecuteEvents.ExecuteHierarchy(kvp.Value.pointerCurrentRaycast.gameObject, kvp.Value, ExecuteEvents.pointerEnterHandler); //NOTE(Simon): Check if any other pointers are hovering the object that's just been unhovered. var otherHovers = false; foreach (var currentHover in pointers) { if (currentHover.Value.pointerCurrentRaycast.gameObject == previousHovers[kvp.Key]) { otherHovers = true; } } //NOTE(Simon): If no other hovers, send PointerExit Event. if (!otherHovers) { ExecuteEvents.ExecuteHierarchy(previousHovers[kvp.Key], kvp.Value, ExecuteEvents.pointerExitHandler); } previousHovers[kvp.Key] = kvp.Value.pointerCurrentRaycast.gameObject; } if (clickStates[kvp.Key] == PointerEventData.FramePressState.Pressed) { ExecuteEvents.ExecuteHierarchy(kvp.Value.pointerCurrentRaycast.gameObject, kvp.Value, ExecuteEvents.pointerDownHandler); ExecuteEvents.ExecuteHierarchy(kvp.Value.pointerCurrentRaycast.gameObject, kvp.Value, ExecuteEvents.initializePotentialDrag); #if DEBUG_UI_INPUT_MODULE Debug.Log("Pointer down by " + kvp.Key + " on " + kvp.Value.pointerCurrentRaycast.gameObject + " in frame " + Time.frameCount); #endif } if (clickStates[kvp.Key] == PointerEventData.FramePressState.Released || clickStates[kvp.Key] == PointerEventData.FramePressState.PressedAndReleased) { ExecuteEvents.ExecuteHierarchy(kvp.Value.pointerCurrentRaycast.gameObject, kvp.Value, ExecuteEvents.pointerClickHandler); ExecuteEvents.ExecuteHierarchy(kvp.Value.pointerCurrentRaycast.gameObject, kvp.Value, ExecuteEvents.pointerUpHandler); #if DEBUG_UI_INPUT_MODULE Debug.Log("Click by " + kvp.Key + " on " + kvp.Value.pointerCurrentRaycast.gameObject + " in frame " + Time.frameCount); #endif } } }
private void PerformRaycast() { // Generate a new ray at our input object facing forward var ray = new Ray(transform.position, transform.forward); // Check if there is a 3d object between us and the canvas. var distance = float.PositiveInfinity; RaycastHit rayHit; if (Physics.Raycast(ray, out rayHit, distance, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore)) { distance = rayHit.distance; } RaycastResult raycastResult = new RaycastResult(); foreach (var canvas in XRUICanvas.Canvases) { // Raycast against the canvas var canvasTransform = canvas.GetComponent <RectTransform>(); var graphicRaycaster = canvas.GetComponent <GraphicRaycaster>(); if (RayIntersectsRectTransform(canvasTransform, ray, ref distance)) { // Now use the Graphic Raycaster to perform a raycast into the canvas to get the actual control. // The GraphicRaycaster expects the position to be in screenspace, of a particular event camera. var screenPoint = graphicRaycaster.eventCamera.WorldToScreenPoint(ray.GetPoint(distance)); eventData.position = screenPoint; raycastResults.Clear(); graphicRaycaster.Raycast(eventData, raycastResults); if (raycastResults.Count > 0) { raycastResult = raycastResults[0]; } } } if (!raycastResult.isValid) { LookAway(); onRaycastMiss.Invoke(); return; } onRaycastHit.Invoke(raycastResult.worldPosition, raycastResult.worldNormal); //If we are looking at the same object that we were looking at, we don't need to do anything and can exit if (eventData.pointerEnter == raycastResult.gameObject) { return; } //Otherwise we are looking at something new and should look away from the old object LookAway(); //Record this data and tell the object that we are pointing at them (OnPointerEnter) eventData.pointerEnter = raycastResult.gameObject; eventData.pointerCurrentRaycast = raycastResult; ExecuteEvents.ExecuteHierarchy(eventData.pointerEnter, eventData, ExecuteEvents.pointerEnterHandler); }
private void ProcessInteraction(PointerEventData pointer, bool pressed, bool released) { var currentOverGo = pointer.pointerCurrentRaycast.gameObject; objectUnderAimer = ExecuteEvents.GetEventHandler <ISubmitHandler>(currentOverGo);//we only want objects that we can submit on. if (pressed) { pointer.eligibleForClick = true; pointer.delta = Vector2.zero; pointer.pressPosition = pointer.position; pointer.pointerPressRaycast = pointer.pointerCurrentRaycast; // search for the control that will receive the press // if we can't find a press handler set the press // handler to be what would receive a click. var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointer, ExecuteEvents.submitHandler); // didnt find a press handler... search for a click handler if (newPressed == null) { newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointer, ExecuteEvents.pointerDownHandler); if (newPressed == null) { newPressed = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo); } } else { pointer.eligibleForClick = false; } if (newPressed != pointer.pointerPress) { pointer.pointerPress = newPressed; pointer.rawPointerPress = currentOverGo; pointer.clickCount = 0; } // Save the drag handler as well pointer.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(currentOverGo); if (pointer.pointerDrag != null) { ExecuteEvents.Execute <IBeginDragHandler>(pointer.pointerDrag, pointer, ExecuteEvents.beginDragHandler); } } if (released) { //Debug.Log("Executing pressup on: " + pointer.pointerPress); ExecuteEvents.Execute(pointer.pointerPress, pointer, ExecuteEvents.pointerUpHandler); //Debug.Log("KeyCode: " + pointer.eventData.keyCode); // see if we mouse up on the same element that we clicked on... var pointerUpHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo); // PointerClick if (pointer.pointerPress == pointerUpHandler && pointer.eligibleForClick) { float time = Time.unscaledTime; if (time - pointer.clickTime < 0.3f) { ++pointer.clickCount; } else { pointer.clickCount = 1; } pointer.clickTime = time; ExecuteEvents.Execute(pointer.pointerPress, pointer, ExecuteEvents.pointerClickHandler); } else if (pointer.pointerDrag != null) { ExecuteEvents.ExecuteHierarchy(currentOverGo, pointer, ExecuteEvents.dropHandler); } pointer.eligibleForClick = false; pointer.pointerPress = null; pointer.rawPointerPress = null; if (pointer.pointerDrag != null) { ExecuteEvents.Execute(pointer.pointerDrag, pointer, ExecuteEvents.endDragHandler); } pointer.pointerDrag = null; } }