Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Sleek Inventory - Complete GUI System for Inventories

Discussion in 'Assets and Asset Store' started by Grazer2, Apr 30, 2012.

  1. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    $screenshot1.png

    Sleek Inventory allows creating flexible and powerful inventory systems in Unity. Get it from the Asset Store. The system supports

    • Multiple pages with tabs
    • Dragging and dropping of items onto scene objects
    • Tooltips on items
    • Easy screen alignment
    • And more

    All code is written in C# and the system is provided as an encapsulated and independent plugin within the Unity project. Scripting experience is required as the content of an inventory needs to be added by help of code. The entire source code of the system is included and can be modified and expanded.

    Demo1 | Demo2 | Demo3

    $screenshot2.png

    Full help page | Code reference | Asset Store Link
    Help Page Backup
     
    Last edited: May 13, 2014
  2. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,626
    Very sleek indeed judging from the functionality and graphics. :)

    Is this a good thing? Are we able to change and/or expand on the code ourselves?

    I'm not so sure of the second demo though. Wouldn't it be more intuitive to show items being able to be dropped on the ground instead of textured onto boxes? :)

    Is it using Unity GUI or is it a separate GUI system?
     
  3. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    Thank you :)

    * The entire source code is included in the package. There's no separate dll or anything. One of the design goals was in fact that it is extendable for us as well as all other users.

    * As for the demo: If I understand you correctly that'd just be a matter of spawning a new physical cube at the mouse position and applying the item texture on it. Should be doable with a couple of lines of code. The demo was just meant to show that this kind of interaction is possible. I just didn't think of all the possibilities of what one could do :) I may add another demo that does this for fun when I got some spare time.
    edit: If you mean that the actual sword/helmet/flask item should drop on the floor: That's doable as well, but that'd obivously require for those objects to be modeled in 3d. And that's something we didn't do as we tried to keep the demo just simple enough to show the possibility.

    * It's currently using unity GUI.
     
    Last edited: Apr 30, 2012
  4. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,626
    Great stuff, bought and imported. Will let you know what I think when I've tried to fit it into my project. :)

    Yeah, I misunderstood the part about encapsulated and independent. I just read plugin and thought: "bah, if I can't modify it I don't want it", but now I definitively do.

    Especially since it's using Unity GUI as well so it should be easy to plug into what I already have.

    As for the demo I just thought it was an odd functionality to show considering most people would compare it to something like Diablo or World of Warcraft. I don't think I'll have a problem with making the drop on the ground behavior myself.

    I was actually working on an inventory myself, but was really struggling with the GUI system as I think it takes an insane amount of time to get what you want from it, especially the GUI skin part. It's nice to be able to buy something and see how it's done. All the other inventory systems I've bought were just shoddy coded or tried to include too much making them practically unusable. This seems just right and it looks tight from the demo. :p
     
  5. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
  6. siflandolly

    siflandolly

    Joined:
    May 17, 2011
    Posts:
    141
    This does look very nice. Is there support for some way to associate an inventory item with a physical prefab? Or do you have a recommended class to add this to?

    I was thinking a GameObject called itemPrefab or something as a member of AbstractDraggableInventoryItem ?

    This way if you drag the item on the terrain for instance it could instantiate the prefab and create it on the terrain.
     
  7. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    Yes you could simply add a gameobject as member to the AbstractDraggableInventoryItem class and then add it as additional parameter in the constructor. If all of the inventory systems you'll build should have the connection to a gameobject then that's definitely a good and clean solution.

    If you however may want to have another inventory in your game that is just displaying items and not have any connection to 3d gameobjects then i'd probably copy the ImageItem class, rename it and implement the gameobject functionality just in the copied class.

    Both solutions seem legit, depending on the way you want to use the inventory system.
     
  8. Rush-Rage-Games

    Rush-Rage-Games

    Joined:
    Sep 9, 2010
    Posts:
    1,998
    Looks pretty nice!
     
  9. Amytalk

    Amytalk

    Joined:
    May 3, 2012
    Posts:
    6
    Hey there! I'm a noobie game designer who is trying to build an rpg/trading card game. Instead of just normal weapons, players will be equipping cards. I'm using playMaker to visually script and wanted to know if your system is something I would be able to plug in and format to cards instead of just items for a normal RPG.
     
  10. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    Can you elaborate a little more on this? Are you talking about the graphical content? Adding custom content is totally up to the user. You'd have to create the card textures yourself though.
    Be advised though that currently this system is aimed at people who do have a bit of a programming background.
     
  11. Amytalk

    Amytalk

    Joined:
    May 3, 2012
    Posts:
    6
    Well, I'm a pretty good visual programmer ;) You have the ability to call and implant any script and for the most part, I understand the algorithms and concepts of programming decently. I'm more just making sure that I'm not stuck with an inventory aimed at 100 by 100 icons. I want cards that are about 250 by 150 that still look just as sleek.
     
  12. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    Gotcha. Here's a quick proof of concept that this is doable:

    http://download.rarebyte.com/sleekinventory/sleek_inventory_playing_cards.png

    Mind you that the slots background and highlighting graphics we ship with the package aren't really optimized for this ratio. You'd probably have to stretch them in photoshop for best visual quality. The icons can be any size. The only change in code that is necessary in order for this to work I will show you in the following.

    In the Simple Inventory Setup (1 Page, 1 Item) Tutorial there's currently this line that creates an inventory page:

    Code (csharp):
    1.  
    2. //Add 1 page.
    3. pages.Add(new ItemGridPage(inventorySizeX, inventorySizeY));
    4.  
    To get it working for your ratio of items you'd have to use the following code instead:

    Code (csharp):
    1.  
    2. pages.Add(new ItemGridPage(inventorySizeX, inventorySizeY, new Vector2(1, 1.67f)));
    3.  
    You're basically overriding the default square ratio to 1/1.67 which is what you want for 150 by 250 sized items. Hope this helps for you.
     
  13. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,626
    I hate making requests for a package I haven't actually used yet and I don't want this project to be bloated like all the other inventory systems on the asset store, but I noticed you included a numbered item class and it would be cool if those items where actual stacks of items which could be split.

    So let's say the potion is a stackable item. If I drag one potion on top of another they merge into a stack of 2. If I left click this new stack item I move both potions around, but if I right click I pull one potion from the stack.

    I think that would complement this package well.

    Hopefully, I will actually put this inventory into my game this weekend. Then I can probably say more about what I think about it. :)
     
  14. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    That is a good point. We have that on our internal wishlist. I'll be thinking about this some more in a couple of days. One thing though. While you're already thinking about it I might as well use your brain-power :p
    Any idea on how to do the splitting without the use of the right mouse button? Using the right mouse button would break this functionality for webplayer-based and touch input-based (iOS/Android) projects. This would be a pretty big dealbreaker imo.
     
  15. jorgenpt

    jorgenpt

    Joined:
    Apr 21, 2012
    Posts:
    9
    For iOS/Android, you could do long-press to pop up a "split items" dialog that has a slider to change the quantity.

    This looks really promising, but I feel like $50 is a tad on the expensive side for *just* a 2D inventory system.
    Any chance of a demo / limited free version to test out integration capabilities before buying?
     
  16. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    554
    This looks really nice.

    Just a quick mostly thoughtless idea on how to do splitting of stacks on web/mobile: Perhaps on web it can be done with a keypress modifier (such as holding shift while clicking) and on mobile it can be done with a long-press (the longer you hold it down, the more are split from the stack). Or maybe just leave it up to the developer to determine how to split them, and you just provide the functionality for it.
     
  17. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,626
    I feel very stupid when trying to use this inventory. :/

    I don't understand how to uses the classes/methods available.

    I added the inventory to my game. I already have items etc. in my game and I want to click on them and add them to the Sleek Inventory instead of my old inventory. No dragging, just click an item on the ground and add it to the inventory like in games like Diablo etc.

    I added this to my item class:
    Code (csharp):
    1. private SleekInventory inventory;
    2. void Start() {
    3.     inventory = GameObject.Find("SleekInventory").GetComponent<SleekInventory>();
    4. }
    Then I started looking for a way to get the first available slot in the inventory and add an item to that slot, but I honestly don't understand how to use the code in the package. Can I only access SetSlotItem() inside the GeneratePages method? How do I actually get the current pages in my inventory? Why isn't there a GetFirstFreeInventorySlot() method for the entire inventory instead of just per page?

    I looked in the SleekInventory class and found a gettersetter for Pages, but that was private. I tried changing it to public and then add this code to my item class:
    Code (csharp):
    1. public void OnMouseUp() {
    2.     foreach (AbstractInventoryPage page in inventory.Pages) {
    3.         InventorySlot slot = page.GetFirstFreeInventorySlot();
    4.     }
    5. }
    But got this error "Cannot implicitly convert type 'SleekInventorySystem.IInventoryDragTarget' to 'SleekInventorySystem.InventorySlot'."

    With pseudo code this is sort of what I was expecting to have to do to add an item to the inventory:
    Code (csharp):
    1. private SleekInventory inventory;
    2. void Start() {
    3.     inventory = GameObject.Find("SleekInventory").GetComponent<SleekInventory>();
    4. }
    5.  
    6. public void OnMouseUp() {
    7.     if (InventorySlot slot = inventory.GetFirstFreeInventorySlot()) {
    8.         inventory.SetSlotItem(slot, theItemIClicked);
    9.     }
    10.     else {
    11.         // You haven't got room in your inventory
    12.     }
    13. }
    Excuse my terminology, I probably butchered it. I've been programming for nearly 10 years, but always in frameworks like Drupal, Unity etc. and with no formal programming education I've never learned the actual terminology properly. By looking at the source code for this it's obvious this is "proper" code so that's surely why I'm struggling so much. :)
     
  18. jorgenpt

    jorgenpt

    Joined:
    Apr 21, 2012
    Posts:
    9
    I'm not entirely sure why GetFirstFreeInventorySlot returns an IInventoryDragTarget and not an InventorySlot, since the other implementations of IInventoryDragTarget are not slots you can put items in, AFAICT.

    I drummed this up from the docs, you should try something like this:
    Code (csharp):
    1. private SleekInventory inventory;
    2. void Start() {
    3.     inventory = GameObject.Find("SleekInventory").GetComponent<SleekInventory>();
    4. }
    5.  
    6. private InventorySlot GetFirstFreeInventorySlot ()
    7. {
    8.     foreach (AbstractInventoryPage page in inventory.Pages) {
    9.         InventorySlot slot = page.GetFirstFreeInventorySlot() as InventorySlot;
    10.         if (slot != null)
    11.             return slot;
    12.     }
    13.  
    14.     return null;
    15. }
    16.  
    17. public void OnMouseUp() {
    18.     InventorySlot slot = GetFirstFreeInventorySlot ();
    19.     if (slot != null) {
    20.         slot.SetItem(theItemIClicked);
    21.     } else {
    22.         // You haven't got room in your inventory
    23.     }
    24. }
     
  19. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,626
    That was fast.

    That actually worked perfectly. It gives me 2 items instead of 1, but that's probably just something I'm screwing up. :p

    But it did require that I made Pages public instead of private and use the SetItem() method which is commented such that I would think I'm doing something wrong by using it.

    Even so, thanks a lot.

    A tip for making the inventory background look a lot better, you should set the border values in the skin so it only stretches the middle of the image and leaves the edges crisp and pixel perfect:
     
    Last edited: May 5, 2012
  20. jorgenpt

    jorgenpt

    Joined:
    Apr 21, 2012
    Posts:
    9
    Oh, huh, http://download.rarebyte.com/sleeki...leek_inventory_system_1_1_inventory_slot.html didn't mention anything about SetItem. I guess the other option would be something like this:

    Code (csharp):
    1. private SleekInventory inventory;
    2. void Start() {
    3.     inventory = GameObject.Find("SleekInventory").GetComponent<SleekInventory>();
    4. }
    5.  
    6. private bool PutInFirstFreeInventorySlot (AbstractDraggableItem item)
    7. {
    8.     foreach (AbstractInventoryPage page in inventory.Pages) {
    9.         InventorySlot slot = page.GetFirstFreeInventorySlot() as InventorySlot;
    10.         if (slot != null)
    11.         {
    12.             SlotId slotId = slot.SlotId;
    13.             page.SetSlotItem (slotId.GridIdX, slotId.GridIdY, item);
    14.             return true;
    15.         }
    16.     }
    17.  
    18.     return false;
    19. }
    20.  
    21. public void OnMouseUp() {
    22.     if (PutInFirstFreeInventorySlot (theItemIClicked)) {
    23.         // You placed it successfully.
    24.     } else {
    25.         // You haven't got room in your inventory
    26.     }
    27. }

    I'm not sure what to do about the pages stuff, since I base this off the docs. :)
     
  21. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,626
    Hehe, I appreciate it. :)

    I'm sure Grazer2 will clear things up a bit for me when he gets here, but it's nice to get the ball rolling.

    This was what was written above SetItem:
    I will test your last solution after I'm done eating. :p

    Edit: Both methods worked equally well. The item being added twice was just me messing up some basic inheritance and adding MonoBehaviour twice to my item. :p
     
    Last edited: May 5, 2012
  22. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,626

    http://www.twiik.net/unity/pixelquest (Click the chest if you want to try for yourself)

    Ohh yeah, we've got items. :p

    Realized the streamreader couldn't be used in the webplayer as well so spent the last hour rewriting my random item generator to use textassets instead, but now we're getting somewhere.
     
  23. Amytalk

    Amytalk

    Joined:
    May 3, 2012
    Posts:
    6
    I can't afford it just yet. (Hopefully within the coming week or so.) but I'm interested to see how easy I can integrate this in playMaker unity scripting...I can already picture in my head commanding I to open and close this while tying this in with a battle system.

    Also, nice demo Twiik, still needs a ton of work but it's a great start.
     
    Last edited: May 6, 2012
  24. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,626
    Loving this. Very easy to get what I want from it so far.

    But I'm really not a fan of how you set the size of the inventory.

    I think you should set the size of each inventory slot and then the inventory stretches to fit instead of the way it is now where you set the size of the inventory and the slots stretches to fit. It's impossible to get pixel perfect inventory slots the way it is currently. Also I am drawing my game 2x the size of the textures so being able to set the size of each inventory slot to 32x32 and use a 16x16 texture would be really helpful.

    For now I just changed the return value of GetSlotArea() to a fixed size, which seems to work fine for everything except the items themselves. They are slightly skewed and I don't really know why:

    Compare the correct one on the left to the one on the right.
     
  25. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,626
    Heh, thanks Amy. You needn't tell me of the of the amount of work that remains, I know. :p

    Added the ability to drop items as well. Those with a keen eye will probably notice that it's not actually dropping the item you picked up, but rather generating a new one, but that's just technicalities. :D

    Two questions regarding tooltips:

    1. I want to press a key, e.g ALT, and have the tooltip for every item on the ground show up just like in Diablo and similar games. Is this possible with the GUI.tooltip? It seems to be global?


    2. I want to have tooltips with multiple colors and font styles:


    By looking at GUI.tooltip I'm thinking neither of these things are possible, is that correct? If so I guess I'll have to make my own tooltips.
     
  26. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    Main reason was extensibility. Maybe this was a bit overthinking on my side, but if someday somebody creates a crazy new type of inventory page that doesn't have 'slots', but some other kind of construct where you can put stuff into then this would still work. I guess I should've named the method differently.

    Good point. Will think about this and possibly add this to the system. For some reason I didn't have this way of using the system in mind. For our own projects there's always a data layer between the inventory and the items. Items are typically added to the database and then the GeneratePages method is called to re-generate the pages and add all items from the database. I see how your way of using the system makes it more direct and easier to use though.

    Great to hear.

    Pixel perfect slot size, I hear you.As for the 16x16 textures for 32x32 slots. Not sure how you are currently using the the inventory, but in my mind you can use any size items with any size slots. Can you elaborate on this?

    Will try to have a look at it.

    I fear you're correct. For now there's only the default Unity GUI.tooltip functionality that is added to the system. That functionality has both of the downsides you mentioned.
    As for point 2: There's FancyLabel which is basically free code that can be used to draw multicolor labels.
     
    Last edited: May 7, 2012
  27. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,626
    Does that mean you regenerate the inventory for each item you pick up? Or do you not have projects where items can be picked up?

    For now I'm just reading my item data from a text asset and generating them at runtime and the player can pick them up one and one like in Diablo, but I will try to implement saving and loading soon so then I guess generate pages will come in handy.

    For my game I scale everything 2x so a 16x16 texture looks like a 32x32 texture etc. I do this by just doubling the height and width of all my sprites, gui elements etc. In Sleek Inventory it displays the image based on its height and width so I have to use actual 32x32 textures for them to display as 32x32. This is probably an edge case, but it is something I need in my game.

    Cool, will check out FancyLabel.

    Using this package is a nice coding tutorial for me. :p Abstract, delegate, constructor, interface, virtual, override etc. etc. All words I had no clue what meant or did, but I'm beginning to grasp how it all fits together now. Luckily there's very little code and it's all nicely documented.
     
  28. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    Currently there aren't any plans on creating a demo or limited version. Maybe there will be in the future, but there's not certainty right now.
     
  29. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    We simply call the generate pages method everytime the inventory is updated. Since this typically is not something you do multiple times per frame there shouldn't be any performance hit, even on mobile devices or slow webplayers.

    Damn, I still don't get you. If you change the width and height of the inventory the items are rescaled to fit automatically. Try setting your inventory size to 100x100 and then to 500x500 and you should see all items being scaled, not depending on their actual widths or heights. If there are any other hints you can give me as to why exactly it doesn't work, please feel free to notify me by PM or something.
     
  30. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,626
    I see. I just assumed that there had to be a method for easily adding one item to the inventory instead of regenerating the whole thing. :)

    Ahh, I was just saying that if you add the option to scale the inventory to fit the slots instead of scaling the slots to fit the inventory like it is now it would be useful for me to specify the width/height of each slot instead of it relying on the image sizes.

    I've changed quite a bit of the code that draws the inventory in my version (it could probably be overridden instead of hacked, but I'm a noob. :D). Basically I want to specify the exact width, height and padding of the inventory and the exact width, height and spacing of each slot. Having stuff not be pixel perfect is not an option for me, but that's because my current game is made with pixel art. I guess in other games you would have to scale stuff to fit different resolutions etc.

    I also want to drag the inventory around instead of it being fixed, but these are all just wishes. They may not fit into your design plan and I should be able to accomplish them myself. :)

    Other stuff on my plan:
    - A character sheet / doll with inventory slots showing equipped items, probably separate from this, but using much of the same code.
    - Stacked items
     
    Last edited: May 7, 2012
  31. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
  32. KillbunnyuK

    KillbunnyuK

    Joined:
    Aug 21, 2012
    Posts:
    7
    Hey,

    Just wondering has anyone managed to get the inventory to drop a game object that is of what the texture is.

    Say like the helmet and vile texture that comes with the inventory and you drag them off the inventory to game and it spawns a real helmet for the helmet texture or a vile for the vile texture. This is the only thing that is kicking my butt :/, was kinda wardering if someone could point me in the right direction to do this.
     
  33. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    Please download the SleekInventory4_SpawnItemInScene.zip file I posted just above. This contains the source code for the 'dragging items into the scene' demo.

    Now you can, for example, find out the name of the texture of the item that was dropped by help of the following line:

    Code (csharp):
    1.  
    2. string iconName = (draggableItem as ImageItem).Icon.name;
    3.  
    which you may add to the InventoryItemDroppedOnWall(AbstractDraggableItem draggableItem) method in the inventory controller. This is where the spawning of the cube happens in the demo. By help of this texture name you can already find out the type of the item and spawn different objects based on that.

    A more elegant solution I guess would be to add some kind of public read ID property to the ImageItem and add this id to the constructor of the ImageItem.
     
  34. KillbunnyuK

    KillbunnyuK

    Joined:
    Aug 21, 2012
    Posts:
    7
    Hi, Sorry to sound like a noob about this but I'm having a bit of a problem. I put the code inside the IventoryItenDorppedOnWall method but it keeps poping up saying The variable 'test_icon_helmet' is assigned but its value is never used and im not 100% sure why this is happening :(
     
  35. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    Well this sounds like it's a problem coming from your code which I do not have. Can you send me your relevant pieces of code by PM so I can have a look at it? Thx.
     
  36. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    Quick update for anybody who is wondering. The package from the asset store works without a single warning in both unity 3.x as well as unity 4.0.
     
    Last edited: Dec 6, 2012
  37. Modeus

    Modeus

    Joined:
    Dec 12, 2012
    Posts:
    10
    Hi Grazer,

    Is this still working with no issues in the latest Unity version?

    Thanks.
     
  38. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    Hey there. Yes, the package is still working fine with the latest version of unity. Regards.
     
  39. Modeus

    Modeus

    Joined:
    Dec 12, 2012
    Posts:
    10
    Bought, and quite happy with it. Integrated into existing project in about 15 minutes by reading the documents. No issues in Unity 4.1.5f1.

    A bit too heavy on the programmatic interfaces side of things maybe? but very tidy. I extended it to handle splitting / merging stacks and easier item adding / finding quite quickly, a clear sign of solid design in an asset. Well done.
     
  40. DavidJNels

    DavidJNels

    Joined:
    Aug 10, 2012
    Posts:
    34
    Hi Grazer2 -

    Just got this plugin for an upcoming project. Excellent work.

    How would you recommend implementing persistance / saving the inventory contents between sessions? Is there a pre-serialized string we can easily store and then load via playerprefs or similar?

    Thanks,
    David
     
  41. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    Hey there. Glad you like the inventory system. I cooked up some helper classes for this case. See the attached .rar file.

    Saving:
    Basically you'll want to invoke the method SaveGridItemPositions() from the save_grid_items_usage.txt. You can do this in your Inventory Controller. This will return you an object that holds item id and position data. This object can be serialized by all kinds of different means. Over here we're mainly using json (minijson or jsonfx) to do this task. Another valid option would be to use XML (de)serialization which I believe is built into .NET. The result will be a string that can be stored in a database or in the playerprefs or any other similar place.

    Loading:
    Deserialize the string created above into the helper object. Then iterate through the contained items and set the items to the inventory using the SetSlotItem method in the ItemGridPage. This part is similar to the code for generating the test items in the Test controllers that are shipped with the plugin.

    Hope this helps you get started on this topic. Feel free to report back in case of troubles. Cheers.
     

    Attached Files:

  42. DavidJNels

    DavidJNels

    Joined:
    Aug 10, 2012
    Posts:
    34
    Hey man,

    We're having to homebrew our own saving for a couple of reasons but just encountered what seems to be a strange issue.

    Code (csharp):
    1. Debug.Log(testInventory.Pages[0].GetAllItems());
    In theory this should spit out an ever growing list as more items are added, correct? Instead it seems to only contain the value for the first slot of the first page.

    If we're doing something wrong here can you please provide an example of code to traverse the inventory contents and do a debug.log w/ each one's metadata?

    Thanks!
    David
     
  43. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    Traversing the inventory should work like this:

    Code (csharp):
    1.  
    2. using SleekInventorySystem;
    3.  
    4. ...
    5.  
    6. foreach (KeyValuePair<AbstractInventorySlotID, AbstractDraggableItem> kvp in testInventory.GetAllItems()) {
    7.  
    8.   InventorySlotID slotId = kvp.Key as InventorySlotID; //You can fetch the item page and position from this.
    9.  
    10.   AbstractDraggableInventoryItem item = kvp.Value as AbstractDraggableInventoryItem; //You can cast this to your custom item type to get your own metadata from it.
    11.  
    12.   //Example for logging:
    13.   //Debug.Log((item as YourItemClass).YourMetaData);
    14. }
    15.  
    Waiting to hear if that works for you. Cheers, Grazer
     
    Last edited: Aug 6, 2013
  44. NCrush

    NCrush

    Joined:
    Aug 1, 2013
    Posts:
    5
    Hey Grazer2,

    To add an item to my Inventory I use this code inside a method and pass in an icon texture name


    Code (csharp):
    1.        
    2.        InventorySlot slot = GetFirstFreeInventorySlot ();
    3.        if (slot != null) {
    4.    
    5.             SleekInventoryTextureContainer textureContainer = this.gameObject.GetComponent<SleekInventoryTextureContainer>();
    6.             ImageItem item1 = new ImageItem(textureContainer.GetTextureByFilename(icon.ToString())); //Regular image item.
    7.            
    8.             slot.SetItem(item1);
    9.         } else {
    10.    
    11.             // You haven't got room in your inventory
    12.    
    13.         }
    14.  
    It works, but what is the best way to reverse this to remove the item and free up the inventory slot?

    The way I want this to work is to be able to click on the item in the inventory and have it highlight as if it's now in hand and then to be able to click an object in gameplay and have them combine etc... So if an item is combined and therefore used, I want to be able to remove it from the inventory.

    I've tried pulling apart the other examples but they're all based on drag and drop and I can't really work out how exactly it steps back to find how you remove and item (which I'm starting to believe doesn't actually happen, you just move it as a texture to different objects, more so.)

    Any help on how to remove an item and free up a slot from the inventory in the simplest of ways by passing an icon texture name, would be fantastic.

    Thanks.
     
  45. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    Hey there,

    If you already have a reference to your item to be removed, you can go like this:

    Code (csharp):
    1.  
    2. //ImageItem itemToRemove
    3. itemToRemove.OldDragTarget.OnItemRemoved(itemToRemove);
    4.  
    I guess I'll have to cook up some more interfaces for this case. In order to find the item that was clicked last you may expose the CurrentlyDraggedItem property in the SleekInventory.cs by adding "public" in front of the "get;" interface. Note that this is rather crude though. Also beware that the property becomes null as soon as the mouse is pressed somewhere else on the screen.
    You're right though, that for some reason I haven't thought of being able to directly click on items, and instead implement drag&drop only.
     
  46. NCrush

    NCrush

    Joined:
    Aug 1, 2013
    Posts:
    5
    Thanks for the reply.

    I'll give it a try. And yes, if there's a way you could develop something like that, it'd be great! :)
     
  47. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    A minor update has just been approved and added to the Asset Store. It contains a few helper classes and methods aimed at simplifying the process of saving and loading the inventory state. A new test-scene is contained that shows this funcionality. Saving is pretty simple, while loading still needs a couple of lines of code in order to work with custom and/or modified types of items.

    Following a request from this thread also the clicking of an item can be caught more easily now. There's a simple OnItemClicked event in the SleekInventory class that can be listened to.
     
  48. Ghosthowl

    Ghosthowl

    Joined:
    Feb 2, 2014
    Posts:
    170
    Pardon my ignorance, I haven't read through all the documentation and I will but I was posting this real quick so if it is indeed not possible or doesn't seem feasible at least I have given some time into getting a response or answer.

    Would it be possibly to make a sub inventory say 1 x 10 grid that works like an action bar? As in a player can use key presses and mouse clicks to activate items and or skills? It seems like from above and in the comments it is with the new OnItemClicked event. Are their classes and or events set up for each slot in the inventory that can be listened to and manipulated? It seems this is completely possible from what I have eyeballed so far, but just want to see how much implementation it would take to achieve this.

    Either way this asset looks completely awesome and I have been eyeballing it for over a month as we are finally getting into the implementation of an inventory system in our game. This would be a huge head start / time saver if anything.

    Thank you for your time!
     
  49. Grazer2

    Grazer2

    Joined:
    Jun 20, 2011
    Posts:
    46
    Hey Ghosthowl,

    Not entirely sure if I completely understood your question. In case I did, the following code would do what you were asking for:

    First, register an event callback method:

    Code (csharp):
    1.  
    2. SleekInventory testInventory = ... //You can see how to get this in any of the samples. Typically this is fetched from a gameobject with the SleekInventory component on it.
    3. testInventory.OnItemClicked += new SleekInventory.ItemClickDelegate(testInventory_OnItemClicked);
    4.  
    Now whenever any item in the inventory of this specific inventory is clicked, the callback will be invoked. Here's an example callback:

    Code (csharp):
    1.  
    2. private void testInventory_OnItemClicked(AbstractDraggableItem inventoryItem) {
    3.   Debug.Log("User clicked on item '" + inventoryItem + "'");
    4.   testInventory.RemoveItem(inventoryItem);
    5. }
    6.  
    Now, when the user clicks on an inventory item, the item is removed, and the following is output to the console:

    User clicked on item 'ImageItem - Icon = test_icon_helmet (UnityEngine.Texture2D)'

    Please report back if the above was of any help to you. Cheers.

    Edit: Note that the above only works for mouse clicks. There's no real keyboard handling available in the inventory system.
     
    Last edited: Mar 25, 2014
  50. Ghosthowl

    Ghosthowl

    Joined:
    Feb 2, 2014
    Posts:
    170
    Hey Grazer2,

    Wow fantastic support already for a perspective customer. Loving what I am seeing here. Yes this seems like what I am trying to do, let me try to explain a little bit more.

    Is it possible to have more than one instance of the inventory class up to display? Say I have a permanent inventory that is of size 1 x 10. This will be used as an action bar. I can drag and drop items in between the main inventory window(which I can open and close) and this bar. Say user presses a button on the keyboard, the number 1. I will program the methods dealing with taking this call, but would it be easily possible send a message to the OnItemClicked or whatever inventory slot is at position 0 (say the 1 x 10 grid is indexed from 0-9). I could then do what I will with the items.

    Basically I am trying to do to main large things: Have 2 (or more) inventory windows and jack in my input handler to interact somehow with this second window via keyboard.