{"id":13663383,"url":"https://github.com/FarrokhGames/Inventory","last_synced_at":"2025-04-25T13:33:03.054Z","repository":{"id":39620057,"uuid":"109060799","full_name":"FarrokhGames/Inventory","owner":"FarrokhGames","description":"A Diablo 2-style inventory system for Unity3D","archived":false,"fork":false,"pushed_at":"2024-03-11T04:54:13.000Z","size":4059,"stargazers_count":257,"open_issues_count":4,"forks_count":31,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-11-10T19:35:45.537Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FarrokhGames.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-31T22:55:22.000Z","updated_at":"2024-11-04T14:14:00.000Z","dependencies_parsed_at":"2024-08-02T05:27:56.962Z","dependency_job_id":null,"html_url":"https://github.com/FarrokhGames/Inventory","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FarrokhGames%2FInventory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FarrokhGames%2FInventory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FarrokhGames%2FInventory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FarrokhGames%2FInventory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FarrokhGames","download_url":"https://codeload.github.com/FarrokhGames/Inventory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250825189,"owners_count":21493407,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T05:02:26.052Z","updated_at":"2025-04-25T13:32:58.038Z","avatar_url":"https://github.com/FarrokhGames.png","language":"C#","readme":"## A Diablo 2-style inventory system for Unity3D\n\n\u003cimg src=\"Documentation/inventory1.gif?raw=true\" alt=\"The Inventory\" width=\"640px\" height=\"512px\"/\u003e\n\n## Table of Contents\n- \u003ca href=\"#features\"\u003eFeatures\u003c/a\u003e\n- \u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e\n- \u003ca href=\"example\"\u003eExample\u003c/a\u003e\n- \u003ca href=\"#documentation\"\u003eDocumentation\u003c/a\u003e\n  - \u003ca href=\"#gettingstarted\"\u003eGetting Started\u003c/a\u003e\n  - \u003ca href=\"#theinventory\"\u003eThe Inventory\u003ca\u003e\n  - \u003ca href=\"#items\"\u003eItems\u003ca\u003e\n  - \u003ca href=\"#rendering\"\u003eRendering the Inventory\u003ca\u003e\n  - \u003ca href=\"#interacting\"\u003eInteracting with the Inventory\u003ca\u003e\n  - \u003ca href=\"#otherfiles\"\u003eOther files included\u003ca\u003e\n- \u003ca href=\"#license\"\u003eLicense\u003c/a\u003e\n\n---\n\n## \u003ca id=\"features\"\u003e\u003c/a\u003eFeatures\n- ```Resize``` at runtime, dropping what no longer fits.\n- ```Add/Remove``` and check if an item fits from code.\n- ```Equipment slots``` for all your RPG needs.\n- ```Custom shapes``` for each item.\n- Rearrange items by ```draggin and dropping```, with visual feedback.\n- ```Move items between inventories```.\n- Remove items by ```dropping``` them outside the inventory.\n- Easily add ```custom graphics``` and change the size of your inventory.\n- Supports ```scaled canvases```.\n- Tested thoroughly with over ```75 Unit Tests```, and profiled using the Unity Profiler.\n- Tested using all types of ```Canvas render modes``` (Screen Space Overlay, Screen Space Camera and World Space)\n\n---\n\n## \u003ca id=\"installation\"\u003e\u003c/a\u003eInstallation\nSimply copy the folder \"```Packages/FarrokGames.Inventory```\" into your own projects packages folder and you're good to go. Optionally, you can add the folder \"```Assets/Example```\" to get started right away.\n\n---\n\n## \u003ca id=\"example\"\u003e\u003c/a\u003eExample\nA fully functional example is included with this reposetory and can be found in the folder \"```Assets/Example```\". \n\n- ```Inventory Overlay.scene``` - the Unity Scene that contains an example using the Canvas render mode of Screen Space Overlay.\n- ```Inventory Camera.scene``` - the Unity Scene that contains an example using the Canvas render mode of Screen Space Camera.\n- ```Inventory World Space.scene``` - the Unity Scene that contains an example using the Canvas render mode of World Space.\n- ```Inventory.png``` - includes all artwork used in the example.\n- ```ItemDefinition.cs``` - a ```ScriptableObject``` implemetation of ```IInventoryItem```.\n- ```SizeInventoryExample.cs``` - a ```MonoBehaviour``` that creates and connects an Inventory with a Renderer, and fills it with items.\n- ```Items-folder``` - Contains the ```ItemDefinitions``` used in the example.\n\n---\n\n## \u003ca id=\"documentation\"\u003e\u003c/a\u003eDocumentation\nBelow you can find documentation of various parts of the system. You are encouraged to look through the code, where more in-depth code docs can be found.\n\n---\n\n### \u003ca id=\"gettingstarted\"\u003e\u003c/a\u003eGetting Started\nCreating a new inventory is simple. Remember that the inventory system rests within its own namespace, so don't forget to add ```using FarrokhGames.Inventory```.\n```cs\nvar inventory = new InventoryManager(8, 4); // Creates an inventory with a width of 8 and height of 4\n```\n\n---\n\n### \u003ca id='theinventory'\u003e\u003c/a\u003eThe Inventory\nBelow is a list of actions methods and getters within ```InventoryManager.cs```.\n```cs\n/// \u003csummary\u003e\n/// Invoked when an item is added to the inventory\n/// \u003c/summary\u003e\nAction\u003cIInventoryItem\u003e onItemAdded { get; set; }\n\n/// \u003csummary\u003e\n/// Invoked when an item was not able to be added to the inventory\n/// \u003c/summary\u003e\nAction\u003cIInventoryItem\u003e onItemAddedFailed { get; set; }\n\n/// \u003csummary\u003e\n/// Invoked when an item is removed to the inventory\n/// \u003c/summary\u003e\nAction\u003cIInventoryItem\u003e onItemRemoved { get; set; }\n\n/// \u003csummary\u003e\n/// Invoked when an item is removed from the inventory and should be placed on the ground.\n/// \u003c/summary\u003e\nAction\u003cIInventoryItem\u003e onItemDropped { get; set; }\n\n/// \u003csummary\u003e\n/// Invoked when an item was unable to be placed on the ground (most likely to its canDrop being set to false)\n/// \u003c/summary\u003e\nAction\u003cIInventoryItem\u003e onItemDroppedFailed { get; set; }\n\n/// \u003csummary\u003e\n/// Invoked when the inventory is rebuilt from scratch\n/// \u003c/summary\u003e\nAction onRebuilt { get; set; }\n\n/// \u003csummary\u003e\n/// Invoked when the inventory changes its size\n/// \u003c/summary\u003e\nAction onResized { get; set; }\n\n/// \u003csummary\u003e\n/// The width of the inventory\n/// \u003c/summary\u003e\nint width { get; }\n\n/// \u003csummary\u003e\n/// The height of the inventory\n/// \u003c/summary\u003e\nint height { get; }\n\n/// \u003csummary\u003e\n/// Sets a new width and height of the inventory\n/// \u003c/summary\u003e\nvoid Resize(int width, int height);\n\n/// \u003csummary\u003e\n/// Returns all items inside this inventory\n/// \u003c/summary\u003e\nIInventoryItem[] allItems { get; }\n\n/// \u003csummary\u003e\n/// Returns true if given item is present in this inventory\n/// \u003c/summary\u003e\nbool Contains(IInventoryItem item);\n\n/// \u003csummary\u003e\n/// Returns true if this inventory is full\n/// \u003c/summary\u003e\nbool isFull { get; }\n\n/// \u003csummary\u003e\n/// Returns true if its possible to add given item\n/// \u003c/summary\u003e\nbool CanAdd(IInventoryItem item);\n\n/// \u003csummary\u003e\n/// Add given item to the inventory. Returns true\n/// if successful\n/// \u003c/summary\u003e\nbool TryAdd(IInventoryItem item);\n\n/// \u003csummary\u003e\n/// Returns true if its possible to add item at location\n/// \u003c/summary\u003e\nbool CanAddAt(IInventoryItem item, Vector2Int point);\n\n/// \u003csummary\u003e\n/// Tries to add item att location and returns true if successful\n/// \u003c/summary\u003e\nbool TryAddAt(IInventoryItem item, Vector2Int point);\n\n/// \u003csummary\u003e\n/// Returns true if its possible to remove this item\n/// \u003c/summary\u003e\nbool CanRemove(IInventoryItem item);\n\n/// \u003csummary\u003e\n/// Returns true ifits possible to swap this item\n/// \u003c/summary\u003e\nbool CanSwap(IInventoryItem item);\n\n/// \u003csummary\u003e\n/// Removes given item from this inventory. Returns\n/// true if successful.\n/// \u003c/summary\u003e\nbool TryRemove(IInventoryItem item);\n\n/// \u003csummary\u003e\n/// Returns true if its possible to drop this item\n/// \u003c/summary\u003e\nbool CanDrop(IInventoryItem item);\n\n/// \u003csummary\u003e\n/// Removes an item from this inventory. Returns true\n/// if successful.\n/// \u003c/summary\u003e\nbool TryDrop(IInventoryItem item);\n\n/// \u003csummary\u003e\n/// Drops all items from this inventory\n/// \u003c/summary\u003e\nvoid DropAll();\n\n/// \u003csummary\u003e\n/// Clears (destroys) all items in this inventory\n/// \u003c/summary\u003e\nvoid Clear();\n\n/// \u003csummary\u003e\n/// Rebuilds the inventory\n/// \u003c/summary\u003e\nvoid Rebuild();\n\n/// \u003csummary\u003e\n/// Get an item at given point within this inventory\n/// \u003c/summary\u003e\nIInventoryItem GetAtPoint(Vector2Int point);\n\n/// \u003csummary\u003e\n/// Returns all items under given rectangle\n/// \u003c/summary\u003e\nIInventoryItem[] GetAtPoint(Vector2Int point, Vector2Int size);\n```\n---\n\n### \u003ca id=\"items\"\u003e\u003c/a\u003eItems\nItems inside the inventory are represented by the IInventoryItem interface. In the included example, this interface is attached to a ```ScritableObject``` making it possible to create, store and change item details in the asset folder.\n```cs\nusing UnityEngine;\nusing FarrokhGames.Inventory;\n\n/// \u003csummary\u003e\n/// ScriptableObject representing an Inventory Item\n/// \u003c/summary\u003e\n[CreateAssetMenu(fileName = \"Item\", menuName = \"Inventory/Item\", order = 1)]\npublic class ItemDefinition : ScriptableObject, IInventoryItem\n{\n    [SerializeField] private Sprite _sprite;\n    [SerializeField] private InventoryShape _shape;\n    [SerializeField] private bool _canDrop;\n\n    public string Name =\u003e return this.name;\n    public Sprite Sprite =\u003e  return _sprite;\n    public InventoryShape Shape =\u003e _shape;\n    public bool canDrop =\u003e _canDrop;\n\n    /// \u003csummary\u003e\n    /// Creates a copy if this scriptable object\n    /// \u003c/summary\u003e\n    public IInventoryItem CreateInstance()\n    {\n        return ScriptableObject.Instantiate(this);\n    }\n}\n```\nThe shape of an item is defined by the serializable ```ItemShape.cs``` class which has a useful property drawer.\n\n\u003cimg src=\"Documentation/shape-property.png?raw=true\" alt=\"Zenject\" width=\"350px\" height=\"75px\"/\u003e\n\n---\n\n### \u003ca id=\"rendering\"\u003e\u003c/a\u003eRendering the Inventory\nThe inventory system comes with a renderer in a MonoBehaviour called ```InventoryRenderer.cs```.\n\n\u003cimg src=\"Documentation/renderer.png?raw=true\" alt=\"Zenject\" width=\"338px\" height=\"486px\"/\u003e\n\nSimply add this to a ```GameObject``` within your ```Canvas```, and connect it to an inventory using the following code.\n\n```cs\n/// \u003csummary\u003e\n/// Set what inventory to use when rendering\n/// \u003c/summary\u003e\n/// \u003cparam name=\"inventory\"\u003eInventory to use\u003c/param\u003e\npublic void SetInventory(InventoryManager inventory);\n```\n\n*Please see the image at the top of this document as an example of how the rendering looks*\n\n---\n\n### \u003ca id=\"interacting\"\u003e\u003c/a\u003eInteracting with the Inventory\nTo enable interactions (drag and drop), add ```InventoryController.cs``` to the same ```GameObject``` as your renderer.\n\n---\n\n### \u003ca id=\"otherfiles\"\u003e\u003c/a\u003eOther files included\nBesides the actual inventory, there are sipport-classes included in the reposetory.\n\n- ```Pool.cs``` - A generic pool of objects that can be retrieved and recycled without invoking additional allocations. Used by the ```Renderer``` to pool sprites.\n\n**You are free to use these** support-classes under the same license, and their ```Unit Tests``` are included.\n\n---\n\n## \u003ca id=\"license\"\u003e\u003c/a\u003eLicense\n    MIT License\n\n    Copyright (c) 2020 Farrokh Games\n\n    Permission is hereby granted, free of charge, to any person obtaining a copy\n    of this software and associated documentation files (the \"Software\"), to deal\n    in the Software without restriction, including without limitation the rights\n    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n    copies of the Software, and to permit persons to whom the Software is\n    furnished to do so, subject to the following conditions:\n\n    The above copyright notice and this permission notice shall be included in all\n    copies or substantial portions of the Software.\n\n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n    SOFTWARE.\n","funding_links":[],"categories":["C\\#","Open Source Repositories","Open Source Packages"],"sub_categories":["Gameplay"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFarrokhGames%2FInventory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFarrokhGames%2FInventory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFarrokhGames%2FInventory/lists"}