Design a drag and drop inventory with transition from icons to game objects

Hi,

I’m trying to write a simple 2d game where the user can drag and drop different objects on the screen.
Each of these objects is made from a Prefab i’ve created with a Drag and Drop component (which handles events like mouse_drag, mouse_down etc’).
There is an inventory on the side of the screen with scaled images from where the user can drag the different objects to the game screen (after that he can continue to drag these objects. Thats why Iv’e written the drag & drop functionality in the object’s class and not in the inventory’s class).
I’m having a little bit of trouble understanding how I should implement it:

The first thing i’ve tried was to show only icons for the different objects in the inventory and then, when they were clicked and dragged, attach the actual game object to the mouse. But that didn’t go so well because i couldn’t really understand how to set the game object in the correct place and then use its drag and drop component to drag it around.

The second thing i was planning to do was to put the actual prefabs (my game objects) in the inventory (maybe scaled down a bit) and then they can give their own drag and drop functionality…

I would really appreciate some guidelines or opinions about the design because I feel i’m doing things kinda wrong…
What do you think?

Thank you,
Moria.

Hey,
You propably want a base slot class, which holds basic slot information like the actual sprite, a text with the amount or a description etc… with a type enum.
Then you could inherit from that class with a version of dragable slots, for example like in a loot window, and another version of dropable slots which can only recieve one way or two way, depending on the using case or time. the base class can be serialized data or prefab, your inventory is basically an array of the base class. What you think? I’m myself working right now on an InventorySystem, so suggestions are welcome :wink:

P.S. perhaps this can help you for inpiration or code: http://forum.unity3d.com/threads/ui-example-project.263418/