Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

S-Inventory: Equipment, Crafting, Skill Bar, Item Groups, Containers & Merchant (C# & JS)

Discussion in 'Assets and Asset Store' started by OussamaB, Jul 29, 2013.

Thread Status:
Not open for further replies.
  1. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Hi twobob, thanks for your observations :). The snapping would work except in cases where there are multiple possible slots for an item, such as two weapon slots or two ring slots. Snapping to the first available slot might work, except when one slot differs functionally from the other (primary weapon vs secondary weapon, etc). The user might not want to auto snap a particular item to a particular slot. Not sure the best way to handle snapping in this case. I've wrestled with these issues building even a simplified inventory system, so I'm sure SoumiDelRio has tons more to think about.

    Not sure what you mean by impossible for 10x16... you mean aspect ratio? Why do you think dragging would be impossible on a mobile screen, especially larger mobile screens with fullHD or quadHD? My main issue with mobile screens is that small pc-oriented menus are hard to read, and tiny pc-oriented buttons are hard to press accurately with big fat fingers like mine :).

    Yes, I totally agree it should be optional :). In fact, I realized that the more things are made optional in an asset, the better it is for the end users. I'm ranting now but I'm always perplexed when software makers insist on only "one right way" of doing things. Zbrush anyone? That interface gives my nightmares nightmares.
     
    twobob likes this.
  2. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Exactly.

    More options to support mobile platforms, thanks for the suggestion.

    And happy new year to all of you!
     
    eridani and twobob like this.
  3. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    This might be a silly suggestion, as I'm not much of a programmer, but I would recommend you look at ways to move as much logic out of the Update() loop as you can: there's a lot of stuff like checking the Save/Load bool and listening for attempts to open containers that could go in one-time events and save a couple of milliseconds every frame.
     
    eridani likes this.
  4. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    The update already includes some code refactoring in order to reduce memory usage.
     
    Last edited: Jan 3, 2015
  5. thenamesace

    thenamesace

    Joined:
    Jan 25, 2014
    Posts:
    157
    @SoumiDelRio This one :)
     
  6. thenamesace

    thenamesace

    Joined:
    Jan 25, 2014
    Posts:
    157
    @SoumiDelRio S-quest was doing the same thing as s-inventory
     
  7. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Yes, that's one of the main reasons of the update. The performance issues were mainly caused by the old GUI system as OnGUI function was called many times in one single frame.
     
    thenamesace likes this.
  8. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    mate. check your mail please.
    update on update sent to you
     
    OussamaB likes this.
  9. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Thanks for the great feedback dude!
     
  10. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    sure. Looking forward to it.

    Might just want to "double double" (that means "do extra checks") that that javascript folder doesn't bite you in the arse. I never did get to the bottom of the "Name" in namepsace errors.

    Thanks for letting me play.


    (my gosh "double double" that that, isn't the English language horrifically twisted )
     
  11. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Changing the build platform actually shows these JS errors. So yeah, I got them all.
     
  12. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    awesomesauce.

    I thought that was what you meant in the email but thought I should double double.

    A minimum of trouser-dropping mistakes is always best ;)
     
  13. lokendoch

    lokendoch

    Joined:
    Feb 10, 2013
    Posts:
    3
    I recently purchased S-Inventory and am trying to use it for a mobile device. In the inspector and unity remote everything works fine, when i build the apk and put on a phone or tablet I can no longer drag and drop and when I buy from a shop it takes the coins away but never gives me my item. Does anyone know how I could go about fixing this in C#? I am kinda new to unity and C# but know a bit.
     
  14. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    S-Inventory current version isn't really mobile friendly. I advise you to wait for the update which has been submitted last Friday but still hasn't been accepted by the asset store.
    As for the vendor issue, does it play the audio clip of a newly added item? Also does the name of the item appear in the middle of the screen like this: "Axe added"?
     
  15. HelixU4

    HelixU4

    Joined:
    Jan 25, 2013
    Posts:
    61
    I'm trying the new update, but everytime i run the scene the EmptySlot gets deleted from the scene and pops back when I stop the scene, so nothing is working :(
     
  16. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    The empty slot object is copied as many times as the number of slots you have (MaxItems in the inventory manager) then it gets destroyed.
     
  17. lokendoch

    lokendoch

    Joined:
    Feb 10, 2013
    Posts:
    3
    As for the audio there was some bug in the vendor script with the closing audio being played over an over continuously so i disabled all the audio for the vendor as I'm not gonna have sound for it. I have a "Player Log" script i can send messages to and it displays it on screen. I can send debug messages to it. The name does not appear in the middle of the screen but when i send the message of what is supposed to be being added in the vendor script it sends the correct message - ie.(Vendor was supposed to give Sword(Clone)).

    About it not being "Mobile Friendly", one of the reasons i bought this system is because on the asses store in bold letters it describes this as mobile friendly ;). I'll wait till the new update and see if it fixes it. Thank you and sorry for the late reply, I've been very busy lately.
     
  18. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Unity 4.6 new UI update is now available on the asset store!

    Please download the update and let me know as soon as possible if the issue still exists.
     
  19. HelixU4

    HelixU4

    Joined:
    Jan 25, 2013
    Posts:
    61
    Hmm well the problem is that in the inventory inspector i get an error "MissingObject" and when I stop the scene i have to assign it again to the inventory manager. Also the drag window function does not work, same goes with dragging items around in the inventory.
     
  20. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Have you imported the update into a new project or an existing one (which used to include the old version of the asset)?
    By the way it's normal that it writes "MissingObject" in the inspector view of the inventory which is NOT an error and it shouldn't have any effect on the game. As for dragging, check if you have an Event System in the scene and check if each one of the dragging events are placed (follow the guide).
    Screenshots of your issue will help as well.
     
  21. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    This is great, really happy that the asset story finally posted the update... one question though, I'm getting six identical warnings from SlotUI, 'UnityEngine.GameObject.active is obsolete: use GameObject.SetActive()'. Don't know if it matters at all, but thought I'd let you know :)
     
  22. lokendoch

    lokendoch

    Joined:
    Feb 10, 2013
    Posts:
    3
    Everything works great now! Thank you again.
     
  23. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Thanks for reporting that issue. It won't effect anything in the asset but I will clear those warnings in the next update.

    Glad you liked it!
     
  24. TheKnown

    TheKnown

    Joined:
    Jan 2, 2015
    Posts:
    1
    How would one write a simple script for dropping all inventory objects when the player dies. Ive looked around and there are no in-depth ways of doing this looks like im in the dark for now :(
     
  25. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    It's easy, you just need to loop through all the inventory slots and remove them all.
    Here's an example code of how to loop through the inventory slots and check if they are taken:
    http://soumidelrio.com/document/s-inventory/custom-events/
     
  26. john_galt

    john_galt

    Joined:
    Jan 10, 2015
    Posts:
    1
    Hello!
    I believe I have encountered an issue using your S-Inventory asset.
    The C# version of the container script doesn't seem to work properly.

    The JS version works perfectly, without any problem:
    - If the pickup type is set on "Mouse", the player can open a container ONLY by pressing the left mouse button.
    - If the pickup type is set on "Keyboard", the player can open the container ONLY by pressing "E" on the keyboard.

    The C# version is buggy however:
    - If the pickup type is set on "Mouse", the player can open a container by pressing the left mouse button AND by pressing "E" on the keyboard.
    - If the pickup type is set on "Keyboard", the player cannot open the container at all. Nothing happens.

    Thanks for your help!
     
  27. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Hello there, thanks for reporting that bug. It will be fixed in the next update.
     
  28. unitynewb

    unitynewb

    Joined:
    Feb 22, 2009
    Posts:
    243
    Are there any plans on getting this to work with NGUI instead of the UnityGUI?
     
  29. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Even better, the latest version uses the new Unity UI!

    @SoumiDelRio - I have another request. Would you please separate the menu items for "Use" and "Add To Skill Bar"? I think some people would like to be able to add potions to the skill bar and also use them directly from the inventory window. Thanks!
     
  30. unitynewb

    unitynewb

    Joined:
    Feb 22, 2009
    Posts:
    243
    I read that the UnityUI is not as good as NGUI yet, so its best to keep using NGUI.
     
  31. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    If you have access to both, try them out. I think you'll be pleased with Unity UI. Unity has a good tutorial series on it.
     
  32. unitynewb

    unitynewb

    Joined:
    Feb 22, 2009
    Posts:
    243
    Yeah I was thinking about it and I can just turn off NGUI and turn on the Unity GUI object when i use this inventory tool.

    The problem is after downloading the plugin from the asset store, I start up the demo and get errors. I looked into it and it seems like the reason is because the UnityCanvas included in the demo has all the scripts missing from the objects which causes the S-Inventory scripts to throw errors because it can't access all the UnityGUI image and text objects.
     
  33. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    The developer, @SoumiDelRio , may have a better answer, but make sure you're using Unity 4.6.x, and try to import into a project that doesn't already have S-Inventory in it.
     
  34. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    The 4.6 UI update has been recently released and I'm going to focus on improving it in future updates. Therefore, I can't promise a NGUI update any time soon. Sorry.
     
  35. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Added on my to-do list. Keep those suggestions coming!
     
  36. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Try to import the asset into a new project. If it works then make sure that you delete everything related to the old version only of the asset. Have you tried both demo scenes?
     
  37. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Update 1.21 has been submitted, here's the main list of changes/fixes:

    - Fixed a bug when you interact with containers with keyboard pick up type.
    - Fixed updating currency when buying/selling items.
    - Added On Collision item/currency pick up option.
    - Added the option to place random items in the item group.
    - Added the option to make vendors accept specific items only to sell.
    - Added event hooks for the custom events (C# only).

    The guide has been updated as well.
     
    thenamesace likes this.
  38. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Is there a simple way to remove the left-click menu in the inventory screen? Ideally, I'd like to figure out how to configure it so double-clicking equips the item if it's equipment, and right-click consumes/uses the item if it's useable.
     
  39. HelixU4

    HelixU4

    Joined:
    Jan 25, 2013
    Posts:
    61
    When will it be possible to run different events based on what item in the inventory is used?
    Using that potion will run that script/event and that scroll with do another event/script.
     
  40. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    If you're using the C# version of v1.21, SoumiDelRio added event hooks to InventoryEvents.cs. Add InventoryEvents to your character, and then add a script like this:
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class UseItems : MonoBehaviour {
    4.  
    5.     void OnEnable() {
    6.         GetComponent<InventoryEvents>().PlayerUsedItem += OnPlayerUsedItem;
    7.     }
    8.  
    9.     void OnDisable() {
    10.         GetComponent<InventoryEvents>().PlayerUsedItem -= OnPlayerUsedItem;
    11.     }
    12.  
    13.     void OnPlayerUsedItem(string ItemName) {
    14.         if (string.Equals(ItemName, "Health Potion")) {
    15.             // (Your code here to use a health potion)
    16.         } else if (string.Equals(ItemName, "Invisibility Scroll")) {
    17.             // (Your code here to use an invisibility scroll)
    18.         } // etc.
    19.     }
    20. }
    You could make the code inside OnPlayerUsedItem much more general; the code above is just an example.
     
  41. HelixU4

    HelixU4

    Joined:
    Jan 25, 2013
    Posts:
    61

    Thanks for your reply, I'm not much of a coder so writing actions my self would be a bad idea, but I'm using PlayMaker, and having it sending an message to PlayMaker to run an event should work. Thanks!

    But let's say I have 50 different items, would it have to run through every string and compare it? If so, it is the best solution?
     
  42. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    You could set up a table using ArrayMaker, or a just use a big set of transitions. Conceptually, your FSM might look something like this:

    Code (FSM):
    1. UseState
    2. ---------
    3. [HealthPotion]        --->  <GiveHealthState>       --> (back to UseState)
    4. [InvisibilityScroll]  --->  <EnableInsibilityState> --> (back to UseState)
    5. [GrowthPotion]        --->  <GrowState>             --> (back to UseState)
     
  43. HelixU4

    HelixU4

    Joined:
    Jan 25, 2013
    Posts:
    61
    Yeah the PlayMaker part is fine. I was thinking more about the InvenotryEvents.cs script. In the
    Code (CSharp):
    1.  void OnPlayerUsedItem(string ItemName)
    section I would list all the items that should run an event when used. Let's say I have 50 different potions and scrolls to use, it would have to run through all of them until it finds the String that matches the item used and then run the set of commands in that section.
     
  44. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    If you name your PlayMaker events the same as your item names, you can just do this:
    Code (csharp):
    1. using UnityEngine;
    2. using HutongGames.PlayMaker ;
    3.  
    4. public class UseItems : MonoBehaviour {
    5.  
    6.     void OnEnable() {
    7.         GetComponent<InventoryEvents>().PlayerUsedItem += OnPlayerUsedItem;
    8.     }
    9.  
    10.     void OnDisable() {
    11.         GetComponent<InventoryEvents>().PlayerUsedItem -= OnPlayerUsedItem;
    12.     }
    13.  
    14.     void OnPlayerUsedItem(string ItemName) {
    15.         GetComponent<PlayMakerFSM>().SendEvent(ItemName);
    16.     }
    17. }
     
  45. HelixU4

    HelixU4

    Joined:
    Jan 25, 2013
    Posts:
    61
    Thank you so much TonyLi! Worked like a charm :)
     
  46. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Happy to help!
     
    eridani likes this.
  47. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    To disable the action menu just comment the "ActionMenu" function in the "SlotUI" script. This function is called on pointer click so you'd have to replace it with another function that will check if the clicked item is usable then consume it.
    I would be more than happy to make this modification for you by tomorrow since I don't have access to my PC till then.

    Your assistance has been very helpful for me. Thank you very much!
     
  48. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Perfect, thank you! I really appreciate the help. :)
     
  49. HelixU4

    HelixU4

    Joined:
    Jan 25, 2013
    Posts:
    61
    Is it possible to change the cursor when hovering a item that can be looted? Like a hand or something :) ?
     
  50. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    If you're using RFPS, add a Pickup script (or an SInventoryPickup if you have the Dialogue System and import the support package).

    If you're not using RFPS, how about writing a short script that implements OnMouseEnter and OnMouseExit? Something like:
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class CursorOnMouseOver : MonoBehaviour {
    4.  
    5.     public Texture2D cursorTexture;
    6.     public Vector2 hotSpot;
    7.  
    8.     void OnMouseEnter() {
    9.         Cursor.SetCursor(cursorTexture, hotSpot, CursorMode.Auto);
    10.     }
    11.  
    12.     void OnMouseExit() {
    13.         Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto); // restore default cursor
    14.     }
    15. }
    It might be nice to have this as a built-in option with S-Inventory, too.
     
Thread Status:
Not open for further replies.