Author Topic: drop into the same slot.  (Read 2351 times)

Slyfox

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
drop into the same slot.
« on: October 17, 2013, 06:39:33 AM »
In the inventory example, is it possible to change the code somehow so that it is possible to drag from a slot then drop back into the same slot?

Currently the slot that started the drag event doesn't receive a drop event at all.
« Last Edit: October 17, 2013, 04:35:14 PM by Slyfox »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: drop into the same slot.
« Reply #1 on: October 18, 2013, 06:38:27 PM »
You get OnPress(false) instead. Look into the drag & drop example.

Slyfox

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: drop into the same slot.
« Reply #2 on: October 18, 2013, 07:47:15 PM »
Thanks for the response.
But now there is a new problem.
With the OnPress(bool isDown) method, the event still launch whenever the mouse enter or exit a slot.
when exiting, the isDown value is false and when entering, isDown is true.
This behavior replace the items just by dragging.


Slyfox

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: drop into the same slot.
« Reply #3 on: October 18, 2013, 08:42:50 PM »
I got it working.
If anyone is interested this is how I fixed it :


  1. bool mIsDragging = false;
  2. GameObject lastHoveredGameObjectDuringDrag = null;
  3.  
  4. void OnDrag (Vector2 delta)
  5. {
  6.         mIsDragging = true;
  7. }
  8.  
  9.  
  10. void OnPress(bool isDown)
  11. {
  12.         if(mIsDragging)
  13.                 lastHoveredGameObjectDuringDrag = UICamera.hoveredObject;
  14.                
  15.         if (!isDown)
  16.         {      
  17.                        
  18.                 if (lastHoveredGameObjectDuringDrag == this.gameObject)
  19.                         mIsDragging = false;
  20.         }
  21.         if(!mIsDragging)
  22.         {
  23.                 //do code here...
  24.         }
  25. }
  26.  

I think the strange behavior of Onpress(bool isDown) is due to the stickyPress value being false, though I needed it to be false for something else.