Search Unity

Possible to offset pointer position - PointerEventData

Discussion in 'UGUI & TextMesh Pro' started by Hjeldnes, Apr 20, 2016.

  1. Hjeldnes

    Hjeldnes

    Joined:
    Jul 22, 2012
    Posts:
    116
    I have a drag and drop system on ios, and I drag icons onto slots. I have quite a lot of slots, and it is a bit hard to hit the right one because the finger covers the slot, and the icon.

    I can offset the position of the icon in OnDrag, but I will still get a pointerEnter event at the touch under the finger. The best would be if I could offset the icon a bit, and get a pointer enter event from the center of the icon.

    Are there any recommended solutions for this? The whole setup is currently based around input events, so it would really be best to keep that. Thanks!

    Kjetil
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @Hjeldnes

    Hi, there, I think it's possible.

    I can imagine two solutions, at least for the click offset / finding proper object.

    If you already have a OnPointerClick (or similar, drag or such) method, you can do additional raycast there, create new PointerEventData, where you offset location of click, from original click that you received from OnPointerClick, then perform another raycast using Eventsystem raycast all with this pointer event data. Then loop the hits and get your object.

    But for this to work you need to first hit "empty" as your offset is most likely above empty area if not above other icon, then you have to make "click catcher", add empty image or optimized graphic component to canvas for example, to be able to catch missed hit, then perform proper raycast on offset location.

    Or to avoid this, just do update with GetMouseButton, then call method that does the above.

    Not sure how this would be added to drag 'n' drop, don't remember how it all went since it's been months I've done anything similar.
     
  3. Hjeldnes

    Hjeldnes

    Joined:
    Jul 22, 2012
    Posts:
    116
    @eses ok, thanks. I discovered that it might be possible to override the physicsraycaster, so I was thinking I could add an offset to where the ray is cast from. I will have a look anyway. If not I could try your method, to add an additional raycast. I don't see why I would need an empty image to catch the ray? This is a 3d scene, so I check against 40 box colliders or so. They are placed in a grid, like a checkerboard. And quite small, thats why I would like to offset the ray, since the finger covers the entire slot when the player drags the icon onto it. I'm thinking as long as I can offset the raycast, then I would hit a slot above the finger, in all events.

    Thanks for the response! :)

    Kjetil