Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

*UPDATE* Inventory Master - Inventory System written with the new UI System 4.6 *UPDATE*

Discussion in 'Assets and Asset Store' started by Sander1991, Dec 12, 2014.

  1. Sander1991

    Sander1991

    Joined:
    Aug 25, 2014
    Posts:
    162
    @jokerfool

    can you add me in skype(buchheim.sander)? I guess we can work there easier.
     
  2. Sander1991

    Sander1991

    Joined:
    Aug 25, 2014
    Posts:
    162
    For everyone who wants to have a UFPS integration can write me an email! I have to take my current submission back. I got an email from the publisher of UFPS and he gave me some important informations, which I did not consider. So I have to rethink the whole system behind it and will go through the whole stuff again!

    I want to deliver the perfect inventory system with UFPS and not just a average solution, so please understand my decision to rethink everything. Everyone who cannot wait, can write me an email(buchheim.sander@yahoo.de) with his invoice and can use my current solution of the UFPS integration, which is already working pretty solid.

    I hope you understand my decisions.
    Sander

    PS: There will be a update with the following things:
    + Unity 5 ready
    + new IM-Manager
    + new Input Manager, to handle Keycodes for the inventories
    + now you are allowed to create more final items out of an ingredient(Example: 1 wood as an ingridient will give you 2 planks)
    + a complete new texture pack
    + some bug fixes and some different changes(readable in the documentation and script API)
     
  3. The-W-A-T-Z-R

    The-W-A-T-Z-R

    Joined:
    Apr 13, 2014
    Posts:
    22
    what is it that u need to redo for it gonna work better with UFPS? :)
    is it big stuffs do ?
    do it gonna take long time ?

    becuse in our team we have big work to do whit Ufps and your inventory system for ur asset fit us perfectly.
    for in our to do list it is just to get a stable inventory-crafting-hotbar-storage-BlueprintDatabase-backbak-charactersystem to our UFPS character
     
    Last edited: Mar 16, 2015
  4. Sander1991

    Sander1991

    Joined:
    Aug 25, 2014
    Posts:
    162
    @The-W.A.T.Z.R

    So the UFPS publisher wrote me again ;). So it seems not so easy to be, how he firstly thought it would be. I will look into it and if it is too complicated I will submit my current version. How I said, it is a very solid version and you can work with it already! You do not need to worry overall. I will give you further informations about it soon.

    I also asked some other people, who already were using the system from me. They are are pretty happy with the current version. The only thing, are the grenades. You probably will notice, when you have a weapon in the hand and throw a grenade, it take 3 secs to get back to the weapon. This is the only thing, which I do not like at the moment.
     
  5. Sander1991

    Sander1991

    Joined:
    Aug 25, 2014
    Posts:
    162
    @jokerfool
    So firstly to the design of the hotbar. You can change it easily. Just take a look into this video, where I create a hotbar and also change the design of it:


    What do you mean it hides behind it? How I also mentioned in the video about the tooltip. Be sure that the tooltip is always underneath the inventories. You see there are all the panels(inventories) over the the tooltip. That means that the tooltip is getting rendered at last and always will be in front of everything. Just DraggingItem(Clone) needs to be under the tooltip.


    I hope I could have helped!
     
    Last edited: Mar 18, 2015
  6. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,434
    Great asset. Is this working for Mobile?
     
  7. Sander1991

    Sander1991

    Joined:
    Aug 25, 2014
    Posts:
    162
    @rocki
    At the moment it does not support mobile, sorry.
     
  8. psistalk

    psistalk

    Joined:
    Sep 23, 2013
    Posts:
    68
  9. Sander1991

    Sander1991

    Joined:
    Aug 25, 2014
    Posts:
    162
    This how I am doing it with the items ;). It did not come with unity 5. It was already there earlier ;)
     
  10. Tirgon

    Tirgon

    Joined:
    Apr 13, 2015
    Posts:
    2
    Can't get it to work with UFPS. The UFPS checkbox in IM Manager is missing.
     

    Attached Files:

  11. ShivaFooL

    ShivaFooL

    Joined:
    Jul 3, 2010
    Posts:
    16
    I've been trying different inventory systems, and this is my 5th or 6th one. So far it seems to be suiting my needs the needs the best, so thank you and thank you for the videos. I'm using it in Unity5 which seems to be fine. A tip for others who may be trying this out, you have to add the EventSystem and DraggingItem prefabs into your scene in addition to the other steps which are made very clear. I don't know if I missed that somewhere in the instructions, but if I did, maybe someone else did too who may benefit from the tip.I got null reference error that was cleared up by making a prefab from the Timer in the example scene, and adding that as well to the canvas inventory. And the Item prefab had a place for a script that wasn't filled, and other error messages cleared up by putting the Pick Up Item script in there. Again, I hope this may help someone else.
    I was surprised that you said Playmaker support is way down the list. I know there are a lot of other Playmaker fans besides me. Anyhow, I'm very pleased with my purchase of your asset.
     
    Last edited: Apr 13, 2015
  12. Sander1991

    Sander1991

    Joined:
    Aug 25, 2014
    Posts:
    162
    @ShivaFooL

    Nice to hear that my system fits to your needs ;). It is weird that you need to create some prefabs. They should be already created in the Resources/Prefabs folder. However thank you for writing it down for other people ;)
     
  13. ShivaFooL

    ShivaFooL

    Joined:
    Jul 3, 2010
    Posts:
    16
    I am trying to implement the example random looting system, and I am getting this error:
    "
    UnassignedReferenceException: The variable prefabItem of Inventory has not been assigned.
    You probably need to assign the prefabItem variable of the Inventory script in the inspector.
    UnityEngine.Object.Instantiate[GameObject] (UnityEngine.GameObject original) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:95)
    Inventory.addItemToInventory (Int32 id, Int32 value) (at Assets/InventoryMaster/Scripts/Inventory/Inventory.cs:611)
    PickUpItem.Update () (at Assets/InventoryMaster/Scripts/Item/PickUpItem.cs:31)
    "
    I'm just using the basic ItemOnTheGround prefab. Is that the problem? I haven't been able to figure it out.
     
  14. Sander1991

    Sander1991

    Joined:
    Aug 25, 2014
    Posts:
    162
    @ShivaFooL

    I have tried it. For me everything is working without any problem. Could it be that some of your items does not have a gamemodel? Just check it in the itemdatabase. Be sure that they have a gameobject as a model! I hope this fixes it ;)
     
  15. ShivaFooL

    ShivaFooL

    Joined:
    Jul 3, 2010
    Posts:
    16
    Hi Sander.
    I think I figured it out. In testing out your asset, I made a prefab from the whole inventory canvas that was working for me, and then dropped that into a new test scene. Harmless time-saver, or so I thought. The pickUpItem script calls the addItemToInventory function in the Inventory script, which needs the Item prefab. Since I used that canvas prefab instead of starting from scratch, the Inventory script's getPrefabs function had been bypassed. When I build the inventory canvas into the scene from the Master System menu's Create method, then I have no problem.
    Again, I hope my bumbling about helps someone else.
    Cheers.
     
  16. Alex3333

    Alex3333

    Joined:
    Dec 29, 2014
    Posts:
    342
    You will have support in the near future or not UFPS Multieplayer?
     
  17. fifty6

    fifty6

    Joined:
    Jul 12, 2012
    Posts:
    5
    Does anyone know how well this works with a 2D Game? I am working on a 2d orthographic game and and considering using this. However I just want to verify it is compatible with 2d builds. Does anyone know anything regarding this inventory system working with a 2d game?
     
    Last edited: May 3, 2015
  18. Sander1991

    Sander1991

    Joined:
    Aug 25, 2014
    Posts:
    162
    @Alex3333
    Sorry for the late reply. Actually it is not planned to support UFPS Multiplayer.
     
  19. ShivaFooL

    ShivaFooL

    Joined:
    Jul 3, 2010
    Posts:
    16
    I'm wondering about a save function for the inventories, which is the main feature request for me. Will this be in an update sometime, or should we plan on implementing this ourselves?
    Cheers.
     
  20. Sander1991

    Sander1991

    Joined:
    Aug 25, 2014
    Posts:
    162
    @ShivaFooL
    Yes, it is planned. The problem is that my university started again and I am really busy, thats why I answered the last posts so late. I am trying to implement them, but the time is limited at the moment.
     
  21. ShivaFooL

    ShivaFooL

    Joined:
    Jul 3, 2010
    Posts:
    16
    Thanks, Sander. I'm still loving this asset. Best of luck with university. Fortunately, I am in no hurry.
    Cheers.
     
  22. fifty6

    fifty6

    Joined:
    Jul 12, 2012
    Posts:
    5
    Does anyone know how well this works with a 2D Game? I am working on a 2d orthographic game and and considering using this. However I just want to verify it is compatible with 2d builds. Does anyone know anything regarding this inventory system working with a 2d game?
     
  23. Stevorino

    Stevorino

    Joined:
    May 4, 2013
    Posts:
    7
    I'm using it on my 2D RTS and so far it's worked really well.

    I haven't run into anything that is 3D-centric that I had to work around. It's based off of uGUI 4.6, so it is really easy to tweak and manage for 2D. I just plugged it in and it worked flawlessly with my existing HUD almost immediately.
     
    Last edited: May 17, 2015
  24. Stevorino

    Stevorino

    Joined:
    May 4, 2013
    Posts:
    7
    Awesome Asset - Couple questions and one potential bug report:

    - When first learning the system, I added a bunch of unnecessary attributes - is there an easy way to get them out of the attribute database? Sorry if this is a newb question - I haven't been able to figure it out yet.

    - What is the difference beween 'EquipItem' and 'OnGearItem' - or is there not a difference?

    - Possible Bug: When assigning attributes in the IM to various items from the 'Manage Items' view, it seems like the system is consistently overwriting my input from the input of the previous item. Ex: Put Health 10 on Item #2. When I go to Item #3 and click 'Add Attribute' - it auto fills Health but won't let me change it to something else. The only way I can get around it is to add more attributes until a blank one appears, then fill it with what I want, save the item, and then delete the attributes I don't want. May just be a silly bug. Not a big deal - but wanted to give you a heads up!

    Great product - I wrote a great review for it! Thanks!
     
    Last edited: May 18, 2015
  25. Sander1991

    Sander1991

    Joined:
    Aug 25, 2014
    Posts:
    162
    @Stevorino
    Nice to hear that you like my asset and thank you for this nice review.

    So firstly to the attribute database. Just search "attribute" and you will find a assetdatabase where you can click on and in the inspector is a list of all attributes which exist. You can modify them there or you can delete them. Here is a picture:


    What is the difference beween 'EquipItem' and 'OnGearItem' - or is there not a difference?

    Yep, they are the same.

    Bug:
    Thank you for reporting it. I will look into it.
     
    Last edited: May 18, 2015
  26. Stevorino

    Stevorino

    Joined:
    May 4, 2013
    Posts:
    7
    Wow - I feel like a dummy :p

    I had the Inv Manager over the inspector whenver clicking on the attribute database and never thought about it being accessible in the inspector. Thanks for helping out!

    Happy to write the review - it's a great product - thanks for making it!
     
  27. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    @ Sander1991,

    Can this asset cater for item types and subtypes, equipment slots for weapons (also to the 3d humanoid, mounting objects, armour, weapons)? Could I combine this easily with my SimpleSQL databases?

    Does it run it's own databases? If yes, in what format?
     
  28. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    @Sander1991 ,

    I've got that that point where I am considering whether to invest in an Inventory+ system to complement my work on an RPG and perhaps go hand in hand with Playmaker etc. And SimpleSQL.

    I can't find the info requested in the post above anywhere on the system.

    Referring to the questions in the post immediately above, how many attributes can you add to items,weapons,equipment? Also, with the databases, can they be encrypted?

    Is there a manual somewhere or some documentation in addition to the video tutorials?

    I am trying to distinguish between this Asset, Inventory Pro and the systems already available under the ORK framework...

    I look forwards to hearing from you.
     
  29. Sander1991

    Sander1991

    Joined:
    Aug 25, 2014
    Posts:
    162
    @Duffer123
    Sorry that I write back so late. It is running with his own "databases". It is using the unity intern assetdatabases. It does not save the items after you "quit" the game. That is something which is planned but I can not create it at the moment. I am in the learning phase.

    I do not know how easy it is to combine it with SimpleSQL - sorry.

    Yes, there is a Script API and a documentation. I hope I could have helped.
     
  30. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    Thanks. . What about subtypes for items?
     
  31. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    (see above re query on subtypes). Also, does this Asset support Playmaker?
     
  32. Sander1991

    Sander1991

    Joined:
    Aug 25, 2014
    Posts:
    162
    @Duffer123
    What do you mean with subtypes?
    It does not support Playmaker.
     
  33. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    @Sander1991 ,

    So - say Item type, Weapon subtype, Sword subtype of Weapon, 1h Sword subtype of Sword...
     
  34. Recon03

    Recon03

    Joined:
    Aug 5, 2013
    Posts:
    825
    When did this go free and why??
     
  35. Sander1991

    Sander1991

    Joined:
    Aug 25, 2014
    Posts:
    162
  36. Recon03

    Recon03

    Joined:
    Aug 5, 2013
    Posts:
    825
    I understand why it went free, but for those that paid, that can look bad, I would be careful next time is all. I hate seeing assets I paid for go free.. I would go nuts then with this asset maybe another and give for free if you want to give back . Best of Luck ... I would be happy to help in any way I can , I been a UI designer, programmer for 10 years. I did not buy this asset I just always watched it because it was rare there was a good inventory system, I made my own but for others on the asset store it look good for them. that didnt know how... This one had alot of similiar aspects that mine did,,,
     
  37. ionthedev

    ionthedev

    Joined:
    Oct 1, 2012
    Posts:
    1
    I've run into an issue that I don't quiet know how to fix. When I click and drag an item out of a chest storage, the item drops, but it still remains to be in the StorageInventory.

    I have an idea on how to maybe make it work, but I don't know much on how the asset was developed so it will be too risky for me to add; but if you could make it where you drag an item out of the storage inventory and it drops, set the StorageInventory scripts "Storage Items" size to 0.

    If anyone can help me with this problem it would be much appreciated.
     
  38. webik150

    webik150

    Joined:
    Mar 23, 2013
    Posts:
    57
    Hey @Sander1991, just wanted to tell you how great your asset is (will actually tell tomorrow probably). I've only had a quick look so far, but I plan to definitely use this in one way or another. I've been struggling with my own inventory system for few days now, and I feel like it's going nowhere. Tomorrow I'm going to study the source code of this, and I'll try to port it to NGUI (I'll probably rewrite it line by line because they always tell me "you learn by writing").

    Anyway, thank you very much.
     
  39. Feuerwerker

    Feuerwerker

    Joined:
    Jan 6, 2014
    Posts:
    1
    Hi. I have an issue. When I use your InventorySystem, there are 91 errors "The referenced script on this Behavior is missing". Some of this pointed to timers, where the associated script can not be loaded. The other is "
    The referenced script on this Behaviour is missing!
    UnityEngine.Object:Instantiate(GameObject)
    CraftResultSlot:Start() (at Assets/InventoryMaster/Scripts/CraftSystem/CraftResultSlot.cs:21)"

    Has anyone else the same problem? Or can help me?

    (I have unity 5.1.2 free and your version 4.6.8)
     
  40. Sander1991

    Sander1991

    Joined:
    Aug 25, 2014
    Posts:
    162
    @Feuerwerker
    The script which is missing is my fault. If you want you can search for the Item prefab and remove the component. Just delete it and everything is fine.
     
    Tronnyi likes this.
  41. Raziel84

    Raziel84

    Joined:
    Oct 19, 2014
    Posts:
    1
    Thanks for your job! Its excellent! But the item prefab and the hotbar prefab have a referenced script missing.If I delete both references would work? I ask because I delete the references and create an new inventory this gave me error in execution. I am not at my computer right now, but later copied the mistake showed me.
     
  42. Tronnyi

    Tronnyi

    Joined:
    Aug 1, 2015
    Posts:
    2
    Hello @Sander!
    I am currently making a Pseudo2D spcashipshooter with RPG elements and i would lke to use your inventory system. I really like it so far but i am having a view issues. My main problem at the moment is, i cant find a way to access specific Slots of the Equipment Window. i need this, bcause i plan to write some code, that shows weapons in specific slots on my ship.
    So i would want the EquipmentSystem to send a message to my ShipSystem (on Equip), so that my ShipSystem knows: "Slot 2 has a Weapon in it with 2 Damage and 5 Speed" then it triggers and loads the right model in Slot 2 while the other Slots stay unchanged...
    is this possible with your ui-System?
    BTW my scripting knowledge is far inferior to yours, so i hope this isnt a very stupid question.
    Thank you for answering in advance!

    EDIT: later i will also need a vendor-system for my game, so that the player can buy and sell weapons, shields,... i read that you were planning to add that..? can you give me an update on that, would really apprechiate it, thanks!
     
    Last edited: Aug 1, 2015
  43. frodoe7

    frodoe7

    Joined:
    Jul 25, 2014
    Posts:
    37
    the inventory not shown and show this error 6 times :
    Screen position out of view frustum (screen pos 129.000000, 237.000000) (Camera rect 2 2 763 324)
    UnityEditor.DockArea:OnGUI()
     
  44. Tronnyi

    Tronnyi

    Joined:
    Aug 1, 2015
    Posts:
    2
    i dont think i got that error, but it didnt show for me either, what i did was deleting the inventory part from the canvas and loading it again, from this point on it showed.
     
    frodoe7 likes this.
  45. traderain

    traderain

    Joined:
    Jul 7, 2014
    Posts:
    108
    Dear @Sander1991 I am using your asset and it is very awesome.
    • I have a problem that I am stuck with is that I know that the list of items which is in the inventory is the ItemsIninventory in inventory.cs I can add and delete Items but how can I get rid of the default items?
    • One the other hand I would like to ask that do you have an ETA or will you ever make a save method for the inventory because I am at the point where I would need to start programming the saving the inventory and if you would have a working solution it would be really nice.
    • I am getting an error with your scripts:
    • Code (CSharp):
      1. Missing reference
      2. Prefab: Assets/InventoryMaster/Resources/Prefabs/Panel - CraftSystem.prefab
      3. Game Object: Panel - CraftSystem
      4. Component: Inventory
      5. Field: Prefab Slot
    Thanks for your efforts.


    Bence
     
    Last edited: Aug 5, 2015
  46. Wulfara

    Wulfara

    Joined:
    Aug 11, 2015
    Posts:
    40
    Hello. This is my first post at Unity's forum and first of all I want to show you my gratitude for this super-usefull asset.

    In my game you can equip multiple items of the same type at the same time, and it does matter in which slot they're equipped. I've manage to do this with no problem, but now the issue is that when I switch an item from a equipment slot to another of the same type, the inventory doesn't apply the Inventory.ItemEquip and Inventory.UnEquipItem methods. The only way to make it work is to move the item to the Main Inventory and move it back to the new slot of the Equipment.

    Is there any way to capture the switching between slots of the same type in the Equipment Inventory so I can do something at that moment?

    Thank you -and sorry for my poor English- :)
     
  47. Wulfara

    Wulfara

    Joined:
    Aug 11, 2015
    Posts:
    40
    Ok, I've managed to solve it. Maybe someone can be interested on this if they are making games where you want to switch weapons from one hand to another, for example.

    In the Inventory class I've added a new ItemDelegate event for equipment switching. Then, in DragItem class I called this method from the "dragging into equipment system" section where the comment says "items getting swapped if they are the same itemtype" and from "if the slot is empty // is the same type". Finally, in my PlayerInventory class I overloaded this method the same way we do with OnEquipItem and the rest as well. Now I can run any code I need when swapping/moving items between Equipment System slots of same type.

    Thanks Sander1991 for his clear and properly commented code :)
     
    Last edited: Aug 11, 2015
  48. kornstar83

    kornstar83

    Joined:
    Aug 25, 2015
    Posts:
    1
    First off I want to say thanks to Sander1991 for this awesome asset. I recently started adding this inventory system to a scene I have been working on and am loving it so far.

    I am running unity 5.1.3f and had already used the first person controller in the scene before importing the inventory asset. due to the extra gameobjects, components, and scripts needed for the inventory to work I have been forced to use the included firstpersoncontroller which seems to be outdated and lacks many of the newer features like head bob and all that jazz. I am still very new to programming in general and programming with unity so my attempts to combine the new first person controller with the added gameobject references and code have been unsuccessful.

    I'm simply wondering if there is an updated controller script available...
    if yes then where/how do I get it.
    if no, is there any plans on updating this?

    Thanks again for this awesome Asset :)
     
  49. Argument

    Argument

    Joined:
    Jul 5, 2015
    Posts:
    17
    Hello, Sander1991
    I have a question on the Inventory Master - uGUI.
    I try to do your lesson in this video:
    О

    When I'm doing here so
    (watch with 5m 19 s)
    Master system -> Create -> Inventory and Storage, the unit generates an error:
    "UnityException: Tag: Canvas is not defined.
    Inventory.menuItemCreateInventory () (at Assets / InventoryMaster / Scripts / Inventory / Inventory.cs: 213)"

    Is it possible to bypass this error and how can I create an inventory? Will this bug is fixed in versions are following?
    Version yuniti3d: 5.1.2f1
    Version inventory: 4.6.8 (Jul 14, 2015)
    Thank you.
     
  50. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    Hi i managed to get this working with RFPS, just gotta do the weapons now, these 2 scripts will help anyone wanting to use this with RFPS :D
    attach to FPSPlayer
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class jimsRFPSInvInput : MonoBehaviour {
    4.     GameObject _inventory;
    5.     GameObject _tooltip;
    6.     GameObject _character;
    7.     GameObject _dropBox;
    8.     float verticalVelocity = 0;
    9.     GameObject inventory;
    10.     GameObject craftSystem;
    11.     GameObject characterSystem;
    12.     private FPSRigidBodyWalker FPSPlayer = null;
    13.     private SmoothMouseLook InputControl = null;
    14.     void Start()
    15.     {
    16.         FPSPlayer = GameObject.FindObjectOfType(typeof(FPSRigidBodyWalker)) as FPSRigidBodyWalker;
    17.         InputControl = GameObject.FindObjectOfType(typeof(SmoothMouseLook)) as SmoothMouseLook;
    18.          
    19.         if (GameObject.FindGameObjectWithTag("Player") != null)
    20.         {
    21.             PlayerInventory playerInv = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerInventory>();
    22.             if (playerInv.inventory != null)
    23.                 inventory = playerInv.inventory;
    24.             if (playerInv.craftSystem != null)
    25.                 craftSystem = playerInv.craftSystem;
    26.             if (playerInv.characterSystem != null)
    27.                 characterSystem = playerInv.characterSystem;
    28.         }
    29.     }
    30.     void Update()
    31.     {
    32.         if (!lockMovement())
    33.         {                
    34.             Screen.lockCursor = true;
    35.             FPSPlayer.enabled = true;
    36.             InputControl.enabled = true;
    37.         }
    38.         else
    39.         {
    40.             Screen.lockCursor = false;
    41.             FPSPlayer.enabled = false;
    42.             InputControl.enabled = false;
    43.         }
    44.     }
    45.     bool lockMovement()
    46.     {
    47.         if (inventory != null && inventory.activeSelf)
    48.             return true;
    49.         else if (characterSystem != null && characterSystem.activeSelf)
    50.             return true;
    51.         else if (craftSystem != null && craftSystem.activeSelf)
    52.             return true;
    53.         else
    54.             return false;
    55.     }
    56. }
    and now replace the PlayerInventory script with this
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. using UnityEngine.EventSystems;
    5. public class PlayerInventory : MonoBehaviour
    6. {
    7.     public GameObject inventory;
    8.     public GameObject characterSystem;
    9.     public GameObject craftSystem;
    10.     private Inventory craftSystemInventory;
    11.     private CraftSystem cS;
    12.     private Inventory mainInventory;
    13.     private Inventory characterSystemInventory;
    14.     private Tooltip toolTip;
    15.     private InputManager inputManagerDatabase;
    16.     private FPSPlayer fpsPlayer;
    17.     private Transform myTransform;
    18.  
    19.     int normalSize = 3;
    20.     public void OnEnable()
    21.     {
    22.         Inventory.ItemEquip += OnBackpack;
    23.         Inventory.UnEquipItem += UnEquipBackpack;
    24.         Inventory.ItemEquip += OnGearItem;
    25.         Inventory.ItemConsumed += OnConsumeItem;
    26.         Inventory.UnEquipItem += OnUnEquipItem;
    27.         Inventory.ItemEquip += EquipWeapon;
    28.         Inventory.UnEquipItem += UnEquipWeapon;
    29.     }
    30.     public void OnDisable()
    31.     {
    32.         Inventory.ItemEquip -= OnBackpack;
    33.         Inventory.UnEquipItem -= UnEquipBackpack;
    34.         Inventory.ItemEquip -= OnGearItem;
    35.         Inventory.ItemConsumed -= OnConsumeItem;
    36.         Inventory.UnEquipItem -= OnUnEquipItem;
    37.         Inventory.UnEquipItem -= UnEquipWeapon;
    38.         Inventory.ItemEquip -= EquipWeapon;
    39.     }
    40.     void EquipWeapon(Item item)
    41.     {
    42.         if (item.itemType == ItemType.Weapon)
    43.         {
    44.             //add the weapon if you unequip the weapon
    45.         }
    46.     }
    47.     void UnEquipWeapon(Item item)
    48.     {
    49.         if (item.itemType == ItemType.Weapon)
    50.         {
    51.             //delete the weapon if you unequip the weapon
    52.         }
    53.     }
    54.     void OnBackpack(Item item)
    55.     {
    56.         if (item.itemType == ItemType.Backpack)
    57.         {
    58.             for (int i = 0; i < item.itemAttributes.Count; i++)
    59.             {
    60.                 if (mainInventory == null)
    61.                     mainInventory = inventory.GetComponent<Inventory>();
    62.                 mainInventory.sortItems();
    63.                 if (item.itemAttributes[i].attributeName == "Slots")
    64.                     changeInventorySize(item.itemAttributes[i].attributeValue);
    65.             }
    66.         }
    67.     }
    68.     void UnEquipBackpack(Item item)
    69.     {
    70.         if (item.itemType == ItemType.Backpack)
    71.             changeInventorySize(normalSize);
    72.     }
    73.     void changeInventorySize(int size)
    74.     {
    75.         dropTheRestItems(size);
    76.         if (mainInventory == null)
    77.             mainInventory = inventory.GetComponent<Inventory>();
    78.         if (size == 3)
    79.         {
    80.             mainInventory.width = 3;
    81.             mainInventory.height = 1;
    82.             mainInventory.updateSlotAmount();
    83.             mainInventory.adjustInventorySize();
    84.         }
    85.         if (size == 6)
    86.         {
    87.             mainInventory.width = 3;
    88.             mainInventory.height = 2;
    89.             mainInventory.updateSlotAmount();
    90.             mainInventory.adjustInventorySize();
    91.         }
    92.         else if (size == 12)
    93.         {
    94.             mainInventory.width = 4;
    95.             mainInventory.height = 3;
    96.             mainInventory.updateSlotAmount();
    97.             mainInventory.adjustInventorySize();
    98.         }
    99.         else if (size == 16)
    100.         {
    101.             mainInventory.width = 4;
    102.             mainInventory.height = 4;
    103.             mainInventory.updateSlotAmount();
    104.             mainInventory.adjustInventorySize();
    105.         }
    106.         else if (size == 24)
    107.         {
    108.             mainInventory.width = 6;
    109.             mainInventory.height = 4;
    110.             mainInventory.updateSlotAmount();
    111.             mainInventory.adjustInventorySize();
    112.         }
    113.     }
    114.     void dropTheRestItems(int size)
    115.     {
    116.         if (size < mainInventory.ItemsInInventory.Count)
    117.         {
    118.             for (int i = size; i < mainInventory.ItemsInInventory.Count; i++)
    119.             {
    120.                 GameObject dropItem = (GameObject)Instantiate(mainInventory.ItemsInInventory[i].itemModel);
    121.                 dropItem.AddComponent<PickUpItem>();
    122.                 dropItem.GetComponent<PickUpItem>().item = mainInventory.ItemsInInventory[i];
    123.                 dropItem.transform.localPosition = GameObject.FindGameObjectWithTag("Player").transform.localPosition;
    124.             }
    125.         }
    126.     }
    127.     void Start()
    128.     {
    129.         fpsPlayer = GetComponentInChildren<FPSPlayer>();
    130.         if (inputManagerDatabase == null)
    131.             inputManagerDatabase = (InputManager)Resources.Load("InputManager");
    132.         if (craftSystem != null)
    133.             cS = craftSystem.GetComponent<CraftSystem>();
    134.         if (GameObject.FindGameObjectWithTag("Tooltip") != null)
    135.             toolTip = GameObject.FindGameObjectWithTag("Tooltip").GetComponent<Tooltip>();
    136.         if (inventory != null)
    137.             mainInventory = inventory.GetComponent<Inventory>();
    138.         if (characterSystem != null)
    139.             characterSystemInventory = characterSystem.GetComponent<Inventory>();
    140.         if (craftSystem != null)
    141.             craftSystemInventory = craftSystem.GetComponent<Inventory>();
    142.     }
    143.     void UpdateHUDBar()
    144.     {
    145.         if (fpsPlayer.healthGuiObjInstance != null) {
    146.             foreach (var health in fpsPlayer.healthGuiObjInstance.GetComponentsInChildren<HealthText>()) {
    147.                 health.healthGui = Mathf.FloorToInt(fpsPlayer.hitPoints);
    148.             }
    149.         }
    150.         if (fpsPlayer.hungerGuiObjInstance != null) {
    151.             foreach (var hunger in fpsPlayer.hungerGuiObjInstance.GetComponentsInChildren<HungerText>()) {
    152.                 hunger.hungerGui = Mathf.FloorToInt(fpsPlayer.hungerPoints);
    153.             }
    154.         }
    155.         if (fpsPlayer.thirstGuiObjInstance != null) {
    156.             foreach (var thirst in fpsPlayer.thirstGuiObjInstance.GetComponentsInChildren<ThirstText>()) {
    157.                 thirst.thirstGui = Mathf.FloorToInt(fpsPlayer.thirstPoints);
    158.             }
    159.         }
    160.     }
    161.      public void OnConsumeItem(Item item)
    162.     {
    163.         for (int i = 0; i < item.itemAttributes.Count; i++) {
    164.             if (item.itemAttributes [i].attributeName == "Health") {
    165.                 if (fpsPlayer.hitPoints < fpsPlayer.maximumHitPoints) {
    166.                     fpsPlayer.HealPlayer (item.itemAttributes [i].attributeValue);
    167.                 }
    168.             }
    169.             if (item.itemAttributes [i].attributeName == "Hunger") {
    170.                 if (fpsPlayer.hungerPoints - item.itemAttributes [i].attributeValue > 0.0) {
    171.                     fpsPlayer.UpdateHunger (-item.itemAttributes [i].attributeValue);
    172.                 } else {
    173.                     fpsPlayer.UpdateHunger (-fpsPlayer.hungerPoints);
    174.                 }
    175.             }
    176.             if (item.itemAttributes [i].attributeName == "Thirst") {
    177.                 if (fpsPlayer.thirstPoints > 0.0f && fpsPlayer.usePlayerThirst) {
    178.                      
    179.                     if (fpsPlayer.thirstPoints - item.itemAttributes [i].attributeValue > 0.0) {
    180.                         fpsPlayer.UpdateThirst (-item.itemAttributes [i].attributeValue);
    181.                     } else {
    182.                         fpsPlayer.UpdateThirst (-fpsPlayer.thirstPoints);
    183.                     }
    184.                 }
    185.             }
    186.         }
    187.            UpdateHUDBar();
    188.     }
    189.     public void OnGearItem(Item item)
    190.     {
    191.         for (int i = 0; i < item.itemAttributes.Count; i++)
    192.         {
    193.             if (item.itemAttributes[i].attributeName == "Health")
    194.                 fpsPlayer.maximumHitPoints += item.itemAttributes[i].attributeValue;
    195.             if (item.itemAttributes[i].attributeName == "Hunger")
    196.                 fpsPlayer.hungerPoints += item.itemAttributes[i].attributeValue;
    197.             if (item.itemAttributes[i].attributeName == "Thirst")
    198.                 fpsPlayer.thirstPoints += item.itemAttributes[i].attributeValue;    
    199.         }
    200.         {
    201.             UpdateHUDBar();    
    202.         }
    203.     }
    204.     public void OnUnEquipItem(Item item)
    205.     {
    206.         for (int i = 0; i < item.itemAttributes.Count; i++)
    207.         {
    208.             if (item.itemAttributes[i].attributeName == "Health")
    209.                 fpsPlayer.maximumHitPoints -= item.itemAttributes[i].attributeValue;
    210.             if (item.itemAttributes[i].attributeName == "Hunger")
    211.                 fpsPlayer.hungerPoints -= item.itemAttributes[i].attributeValue;
    212.             if (item.itemAttributes[i].attributeName == "Thirst")
    213.                 fpsPlayer.thirstPoints -= item.itemAttributes[i].attributeValue;
    214.         }
    215.         {
    216.             UpdateHUDBar();    
    217.         }
    218.     }
    219.  
    220.     void Update()
    221.     {
    222.         if (Input.GetKeyDown(inputManagerDatabase.CharacterSystemKeyCode))
    223.         {
    224.             if (!characterSystem.activeSelf)
    225.             {
    226.                 characterSystemInventory.openInventory();
    227.             }
    228.             else
    229.             {
    230.                 if (toolTip != null)
    231.                     toolTip.deactivateTooltip();
    232.                 characterSystemInventory.closeInventory();
    233.             }
    234.         }
    235.         if (Input.GetKeyDown(inputManagerDatabase.InventoryKeyCode))
    236.         {
    237.             if (!inventory.activeSelf)
    238.             {
    239.                 mainInventory.openInventory();
    240.             }
    241.             else
    242.             {
    243.                 if (toolTip != null)
    244.                     toolTip.deactivateTooltip();
    245.                 mainInventory.closeInventory();
    246.             }
    247.         }
    248.         if (Input.GetKeyDown(inputManagerDatabase.CraftSystemKeyCode))
    249.         {
    250.             if (!craftSystem.activeSelf)
    251.                 craftSystemInventory.openInventory();
    252.             else
    253.             {
    254.                 if (cS != null)
    255.                     cS.backToInventory();
    256.                 if (toolTip != null)
    257.                     toolTip.deactivateTooltip();
    258.                 craftSystemInventory.closeInventory();
    259.             }
    260.         }
    261.     }
    262. }
     
    00Randomgamer00 likes this.