Author Topic: UIDragDropItem not under cursor  (Read 19004 times)

matis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
UIDragDropItem not under cursor
« on: February 19, 2014, 10:39:09 AM »
Hi,
Iam working on point and click adventure game and now I want to be able drag item from inventory on item in world to do some actions. Inventory items have UIDragDropItem script on it but  item appear move slower then mouse cursor. Really dont know what is the problem. I hope you understand me. Can someone help me? Thanks a lot.

MrTact

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 32
    • View Profile
Re: UIDragDropItem not under cursor
« Reply #1 on: February 19, 2014, 11:29:22 AM »
I am doing something similar and I don't have this performance issue, so I don't think NGUI is the source of the problem. My money is on two possibilities: either you have a broader performance problem that is just showing up because of drag and drop, or the object you are trying to drag is REALLY complex.

To check for the first problem, I would learn how to use the Unity profiler pane.

To investigate the second, look for the panel that owns the dragged object -- this will be the first gameobject you encounter that is a direct parent of your dragged object that has a UIPanel component. Open up the draw calls window for that panel, then run your game. If you are getting a massive number of draw calls (e.g. in the hundreds), that's likely your problem.

matis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UIDragDropItem not under cursor
« Reply #2 on: February 19, 2014, 11:37:33 AM »
I dont know what to look at profiler but I have about 500fps and my whole scene have just a 9 draw calls.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragDropItem not under cursor
« Reply #3 on: February 19, 2014, 03:40:38 PM »
Unless you are using a hardware cursor, a software cursor will always move slower than your finger. Think about it -- the application gets input notifications infrequently -- roughly 20 times per frame -- so it doesn't matter if you have 20 or 500 fps, the effect will be the same.

matis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UIDragDropItem not under cursor
« Reply #4 on: February 19, 2014, 04:32:09 PM »
ok but your Drag and Drop example scene works ok but when I add this script to my object it is all wrong

matis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UIDragDropItem not under cursor
« Reply #5 on: February 20, 2014, 04:01:18 AM »
This looks like my problem http://www.tasharen.com/forum/index.php?topic=3622.0
but dont know where to put that code - dont know where in UIDragDropItem place it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragDropItem not under cursor
« Reply #6 on: February 20, 2014, 09:42:17 AM »
Drag and drop example works fine even if you change it to be fixed size.

UIDragDropItem takes root pixel size adjustment into account inside its OnDrag function:
  1.         void OnDrag (Vector2 delta)
  2.         {
  3.                 if (!enabled || mTouchID != UICamera.currentTouchID) return;
  4.                 OnDragDropMove((Vector3)delta * mRoot.pixelSizeAdjustment);
  5.         }

matis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UIDragDropItem not under cursor
« Reply #7 on: March 03, 2014, 07:07:16 AM »
so in my case is UIStretch the issue. When I have DragDropItem under UIStretch in hierarchy then my item is not follow cursor correctly. My question is - how can I scale my DragDropItem without this problem?
« Last Edit: March 03, 2014, 10:23:49 AM by matis »

blackant

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
    • blackant master
Re: UIDragDropItem not under cursor
« Reply #8 on: March 03, 2014, 11:22:34 AM »
it's a problem of scale.

to solve it you should put the drag and drop root on an object without size modification.
try different parent to put your script.

i get the same problem for my game, because the script was attached to an object i can resize using wheel.
i put it on the parent and now it's working nice

matis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UIDragDropItem not under cursor
« Reply #9 on: March 03, 2014, 11:45:32 AM »
this is my hierarchy:

Inventory (with UIDragDropRoot script)
-Inventory_grid (with UIGrid script)
--Item01 (with DragDropItem script)
--Item02 (with DragDropItem script)
--Item03 (with DragDropItem script)

When I place UIStretch anywhere I have the issue also I tried put UIDragDropRoot script elsewhere but without any change.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragDropItem not under cursor
« Reply #10 on: March 03, 2014, 10:59:18 PM »
Why are you using UIStretch? It should not be used anymore at all. It stretches the object, which messes with scaling, as blackant mentioned. Don't use it.

matis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UIDragDropItem not under cursor
« Reply #11 on: March 04, 2014, 03:17:03 AM »
because it is the only way I discovered for showing my content on any resolution.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragDropItem not under cursor
« Reply #12 on: March 04, 2014, 03:33:16 AM »
UIRoot is what scales the UI based on the resolution. Set it to "fixed size" and the UI will remain proportional to the height of the screen. UIStretch is the legacy widget stretching component.

matis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UIDragDropItem not under cursor
« Reply #13 on: March 04, 2014, 05:53:09 AM »
Iam using UIRoot, but in some resolutions I have black background on the sides.
« Last Edit: March 04, 2014, 06:10:00 AM by matis »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragDropItem not under cursor
« Reply #14 on: March 05, 2014, 06:00:44 AM »
If the aspect ratio changes, then you will be able to see more or less on the sides, that's perfectly normal.

Are you saying you're skewing your UI? That's ugly as hell. Why would you do that? You need to use anchors instead, making your UI modular. Some things get attached to sides of the screen -- minimap to top-right, chat to bottom-left, for example. Look into the first example that comes with NGUI -- Example 1.