Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: Kevron on June 18, 2013, 04:34:01 AM
-
Hi, I am working with an inventory system a bit like the one in the latest Sam & Max. You pick up the items, and you can drag them onto in your world to create interaction.
I have followed the drag and drop example, so I reckon I have all the scripts needed for it to work. And it does seem to work, but sometimes, "the dragged inventory item" does not come back to the former parent after being un-parented on drag.
I have attached two images that hopefully explains my situation. I have also build a web player version of the current scene, you can fin it here: https://www.dropbox.com/s/z89e2biw1794vqm/Playmaker_Ngui_ArrayMaker.zip
I also notice that "Drag drop surface script" is "working" by just pressing down the mouse button outside the cube, drag the cursor over the cube and release. So, no actual need for grabbing the inventory item to create an interaction. Is there a way to make sure that only the inventory item can "invoke" the "drag drop surface script"
I am no programmer, so I find it a bit hard to describe what is happening. But I am looking for a stable drag and drop solution, and that only inventory items can affect the cubes.
Thanks,
Tor Martin
-
While I understand what you are trying to do, I don't understand how you are going about to accomplishing it. Drag & drop example works by allowing DragDropItem script to be picked up and dropped on a collider that has DragDropSurface on it. Attempting to drop it on anything without DragDropSurface returns the item to its original location.
Both of these scripts are in the Examples folder, so they are meant to be modified to suit your particular needs. For example, DragDropSurface has code inside that instantiates an object in 3D space, and DragDropItem expects there to be a table to work with.
That said, the Drag & Drop example is just that -- an example showing you how to make use of the OnDrag and OnDrop events provided by NGUI. It's not a "the" way to do it. It's just "a" way.
-
Hi and thanks for your answer.
I don't understand how you are going about to accomplishing it
I thought I was copying your drag & drop example. I reckon I tried to understand that example before going in and modify the scripts. I thought I had attached all the scripts in the correct "places". I have a UITable script, A DragDropContainer, A DragDropRoot, A DragDropItem and a DragDrop Surface. But in my build, things just did not run as smooth as I hoped for. And I wanted to ask if you could see something obvious was wrong with the setup.
But I got rid of all scripts, and did it with Playmaker. Your UICamera sends events that playmaker picks up, and that works great.
Could you help me understand how to make sure that the "grabbed" sprite follows the mouse cursor when moving around screen? My scaling style is set to Fixedsize and manual height is 800.
What is the math behind making sure the sprite "sticks" to the cursor. Now the sprite has a growing offset when moving the mouse. I have seen others asking for the same thing, but I am stupid.
Cheers,
Tor M
-
Found this post: Multiply it by UIRoot.screenSize / Screen.height.
After some thinking, I found it out. Wow, what a feeling :)
Here is how I solved it with Playmaker (see attached images)
Cheers!