Author Topic: UIDragObject - setting target at runtime misbehaves  (Read 2286 times)

Gregzo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 64
    • View Profile
UIDragObject - setting target at runtime misbehaves
« on: May 20, 2013, 04:29:54 AM »
Hi,

It seems that setting UIDragObject's target at runtime doesn't work properly. Strangely, if it is never allowed to be null, and never disabled/enabled, everything's fine.
In the following example, I'm trying to start dragging a transform after a long press on another. The hacky workaround I'm using involves setting up a decoy transform, hmm...
Surely I'm missing something? Setting the target in OnPress(true) works fine too, problems arise when press and setting the target are seperate.

Many thanks for your help,

Gregzo

  1. public Transform targetTransform; // not the receiving collider's transform
  2. public Transform decoyTransform; // assign an empty go in the inspector
  3.  
  4. UIDragObject uiDragObject;
  5.  
  6. void Awake ()
  7. {
  8.       uiDragObject = gameObject.AddComponent ( typeof ( UIDragObject ) ) as UIDragObject;
  9.       //uiDragObject.target = decoyTransform; //Uncomment this line, and it works fine.
  10. }
  11.  
  12. void OnLongPress () // custom long press
  13. {
  14.      uiDragObject.target = targetTransform;
  15. }
  16.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragObject - setting target at runtime misbehaves
« Reply #1 on: May 20, 2013, 09:18:08 AM »
The script is designed to work with 'target' set to something before OnPress() is called. If there is no OnPress() event, then there will be no dragging.

Gregzo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 64
    • View Profile
Re: UIDragObject - setting target at runtime misbehaves
« Reply #2 on: May 21, 2013, 05:47:23 AM »
So it's just a fluke that my workaround works?

It is quite handy to start a press on one collider, and to have the drag affecting another.

In my use case, long press on an icon instantiates a hollow version of it which I then drag around...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragObject - setting target at runtime misbehaves
« Reply #3 on: May 21, 2013, 01:11:35 PM »
You can always trigger your own OnPress() event, whether by directly calling the function, doing a SendMessage, or other means. But bottom line is, the target must be set before OnPress(true).