Ejemplo n.º 1
0
		// Copied from StandaloneInputModule where these are marked private instead of protected in Unity 5.3 / 5.4
		#region Unity 5.3 / 5.4 compatibility.

#if UNITY_5_3 || UNITY_5_4
		void ProcessTouchPress( PointerEventData pointerEvent, bool pressed, bool released )
		{
			var go = 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;
				DeselectIfSelectionChanged( go, pointerEvent );
				if (pointerEvent.pointerEnter != go)
				{
					HandlePointerExitAndEnter( pointerEvent, go );
					pointerEvent.pointerEnter = go;
				}
				var go2 = ExecuteEvents.ExecuteHierarchy( go, pointerEvent, ExecuteEvents.pointerDownHandler );
				if (go2 == null)
				{
					go2 = ExecuteEvents.GetEventHandler<IPointerClickHandler>( go );
				}
				float unscaledTime = Time.unscaledTime;
				if (go2 == 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 = go2;
				pointerEvent.rawPointerPress = go;
				pointerEvent.clickTime = unscaledTime;
				pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler<IDragHandler>( go );
				if (pointerEvent.pointerDrag != null)
				{
					ExecuteEvents.Execute( pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag );
				}
			}
			if (released)
			{
				ExecuteEvents.Execute( pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler );
				var eventHandler = ExecuteEvents.GetEventHandler<IPointerClickHandler>( go );
				if (pointerEvent.pointerPress == eventHandler && pointerEvent.eligibleForClick)
				{
					ExecuteEvents.Execute( pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler );
				}
				else if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
				{
					ExecuteEvents.ExecuteHierarchy( go, 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;
				ExecuteEvents.ExecuteHierarchy( pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler );
				pointerEvent.pointerEnter = null;
			}
		}
            public virtual void ProcessUpdated(object sender, PointerEventArgs pointerEventArgs)
            {
#if UNITY_5_6_OR_NEWER
                uiSampler.Begin();
#endif

                var pointers = pointerEventArgs.Pointers;
                var raycast  = new RaycastResult();
                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 pressed not over an UI element
                    if ((pointer.Buttons & Pointer.PointerButtonState.AnyButtonPressed) > 0)
                    {
                        var press = pointer.GetPressData();
                        if (press.Type != HitData.HitType.UI)
                        {
                            continue;
                        }
                    }

                    PointerEventData data;
                    GetPointerData(pointer.Id, out data, true);

                    // If not over an UI element this and previous frame, don't process further.
                    // Need to check the previous hover state to properly process leaving a UI element.
                    if (over.Type != HitData.HitType.UI)
                    {
                        if (data.hovered.Count == 0)
                        {
                            continue;
                        }
                    }

                    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);
                    }
                }

#if UNITY_5_6_OR_NEWER
                uiSampler.End();
#endif
            }
            public virtual void ProcessReleased(object sender, PointerEventArgs pointerEventArgs)
            {
#if UNITY_5_6_OR_NEWER
                uiSampler.Begin();
#endif

                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);
                    }
                }

#if UNITY_5_6_OR_NEWER
                uiSampler.End();
#endif
            }
Ejemplo n.º 4
0
        private void HandleScroll()
        {
            bool    touchDown     = false;
            bool    touching      = false;
            Vector2 currentScroll = Vector2.zero;

            int cidx  = -1;
            int cidxa = -1;

            touchDown |= VRControllers.Instance.GetButtonDown(VRControllerButtons.Touch, out cidx);
            touching  |= VRControllers.Instance.GetButton(VRControllerButtons.Touch, out cidxa);
            if (cidx > -1)
            {
                currentScroll = VRControllers.Instance.GetTouchPos(cidx);
            }
            else if (cidxa > -1)
            {
                currentScroll = VRControllers.Instance.GetTouchPos(cidxa);
            }

            /*
             #if UNITY_HAS_GOOGLEVR && (UNITY_ANDROID || UNITY_EDITOR)
             * touchDown |= GvrController.TouchDown;
             * touching |= GvrController.IsTouching;
             * currentScroll = GvrController.TouchPos;
             #endif  // UNITY_HAS_GOOGLEVR && (UNITY_ANDROID || UNITY_EDITOR)
             */

            if (touchDown && !eligibleForScroll)
            {
                lastScroll        = currentScroll;
                eligibleForScroll = true;
            }
            else if (touching && eligibleForScroll)
            {
                //Debug.Log("currentScroll is " + currentScroll + " , lastScroll is " + lastScroll);
                pointerData.scrollDelta = (currentScroll - lastScroll) * SCROLL_DELTA_MULTIPLIER;

                GameObject currentGameObject = GetCurrentGameObject();
                if (currentGameObject != null && !Mathf.Approximately(pointerData.scrollDelta.sqrMagnitude, 0.0f))
                {
                    GameObject scrollHandler = ExecuteEvents.GetEventHandler <IScrollHandler>(currentGameObject);
                    ExecuteEvents.ExecuteHierarchy(scrollHandler, pointerData, ExecuteEvents.scrollHandler);
                }

                if (scrollEventData == null)
                {
                    scrollEventData = new ScrollEventData(eventSystem);
                }

                if (currentGameObject != null && Mathf.Abs((currentScroll - lastScroll).x) >= 1 && Mathf.Abs(currentScroll.x) > float.Epsilon)
                {
                    scrollEventData.Direction = (currentScroll - lastScroll).x >= 1 ? ScrollEventData.ScrollDirection.Right : ScrollEventData.ScrollDirection.Left;

                    GameObject scrollHandler = ExecuteEvents.GetEventHandler <IScrollToDirectHandler>(currentGameObject);
                    scrollEventData.selectedObject = scrollHandler;
                    ExecuteEvents.Execute(scrollHandler, scrollEventData, VRExecuteEvents.scrollToDirectHandler);
                }

                lastScroll = currentScroll;
            }
            else if (eligibleForScroll)
            {
                eligibleForScroll       = false;
                pointerData.scrollDelta = Vector2.zero;
            }
        }
