Question by
gasparerr · Jun 02, 2021 at 03:04 AM ·
editorscriptableobjectinventory system
How to apply composition to ScriptableObjects
Hey guys, my question is simple. How can I compose ScriptableObjects for my inventory system?
I tried quite a few different approaches and none of them worked, how would you approach it? For clarity here is some code representing the idea
public class Item{
public string Name;
}
public class Consumable{
public bool Consumed;
}
public class Equipment{
public bool Equiped;
}
public class ConsumableEquipmentItem : ScriptableObject {
// ??? how to combine the previous 3 classes into a serializable scriptable object?
}
Some things I tried
At first I wanted to use the decorator pattern to define some simple decorators like "ConsumableDecorator", "EquipableDecorator" and stuff like that.
First I found it impossible because of not being able to use the scriptable object constructor and then I tried composing it at Awake and storing a serializable field. But it wasn't possible to serialize properly.
Comment