- Home /
Inventory Help
I've been silently searching for several weeks now in an effort to learn how to accomplish what I'm trying to do with an Inventory system on my own, but I've decided to try and ask for some guidance. I've done thorough searches using Google and the native searching capabilities of the site, but I haven't quite found a script that accomplishes what I have in mind. I've noticed that detail is key when asking for help around here, so I'll try to be as specific as possible.. starting with a description of my game project:
"The game is predominantly action-based, using tool items to both explore areas around the village and to tend crops on soil plots. The player must build relations with the villagers in order to glean information concerning a mystery, and does this via conversation, gifts, and events. There are RPG elements, but the genre would be better classed as a casual/action game in a fantasy setting."
I've learned quite a bit about the value of prefabs from looking into some available inventory scripts to see how the item database is managed, so I have put together a script with the following vars to set via the inspector for each item:
class Item {
var name : String;
var icon : Texture; // 50x50 icon texture that represents the item
var type : String; // Set whether the item is a tool, ingredient, dish, etc.
var mesh : Transform;
var consumable : Boolean;
var giftable : Boolean; // Flags if the item is able to be given to an NPC
var sellValue : int;
var buyValue : int;
var regenValue : float; // If consumable, sets the percentage of recovery
var index : int; // Means of grouping like items via numbers
var description : Texture; // 2d Texture used to supply layer with item information
}
I'm aiming for a predominantly mouse-based control system in the game overall, but the inventory is my primary concern. The gist of the controls are summarized here:
// Slots should be arranged in a 6x4 grid amounting to a total of 24 slots; 6 columns, 4 rows.
// The Inventory can be opened or closed by clicking on an HUD icon or by pressing the I key.
// Items within the Inventory can be reorganized by dragging and dropping.
// Items are used and tools are equipped by double-clicking.
// Delete items from the inventory by dragging and dropping the item to a delete icon.
// Items can be selected and information viewed by clicking once on the item.
// Items CANNOT be dragged and dropped outside of the inventory, only reorganized within the pane.
Looking into Unity's documentation and the API, I managed to create a series of three GUI Texture buttons as a temporary means of triggering the game menu scripts, but that is as far as I was able to get without now seeking some help. I've grabbed a few books on C#, but for the time being I feel most comfortable with Unityscript's syntax.
This is, so far, the largest hurdle in my learning experience so far with Unity, and I'm very much impressed with the available documentation! I come from an artistic background, but have always enjoyed designing frameworks for my ideas and dabbling in Ruby when my game project was still based in the RPG Maker XP engine.
You know, this is another one of those times when I would point you towards my inventory script , but you are asking for a bit more functionality here! The dragging and dropping inside of a 6x4 grid should be achieveable by reworking a few specifics of how the GUI parts of it works, and as for the rest of it you just need to add in more features to the 'Item' interface to allow for buy and sell prices etc. Unfortunately, my script is in C#, but it's not that hard to follow. I'm actually not sure how I would do it in javascript.
Thanks for the reply, syclamoth! I was actually looking over your script while I was waiting for a response and noticed that it was in C#, which handles Arrays and other features a bit differently than Unity's Javascript. And I also remember reading somewhere that serialization is only truly possible in C#, which has me wishing I had a better grasp on the syntax. I think I'll plug your script in and give it a run, though, since it's a well-written script.
EDIT// I'm getting an error at (60,23) "The type or namespace name '$$anonymous$$onoBehaviour' could not be found."
You need to put in 'using UnityEngine' at the top. Along with 'using System.Collections.Generic' and 'using System.Collections'.
Edited to include those lines, but I'm receiving other errors that I'm not sure how to fix -- mostly due to my inexperience with C#. I did some additional searching and I'm looking into Little Angel's "Inventory $$anonymous$$anager 2.0", which seems to implement what I'm after for a pretty reasonable price. Have you had experience with this system, syclamoth?
As for the errors I've received with the script:
(26, 31) : Operator '+' cannot be applied to operands of type 'float' and 'method group'.
(49, 21) : Cannot implicitly convert type 'UnityEngine.Texture2d[]' to 'UnityEngine.Texture2d'.
(50, 41) : The best overloaded method match for 'UnityEngine.GUILayout.SelectionGrid(int, string[], int, params UnityEngine.GUILayotOption[])' has some invalid arguments.
(50, 41) : Argument '#2' cannot convert 'UnityEngine.Texture2d' expression to type 'string[]'.
We have an inventory system for our RPG. Sadly, I can't share that with you but I recommend checking out EZGUI with which it is built. EZGUI is available in the asset store and will save you a lot of work and speed up your GUI rendering too!
Our Inventory http://forum.anbsoft.com/viewtopic.php?f=17&t=2440
Your answer
Follow this Question
Related Questions
Remove Items and Item Tooltips 0 Answers
Cropped Label Problem - Big Font - Unity3D 1 Answer
OnGUI and Event.current 2 Answers
How To Make A Numeric Inventory System? 0 Answers