Ejemplo n.º 5
0
 //Highlights this button. Unity's default button wasn't really meant to be controlled through code so event handlers are necessary here.
 //I would highly recommend not messing with this stuff unless you know what you're doing, if one event handler is wrong then the whole thing can break.
 public void highlightThisElement(PointerEventData p)
 {
     ExecuteEvents.Execute(button.gameObject, p, ExecuteEvents.selectHandler);
     active = true;
     setParentMenuLable(label);
 }
Ejemplo n.º 6
0
    void PressButton(int i)
    {
        var eventSystem = EventSystem.current;

        ExecuteEvents.Execute(_digitalButtons[i].gameObject, new BaseEventData(eventSystem), ExecuteEvents.submitHandler);
    }
Ejemplo n.º 7
0
    void GetButtonInput()
    {
        var pEventData = new PointerEventData(EventSystem.current);

        ExecuteEvents.Execute(activeButton.gameObject, pEventData, ExecuteEvents.submitHandler);
    }
Ejemplo n.º 8
0
            public void ProcessInput(ActionMapInput input, ConsumeControlDelegate consumeControl)
            {
                if (!(rayOrigin.gameObject.activeSelf || draggedObject) || !proxy.active)
                {
                    return;
                }

                var preProcessRaycastSource = m_Owner.preProcessRaycastSource;

                if (preProcessRaycastSource != null)
                {
                    preProcessRaycastSource(rayOrigin);
                }

                if (eventData == null)
                {
                    eventData = new RayEventData(m_Owner.eventSystem);
                }

                hoveredObject = m_Owner.GetRayIntersection(this); // Check all currently running raycasters

                eventData.node          = node;
                eventData.rayOrigin     = rayOrigin;
                eventData.pointerLength = m_Owner.GetPointerLength(eventData.rayOrigin);

                var uiActions = (UIActions)input;
                var select    = uiActions.select;

                if (isValid != null && !isValid(this))
                {
                    var currentRaycast = eventData.pointerCurrentRaycast;
                    currentRaycast.gameObject       = null;
                    eventData.pointerCurrentRaycast = currentRaycast;
                    hoveredObject = null;
                    m_Owner.HandlePointerExitAndEnter(eventData, null, true); // Send only exit events

                    if (select.wasJustReleased)
                    {
                        m_Owner.OnSelectReleased(this);
                    }

                    HideScrollFeedback();

                    return;
                }

                m_Owner.HandlePointerExitAndEnter(eventData, hoveredObject); // Send enter and exit events

                var hasScrollHandler = false;
                var hasInteractable  = hasObject && HoveringInteractable(eventData, currentObject, out hasScrollHandler);

                // Proceed only if pointer is interacting with something
                if (!hasInteractable)
                {
                    // If we have an object, the ray is blocked--input should not bleed through
                    if (hasObject && select.wasJustPressed)
                    {
                        consumeControl(select);
                    }

                    HideScrollFeedback();

                    if (select.wasJustReleased)
                    {
                        m_Owner.OnSelectReleased(this);
                    }

                    return;
                }

                // Send select pressed and released events
                if (select.wasJustPressed)
                {
                    m_Owner.OnSelectPressed(this);
                    consumeControl(select);
                }

                if (select.wasJustReleased)
                {
                    m_Owner.OnSelectReleased(this);
                }

                // Send Drag Events
                if (draggedObject != null)
                {
                    ExecuteEvents.Execute(draggedObject, eventData, ExecuteEvents.dragHandler);
                    ExecuteEvents.Execute(draggedObject, eventData, ExecuteRayEvents.dragHandler);
                }

                // Send scroll events
                if (currentObject && hasScrollHandler)
                {
                    var verticalScroll        = uiActions.verticalScroll;
                    var horizontalScroll      = uiActions.horizontalScroll;
                    var verticalScrollValue   = verticalScroll.value;
                    var horizontalScrollValue = horizontalScroll.value;
                    if (!Mathf.Approximately(verticalScrollValue, 0f) || !Mathf.Approximately(horizontalScrollValue, 0f))
                    {
                        consumeControl(verticalScroll);
                        consumeControl(horizontalScroll);
                        eventData.scrollDelta = new Vector2(horizontalScrollValue, verticalScrollValue);
                        ExecuteEvents.ExecuteHierarchy(currentObject, eventData, ExecuteEvents.scrollHandler);
                    }

                    if (m_ScrollFeedback.Count == 0)
                    {
                        ShowScrollFeedback();
                    }
                }
            }
