Using ScriptableObject Decorators
As we’ve done with many a chapter throughout our design pattern journey, we’re going to round off the decorator discussion with a little side trip into ScriptableObject
assets (which makes runtime flexibility and scaling exponentially more manageable).
In the Scripts folder, create a new C# script (for the 100th time) named SOData
and update it to match the following code snippet.
If you read Chapter 13, Adding Features with the Visitor Pattern, this should look familiar, because it is! This isn’t the only way to do things in Unity, but since our Component interface has both data and behavior, we’re only splitting out the data into a ScriptableObject
(configurable behaviors in ScriptableObjects
require a ton of extra work and sort of defeat the purpose in the first place). If your Components only store and decorate data values, your ScriptableObject
classes can inherit from the Component interface just fine...