Items/Inventory system using Scriptable Objects and Composition instead Inheritance.
Hello! I'm trying to create an Item/Inventory System where I can use Scriptable objects to hold the Data and Monobehaviours to hold the Logic, but I'm also looking to avoid to use inheritance on the Logic side, to avoid to load a lot of useless functions on some specific items. Is there any common pattern to use composition instead of inheritance to some similar use?
ItemData
Public Class ItemData: ScriptableObject
{
public string name;
public string description;
public GameObject prefab;
}
CoinData
Public Class CoinData:ItemData
{
public int value;
}
Coin Monobehaviour
Public Class Coin:Monobehaviour
{
public CoinData coinData;
// How do I use Composition instead Inheritance to get the functions
//from another class?
}
Item Logics
Now I want to know how can I use Composition, to use the functions of the following class, without becoming it in a static Class:
Public Class ItemsLogics: Monobehaviour
{
// I want to "import" functions from this class to composite all the other specific items on the game.
public void AnyFunction()
{
\\anything
}
}
Should I use Interfaces to do that? I'm looking to avoid to inherit a lot of functions that I don't need to use.
$$anonymous$$aybe you could give an example of "a lot of useless functions on some specific items" so then it would be more obvious how to remove the excess?
Your answer
Follow this Question
Related Questions
How do I make a item system with ScriptableObjects where different items can have durability? 1 Answer
How to apply composition to ScriptableObjects 0 Answers
Why is drag and drop not working? 1 Answer
2d mobile Multi Scene inventory 0 Answers
how I can save the data of a list of purchased items ? 2 Answers