Ejemplo n.º 9
0
    /// <summary>
    /// Calculate and process any mouse button state changes.
    /// </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);
            }

            m_InputPointerEvent = pointerEvent;
        }

        // PointerUp notification
        if (data.ReleasedThisFrame())
        {
            ReleaseMouse(pointerEvent, currentOverGo);
        }
    }
Ejemplo n.º 10
0
 public void UnHighlight(PointerEventData p)
 {
     ExecuteEvents.Execute(_button.gameObject, p, ExecuteEvents.deselectHandler);
     _active = false;
 }
Ejemplo n.º 11
0
        void HandlePointerExitAndEnter(RayEventData eventData, GameObject newEnterTarget, bool exitOnly = false)
        {
            // Cache properties before executing base method, so we can complete additional ray events later
            var cachedEventData = GetTempEventDataClone(eventData);

            // This will modify the event data (new target will be set)
            base.HandlePointerExitAndEnter(eventData, newEnterTarget);

            var pointerEnter = cachedEventData.pointerEnter;

            if (newEnterTarget == null || pointerEnter == null)
            {
                for (var i = 0; i < cachedEventData.hovered.Count; ++i)
                {
                    var hovered = cachedEventData.hovered[i];

                    ExecuteEvents.Execute(hovered, eventData, ExecuteRayEvents.rayExitHandler);
                    if (rayExited != null)
                    {
                        rayExited(hovered, eventData);
                    }
                }

                if (newEnterTarget == null)
                {
                    return;
                }
            }

            if (!exitOnly)
            {
                // if we have not changed hover target
                if (newEnterTarget && pointerEnter == newEnterTarget)
                {
                    var transform = newEnterTarget.transform;
                    while (transform != null)
                    {
                        ExecuteEvents.Execute(transform.gameObject, cachedEventData, ExecuteRayEvents.rayHoverHandler);
                        if (rayHovering != null)
                        {
                            rayHovering(transform.gameObject, cachedEventData);
                        }

                        transform = transform.parent;
                    }
                    return;
                }
            }

            var commonRoot = FindCommonRoot(pointerEnter, newEnterTarget);

            // and we already an entered object from last time
            if (pointerEnter != null)
            {
                // send exit handler call to all elements in the chain
                // until we reach the new target, or null!
                var transform = pointerEnter.transform;

                while (transform != null)
                {
                    // if we reach the common root break out!
                    if (commonRoot != null && commonRoot.transform == transform)
                    {
                        break;
                    }

                    ExecuteEvents.Execute(transform.gameObject, cachedEventData, ExecuteRayEvents.rayExitHandler);
                    if (rayExited != null)
                    {
                        rayExited(transform.gameObject, cachedEventData);
                    }

                    transform = transform.parent;
                }
            }

            if (!exitOnly)
            {
                // now issue the enter call up to but not including the common root
                cachedEventData.pointerEnter = newEnterTarget;
                var transform = newEnterTarget.transform;
                while (transform != null && transform.gameObject != commonRoot)
                {
                    ExecuteEvents.Execute(transform.gameObject, cachedEventData, ExecuteRayEvents.rayEnterHandler);
                    if (rayEntered != null)
                    {
                        rayEntered(transform.gameObject, cachedEventData);
                    }

                    transform = transform.parent;
                }
            }
        }
Ejemplo n.º 12
0
 public void Highlight(PointerEventData p)
 {
     ExecuteEvents.Execute(_button.gameObject, p, ExecuteEvents.selectHandler);
     _active = true;
     //SetParentMenuLable(_label);
 }
Ejemplo n.º 13
0
 public void OnEndDrag(PointerEventData eventData)
 {
     OnEndDragEvent?.Invoke(eventData);
     ExecuteEvents.Execute <IEndDragHandler>(ScrollGameObject, eventData, ExecuteEvents.endDragHandler);
 }
Ejemplo n.º 14
0
 public void ClickButtonFromOutside()
 {
     ExecuteEvents.Execute(button.gameObject, new BaseEventData(EventSystem.current), ExecuteEvents.submitHandler);
 }
Ejemplo n.º 15
0
 private void PressButton(Button button)
 {
     ExecuteEvents.Execute(button.gameObject, new BaseEventData(EventSystem.current), ExecuteEvents.submitHandler);
 }
Ejemplo n.º 16
0
    // 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)
                            {
                                ExecuteEvents.Execute(currentPressed, lookData, ExecuteEvents.beginDragHandler);
                                lookData.pointerDrag = currentPressed;
                                currentDragging      = currentPressed;
                            }
                        }
                        else if (currentPressed.GetComponent <Scrollbar>())
                        {
                            // 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;
                            }
                        }
                    }
                }
            }
        }
    }
 private void RouteEventToCurrentObject <T>(BaseEventData eventData, ExecuteEvents.EventFunction <T> eventFunction) where T : IEventSystemHandler
 {
     ExecuteEvents.Execute(gameObject, eventData, eventFunction);
 }
