Classifying item types without inheritance
I have a system for keeping track of items in my game. Here is the base class for items:
[System.Serializable]
public class Item : IComparable<Item>
{
public string name;
public GameObject model;
public int CompareTo(Item other)
{
return name.CompareTo(other.name);
}
}
It's worth noting that different aspects of my game inherit the item class, adding additional pieces of information that they need.
I am starting to implement a sort of metadata system so that crafting systems can use any such item as long as its classified a 'rock'. The issue I'm having is that should an object be a 'food', I need to be able to give it a food and water value, or if it's a building material I need to assign its strength.
To make things worse on myself, I don't want to use inheritance. I would like objects to be able to be both edible and a building material, for example. Additionally, my current code base relies on inheriting the base item class.
I am thinking along the lines of JSON, for example:
stats: {
edible: {
food: 6,
water: 3
}
weapon: {
damage: 3
}
}
but I should admit forthright that I don't properly understand JSON or have any idea how to replicate it.
I'm almost convinced the solution is far simpler than I think it is, I just can't seem to figure it out. If any of you kind strangers could shed some light on this that would be outstanding.
Your answer
![](https://koobas.hobune.stream/wayback/20220613024529im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Whats the best option for an item database for a single player game 2 Answers
How to add item to inventory with these scripts 0 Answers
How to handle inventory in 2d game, via xml, no game objects (inheritance? interface?) 0 Answers
Security with android 1 Answer
POST request to RESTful APIs 0 Answers