Support => NGUI 3 Support => Topic started by: matis on February 19, 2014, 10:39:09 AM
Title: UIDragDropItem not under cursor
Post by: matis 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.
Title: Re: UIDragDropItem not under cursor
Post by: MrTact 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.
Title: Re: UIDragDropItem not under cursor
Post by: matis 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.
Title: Re: UIDragDropItem not under cursor
Post by: ArenMook 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.
Title: Re: UIDragDropItem not under cursor
Post by: matis 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
Title: Re: UIDragDropItem not under cursor
Post by: matis 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.
Title: Re: UIDragDropItem not under cursor
Post by: ArenMook 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:
Title: Re: UIDragDropItem not under cursor
Post by: matis 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?
Title: Re: UIDragDropItem not under cursor
Post by: blackant 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
Title: Re: UIDragDropItem not under cursor
Post by: matis on March 03, 2014, 11:45:32 AM
When I place UIStretch anywhere I have the issue also I tried put UIDragDropRoot script elsewhere but without any change.
Title: Re: UIDragDropItem not under cursor
Post by: ArenMook 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.
Title: Re: UIDragDropItem not under cursor
Post by: matis on March 04, 2014, 03:17:03 AM
because it is the only way I discovered for showing my content on any resolution.
Title: Re: UIDragDropItem not under cursor
Post by: ArenMook 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.
Title: Re: UIDragDropItem not under cursor
Post by: matis on March 04, 2014, 05:53:09 AM
Iam using UIRoot, but in some resolutions I have black background on the sides.
Title: Re: UIDragDropItem not under cursor
Post by: ArenMook 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.
Title: Re: UIDragDropItem not under cursor
Post by: matis on March 05, 2014, 07:20:42 AM
It is normal but not good in my case. It is not normal to switch to another resolution and let for examle table disapear because it is off-screen. Iam using UIStretch because it is not that bad when I switch from 16:9 to 16:10 at least whole my scene is there. Anchors are good for UI elements but not for game objects I need have them on exactly same place to cover my background.
Title: Re: UIDragDropItem not under cursor
Post by: ArenMook on March 05, 2014, 07:34:18 AM
To anchor game objects, use the old UIAnchor.
Skewing may not be that noticeable when going from 16:9 to 16:10, but when you go from 16:9 to 4:3 -- very much so. All your circles will become visibly squished. It's always very noticeable when games do that.
Skewing your entire UI will break your scroll views because NGUI was designed to work with a uniform scale.