Ejemplo n.º 18
0
 private void ExecuteFocus()
 {
     ExecuteEvents.Execute(this.focusables[focus].gameObject, new BaseEventData(this.eventSystem), ExecuteEvents.submitHandler);
 }
Ejemplo n.º 19
0
 public static void EmitButtonClick(Button button)
 {
     ExecuteEvents.Execute(button.gameObject, new PointerEventData(EventSystem.current), ExecuteEvents.submitHandler);
 }
        public void ProcessInput(ActionMapInput input, Action <InputControl> consumeControl)
        {
            ExecuteUpdateOnSelectedObject();

            if (m_EventCamera == null)
            {
                return;
            }

            m_RaycastSourcesCopy.Clear();
            m_RaycastSourcesCopy.AddRange(m_RaycastSources.Values);             // The sources dictionary can change during iteration, so cache it before iterating

            //Process events for all different transforms in RayOrigins
            foreach (var source in m_RaycastSourcesCopy)
            {
                if (!(source.rayOrigin.gameObject.activeSelf || source.draggedObject) || !source.proxy.active)
                {
                    continue;
                }

                if (preProcessRaycastSource != null)
                {
                    preProcessRaycastSource(source.rayOrigin);
                }

                if (source.eventData == null)
                {
                    source.eventData = new RayEventData(base.eventSystem);
                }
                source.hoveredObject = GetRayIntersection(source);                 // Check all currently running raycasters

                var eventData = source.eventData;
                eventData.node          = source.node;
                eventData.rayOrigin     = source.rayOrigin;
                eventData.pointerLength = getPointerLength(eventData.rayOrigin);

                if (!source.isValid(source))
                {
                    continue;
                }

                HandlePointerExitAndEnter(eventData, source.hoveredObject);                 // Send enter and exit events

                var hasScrollHandler = false;
                source.actionMapInput.active = source.hasObject && ShouldActivateInput(eventData, source.currentObject, out hasScrollHandler);

                // Proceed only if pointer is interacting with something
                if (!source.actionMapInput.active)
                {
                    continue;
                }

                // Send select pressed and released events
                if (source.actionMapInput.select.wasJustPressed)
                {
                    OnSelectPressed(source);
                    consumeControl(source.actionMapInput.select);
                }

                if (source.actionMapInput.select.wasJustReleased)
                {
                    OnSelectReleased(source);
                }

                var draggedObject = source.draggedObject;

                // Send Drag Events
                if (source.draggedObject != null)
                {
                    ExecuteEvents.Execute(draggedObject, eventData, ExecuteEvents.dragHandler);
                    ExecuteEvents.Execute(draggedObject, eventData, ExecuteRayEvents.dragHandler);
                }

                // Send scroll events
                var scrollObject = source.hoveredObject;
                if (!scrollObject)
                {
                    scrollObject = source.draggedObject;
                }

                if (scrollObject && hasScrollHandler)
                {
                    var actionMapInput        = source.actionMapInput;
                    var verticalScroll        = actionMapInput.verticalScroll;
                    var horizontalScroll      = actionMapInput.horizontalScroll;
                    var verticalScrollValue   = verticalScroll.value;
                    var horizontalScrollValue = horizontalScroll.value;
                    if (!Mathf.Approximately(verticalScrollValue, 0f) || !Mathf.Approximately(horizontalScrollValue, 0f))
                    {
                        consumeControl(verticalScroll);
                        consumeControl(horizontalScroll);
                        eventData.scrollDelta = new Vector2(horizontalScrollValue, verticalScrollValue);
                        ExecuteEvents.ExecuteHierarchy(scrollObject, eventData, ExecuteEvents.scrollHandler);
                    }
                }
            }
        }
Ejemplo n.º 21
0
        private 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)
                {
                    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);
                }
            }
        }
        protected void HandlePointerExitAndEnter(RayEventData eventData, GameObject newEnterTarget)
        {
            // Cache properties before executing base method, so we can complete additional ray events later
            var cachedEventData = GetTempEventDataClone(eventData);

            // This will modify the event data (new target will be set)
            base.HandlePointerExitAndEnter(eventData, newEnterTarget);

            if (newEnterTarget == null || cachedEventData.pointerEnter == null)
            {
                for (var i = 0; i < cachedEventData.hovered.Count; ++i)
                {
                    ExecuteEvents.Execute(cachedEventData.hovered[i], eventData, ExecuteRayEvents.rayExitHandler);
                    rayExited(cachedEventData.hovered[i], eventData);
                }

                if (newEnterTarget == null)
                {
                    return;
                }
            }

            Transform t = null;

            // if we have not changed hover target
            if (cachedEventData.pointerEnter == newEnterTarget && newEnterTarget)
            {
                t = newEnterTarget.transform;
                while (t != null)
                {
                    ExecuteEvents.Execute(t.gameObject, cachedEventData, ExecuteRayEvents.rayHoverHandler);
                    t = t.parent;
                }
                return;
            }

            GameObject commonRoot = FindCommonRoot(cachedEventData.pointerEnter, newEnterTarget);

            // and we already an entered object from last time
            if (cachedEventData.pointerEnter != null)
            {
                // send exit handler call to all elements in the chain
                // until we reach the new target, or null!
                t = cachedEventData.pointerEnter.transform;

                while (t != null)
                {
                    // if we reach the common root break out!
                    if (commonRoot != null && commonRoot.transform == t)
                    {
                        break;
                    }

                    ExecuteEvents.Execute(t.gameObject, cachedEventData, ExecuteRayEvents.rayExitHandler);
                    rayExited(t.gameObject, cachedEventData);

                    t = t.parent;
                }
            }

            // now issue the enter call up to but not including the common root
            cachedEventData.pointerEnter = newEnterTarget;
            t = newEnterTarget.transform;
            while (t != null && t.gameObject != commonRoot)
            {
                ExecuteEvents.Execute(t.gameObject, cachedEventData, ExecuteRayEvents.rayEnterHandler);
                rayEntered(t.gameObject, cachedEventData);

                t = t.parent;
            }
        }
Ejemplo n.º 23
0
    // Update is called once per frame
    void Update()
    {
        //Raycast hitting landinggear lever
        Ray          ray = camera.ScreenPointToRay(Input.mousePosition);
        RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);

        if (hit)
        {
            if (hit.collider.name == "LandingGear")
            {
                canHold = true;
            }
        }


        //Moving the handle within boundaries
        if (Input.GetMouseButton(0) && canHold)
        {
            Vector3 pos = Input.mousePosition;

            if (canMoveY)
            {
                rectTransform.position = new Vector3(rectTransform.position.x, camera.ScreenToWorldPoint(pos).y + handleOffset, 79);
            }

            if (canMoveX)
            {
                rectTransform.position = new Vector3(camera.ScreenToWorldPoint(pos).x, rectTransform.position.y, 79);
            }

            if (canMoveX && canMoveY)
            {
                rectTransform.position = new Vector3(camera.ScreenToWorldPoint(pos).x, camera.ScreenToWorldPoint(pos).y + handleOffset, 79);
            }
        }
        else if (Input.GetMouseButtonUp(0) && canHold)
        {
            canHold = false;
        }


        if (Input.GetMouseButtonDown(1))
        {
            Debug.Log(rectTransform.position);
        }

        if (rectTransform.position.y <= 289)
        {
            Debug.Log("Can move x");
            canMoveX = true;
        }
        else
        {
            canMoveX = false;
        }

        //Checks if the landing gear lever is inside bounding box and blocks it from leaving
        if (rectTransform.position.x >= 1471)
        {
            canMoveY = false;
        }
        else
        {
            canMoveY = true;
        }

        if (rectTransform.position.x < 1435.6f)
        {
            rectTransform.position = new Vector3(1440.5f, rectTransform.position.y, 79);
        }
        else if (rectTransform.position.x > 1676.6f)
        {
            rectTransform.position = new Vector3(1660.5f, rectTransform.position.y, 79);
        }

        if (rectTransform.position.y > 601)
        {
            rectTransform.position = new Vector3(rectTransform.position.x, 590, 79);
        }
        else if (rectTransform.position.y < 271)
        {
            rectTransform.position = new Vector3(rectTransform.position.x, 281, 79);
        }


        if (rectTransform.position.x > 1646)
        {
            ExecuteEvents.Execute <ICustomMessage>(indicatorHandler, null, (x, y) => x.landingGear(1));
            ExecuteEvents.Execute <ICustomMessage>(cutSceneManager, null, (x, y) => x.landingGear(1));
        }
    }
Ejemplo n.º 24
0
        internal static DriverResponse HandleDriverRequest(DriverRequest request)
        {
            var response = new DriverResponse {
                method = request.method
            };
            var session = GetSession();

            switch (request.method.ToLowerInvariant())
            {
            case "registereditor":
                if (string.IsNullOrEmpty(session))
                {
                        #if UNITY_EDITOR
                    SaveSession(request.session);
                        #endif

                    response.session = request.session;
                }
                else
                {
                    response.session = session;
                }

                response.result = "unity";
                break;

            case "exist":
                response.result = MainThreadHelper.ExecuteGameObjectEmulation(request.upath,
                                                                              gameObject => true.ToString());
                break;

            case "active":
                response.result = MainThreadHelper.ExecuteGameObjectEmulation(request.upath,
                                                                              gameObject => gameObject.activeInHierarchy.ToString());
                break;

            case "onscreen":
                response.result = MainThreadHelper.ExecuteGameObjectEmulation(request.upath, gameObject => ScreenHelper.IsOnScreen(gameObject).ToString());
                break;

            case "graphicclickable":
                response.result = MainThreadHelper.ExecuteGameObjectEmulation(request.upath, gameObject => ScreenHelper.IsGraphicClickable(gameObject).ToString());
                break;

            case "physicclickable":
                response.result = MainThreadHelper.ExecuteGameObjectEmulation(request.upath, gameObject => ScreenHelper.IsPhysicClickable(gameObject).ToString());
                break;

            case "getcomponent":
                response.result = MainThreadHelper.ExecuteGameObjectEmulation(request.upath, gameObject =>
                {
                    var component = gameObject.GetComponent(request.value);
                    return(component != null ? JsonUtility.ToJson(component) : "null");
                });
                break;

            case "click":
                response.result = MainThreadHelper.ExecuteGameObjectEmulation(request.upath, gameObject =>
                {
                    var pointer = new PointerEventData(EventSystem.current);
                    ExecuteEvents.Execute(gameObject, pointer, ExecuteEvents.pointerClickHandler);
                    return(ErrorMessages.SuccessResult);
                });
                break;

            case "isrendering":
                response.result = MainThreadHelper.ExecuteGameObjectEmulation(request.upath,
                                                                              go =>
                {
                    var renderer = go.GetComponent <Renderer>();
                    if (renderer != null)
                    {
                        return(renderer.isVisible.ToString());
                    }

                    return(false.ToString());
                });
                break;

            case "count":
                response.result = MainThreadHelper.ExecuteGameObjectsEmulation(request.upath, goList => goList.Count.ToString());
                break;

            case "deleteplayerpref":
                response.result = MainThreadHelper.InvokeOnMainThreadAndWait(() =>
                {
                    PlayerPrefs.DeleteKey(request.key);
                    PlayerPrefs.Save();
                });
                break;

            case "deleteallprefs":
                response.result = MainThreadHelper.InvokeOnMainThreadAndWait(() =>
                {
                    PlayerPrefs.DeleteAll();
                    PlayerPrefs.Save();
                });
                break;

            case "getfloatplayerpref":
                response.result = MainThreadHelper.InvokeOnMainThreadAndWait(() => PlayerPrefs.GetFloat(request.key).ToString(CultureInfo.InvariantCulture));
                break;

            case "getintplayerpref":
                response.result = MainThreadHelper.InvokeOnMainThreadAndWait(() => PlayerPrefs.GetInt(request.key).ToString());
                break;

            case "getstringplayerpref":
                response.result = MainThreadHelper.InvokeOnMainThreadAndWait(() => PlayerPrefs.GetString(request.key));
                break;

            case "setfloatplayerpref":
                response.result = MainThreadHelper.InvokeOnMainThreadAndWait(() =>
                {
                    var result = ErrorMessages.SuccessResult;
                    try
                    {
                        PlayerPrefs.SetFloat(request.key, float.Parse(request.value));
                        PlayerPrefs.Save();
                    }
                    catch (Exception e)
                    {
                        result = e.ToString();
                    }
                    return(result);
                });
                break;

            case "setintplayerpref":
                response.result = MainThreadHelper.InvokeOnMainThreadAndWait(() =>
                {
                    var result = ErrorMessages.SuccessResult;
                    try
                    {
                        PlayerPrefs.SetInt(request.key, int.Parse(request.value));
                        PlayerPrefs.Save();
                    }
                    catch (Exception e)
                    {
                        result = e.ToString();
                    }
                    return(result);
                });
                break;

            case "setstringplayerpref":
                response.result = MainThreadHelper.InvokeOnMainThreadAndWait(() =>
                {
                    var result = ErrorMessages.SuccessResult;
                    try
                    {
                        PlayerPrefs.SetFloat(request.key, float.Parse(request.value));
                        PlayerPrefs.Save();
                    }
                    catch (Exception e)
                    {
                        result = e.ToString();
                    }
                    return(result);
                });
                break;

            case "playerprefhaskey":
                response.result = MainThreadHelper.InvokeOnMainThreadAndWait(() =>
                {
                    string result;
                    try
                    {
                        result = PlayerPrefs.HasKey(request.key).ToString();
                    }
                    catch (Exception e)
                    {
                        result = e.ToString();
                    }
                    return(result);
                });
                break;

            case "getcoordinates":
                response.result = MainThreadHelper.ExecuteGameObjectEmulation(request.upath, gameObject =>
                {
                    var position    = ScreenHelper.GetPositionOnScreen(gameObject, Camera.main);
                    var coordinates = new ScreenCoordinates {
                        X = position.x, Y = position.y
                    };
                    return(JsonUtility.ToJson(coordinates));
                });
                break;

            case "swipe":
                var swipeDirection = Vector2.zero;
                switch (request.value)
                {
                case "up":
                    swipeDirection = Vector2.up;
                    break;

                case "down":
                    swipeDirection = Vector2.down;
                    break;

                case "left":
                    swipeDirection = Vector2.left;
                    break;

                case "right":
                    swipeDirection = Vector2.right;
                    break;
                }

                swipeDirection *= 100;

                response.result = MainThreadHelper.ExecuteGameObjectEmulation(request.upath, gameObject => {
                    var pointer = new PointerEventData(EventSystem.current);
                    gameObject.GetComponent <MonoBehaviour>().StartCoroutine(DragCoroutine(gameObject, pointer, (Vector2)ScreenHelper.GetPositionOnScreen(gameObject, Camera.main) + swipeDirection * 2));

                    return(ErrorMessages.SuccessResult);
                });
                break;

            case "dragto":
                response.result = MainThreadHelper.ExecuteGameObjectEmulation(request.upath, gameObject => {
                    var screenCoordinates = new ScreenCoordinates();
                    JsonUtility.FromJsonOverwrite(request.value, screenCoordinates);
                    var pointer = new PointerEventData(EventSystem.current);
                    gameObject.GetComponent <MonoBehaviour>().StartCoroutine(DragCoroutine(gameObject, pointer,
                                                                                           new Vector2 {
                        x = screenCoordinates.X, y = screenCoordinates.Y
                    }));

                    return("OK");
                });
                break;


            case "sendkeys":
                response.result = MainThreadHelper.ExecuteGameObjectEmulation(request.upath, gameObject =>
                {
                    var input = gameObject.GetComponent <InputField>();
                    if (input != null)
                    {
                        input.text = request.value;
                    }
                    else
                    {
                        var tmpInput = gameObject.GetComponent <TMP_InputField>();
                        if (tmpInput != null)
                        {
                            tmpInput.text = request.value;
                        }
                        else
                        {
                            return("input not found");
                        }
                    }

                    return(ErrorMessages.SuccessResult);
                });
                break;

            case "startplaymode":
#if UNITY_EDITOR
                EditorApplication.update += StartPlayMode;
                response.result           = ErrorMessages.SuccessResult;
#else
                response.result = ErrorMessages.MethodIsNotSupported;
#endif
                break;

            case "stopplaymode":
#if UNITY_EDITOR
                response.result = MainThreadHelper.InvokeOnMainThreadAndWait(() =>
                {
                    //EditorApplication.UnlockReloadAssemblies();
                    EditorApplication.isPlaying = false;
                });
#else
                response.result = ErrorMessages.MethodIsNotSupported;
#endif
                break;

            case "ping":
                response.result = "pong";
                break;

            case "takescreenshot":
                var path = request.value;
                response.result = MainThreadHelper.InvokeOnMainThreadAndWait(() => { TakeScreenshot(path); });
                break;

            case "isplaymode":
                response.result = MainThreadHelper.InvokeOnMainThreadAndWait(() => Application.isPlaying.ToString());
                break;

            case "custom":
                response.result = CustomDriverHandler.Process(request.key, request.value);
                break;

            default:
                response.result = "Unknown method " + request.method + ".";
                break;
            }

            return(response);
        }
Ejemplo n.º 25
0
 //默认点击
 public void AutoClick()
 {
     ExecuteEvents.Execute <IPointerClickHandler>(nBt.gameObject, new PointerEventData(EventSystem.current), ExecuteEvents.pointerClickHandler);
     ExecuteEvents.Execute <ISubmitHandler>(nBt.gameObject, new PointerEventData(EventSystem.current), ExecuteEvents.submitHandler);
 }
Ejemplo n.º 26
0
        // reimplementation of VRInputModule's HandlePointerExitAndEnter
        // only functional change should be that we target the off-hand controller for haptics
        private void HandlePointerExitAndEnter(VRInputModule vrInputModule, PointerEventData eventData, GameObject newEnterTarget)
        {
            if (newEnterTarget == null || eventData.pointerEnter == null)
            {
                foreach (var hovered in eventData.hovered)
                {
                    ExecuteEvents.Execute(hovered, eventData, ExecuteEvents.pointerExitHandler);
                }
                eventData.hovered.Clear();

                if (newEnterTarget == null)
                {
                    eventData.pointerEnter = null;
                    return;
                }
            }

            // at this point, newEnterTarget cannot be null
            if (eventData.pointerEnter == newEnterTarget)
            {
                return;
            }

            GameObject commonRoot = null;
            Transform  t          = null;

            if (eventData.pointerEnter != null)
            {
                // reimplementation of BaseInputModule.FindCommonRoot
                Transform t1    = eventData.pointerEnter.transform;
                bool      found = false;
                while (t1 != null)
                {
                    Transform t2 = newEnterTarget.transform;
                    while (t2 != null)
                    {
                        if (t1 == t2)
                        {
                            commonRoot = t1.gameObject;
                            found      = true;
                            break;
                        }

                        t2 = t2.parent;
                    }

                    if (found)
                    {
                        break;
                    }
                    else
                    {
                        t1 = t1.parent;
                    }
                }

                t = eventData.pointerEnter.transform;
                while (t != null && commonRoot?.transform != t)
                {
                    ExecuteEvents.Execute(t.gameObject, eventData, ExecuteEvents.pointerExitHandler);
                    eventData.hovered.Remove(t.gameObject);
                    t = t.parent;
                }
            }

            if (!vrInputModule.userInteractionEnabled)
            {
                return;
            }

            bool hasTriggeredHapticPulse = false;

            eventData.pointerEnter = newEnterTarget;
            t = newEnterTarget.transform;

            while (t != null && t.gameObject != commonRoot)
            {
                _componentsList.Clear();
                t.gameObject.GetComponents(_componentsList);

                if (!hasTriggeredHapticPulse)
                {
                    foreach (var component in _componentsList)
                    {
                        Selectable   selectable   = component as Selectable;
                        Interactable interactable = component as Interactable;
                        if ((selectable != null && selectable.isActiveAndEnabled && selectable.interactable) ||
                            (interactable != null && interactable.isActiveAndEnabled && interactable.interactable))
                        {
                            VRPlatformHelperAccessor(ref vrInputModule).TriggerHapticPulse(_laserPointer.OffHandController.node, 0.25f);
                            hasTriggeredHapticPulse = true;
                            break;
                        }
                    }
                }

                ExecuteEvents.Execute(t.gameObject, eventData, ExecuteEvents.pointerEnterHandler);
                eventData.hovered.Add(t.gameObject);
                t = t.parent;
            }
        }
            public virtual void ProcessPressed(object sender, PointerEventArgs pointerEventArgs)
            {
#if UNITY_5_6_OR_NEWER
                uiSampler.Begin();
#endif

                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.position            = pointer.Position;
                    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);
                    }
                }

#if UNITY_5_6_OR_NEWER
                uiSampler.End();
#endif
            }
Ejemplo n.º 28
0
    protected 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 && 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;

            // 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;
        }
    }
Ejemplo n.º 29
0
    override public void releaseAnimation(GameObject button)
    {
        var pointer = new PointerEventData(EventSystem.current);

        ExecuteEvents.Execute(button, pointer, ExecuteEvents.pointerUpHandler);
    }
Ejemplo n.º 30
0
		void ProcessMousePress( PointerInputModule.MouseButtonEventData data )
		{
			var buttonData = data.buttonData;
			var gameObject = buttonData.pointerCurrentRaycast.gameObject;
			if (data.PressedThisFrame())
			{
				buttonData.eligibleForClick = true;
				buttonData.delta = Vector2.zero;
				buttonData.dragging = false;
				buttonData.useDragThreshold = true;
				buttonData.pressPosition = buttonData.position;
				buttonData.pointerPressRaycast = buttonData.pointerCurrentRaycast;
				DeselectIfSelectionChanged( gameObject, buttonData );
				var gameObject2 = ExecuteEvents.ExecuteHierarchy<IPointerDownHandler>( gameObject, buttonData, ExecuteEvents.pointerDownHandler );
				if (gameObject2 == null)
				{
					gameObject2 = ExecuteEvents.GetEventHandler<IPointerClickHandler>( gameObject );
				}
				var unscaledTime = Time.unscaledTime;
				if (gameObject2 == buttonData.lastPress)
				{
					var num = unscaledTime - buttonData.clickTime;
					if (num < 0.3f)
					{
						buttonData.clickCount++;
					}
					else
					{
						buttonData.clickCount = 1;
					}
					buttonData.clickTime = unscaledTime;
				}
				else
				{
					buttonData.clickCount = 1;
				}
				buttonData.pointerPress = gameObject2;
				buttonData.rawPointerPress = gameObject;
				buttonData.clickTime = unscaledTime;
				buttonData.pointerDrag = ExecuteEvents.GetEventHandler<IDragHandler>( gameObject );
				if (buttonData.pointerDrag != null)
				{
					ExecuteEvents.Execute<IInitializePotentialDragHandler>( buttonData.pointerDrag, buttonData, ExecuteEvents.initializePotentialDrag );
				}
			}
			if (data.ReleasedThisFrame())
			{
				ExecuteEvents.Execute<IPointerUpHandler>( buttonData.pointerPress, buttonData, ExecuteEvents.pointerUpHandler );
				var eventHandler = ExecuteEvents.GetEventHandler<IPointerClickHandler>( gameObject );
				if (buttonData.pointerPress == eventHandler && buttonData.eligibleForClick)
				{
					ExecuteEvents.Execute<IPointerClickHandler>( buttonData.pointerPress, buttonData, ExecuteEvents.pointerClickHandler );
				}
				else
				{
					if (buttonData.pointerDrag != null)
					{
						ExecuteEvents.ExecuteHierarchy<IDropHandler>( gameObject, buttonData, ExecuteEvents.dropHandler );
					}
				}
				buttonData.eligibleForClick = false;
				buttonData.pointerPress = null;
				buttonData.rawPointerPress = null;
				if (buttonData.pointerDrag != null && buttonData.dragging)
				{
					ExecuteEvents.Execute<IEndDragHandler>( buttonData.pointerDrag, buttonData, ExecuteEvents.endDragHandler );
				}
				buttonData.dragging = false;
				buttonData.pointerDrag = null;
				if (gameObject != buttonData.pointerEnter)
				{
					HandlePointerExitAndEnter( buttonData, null );
					HandlePointerExitAndEnter( buttonData, gameObject );
				}
			}
		}