Hello!
I often find myself struggling to design code inside of Unity due to the nature of MonoBehaviors, ScriptableObjects, etc being a bit different from standard classes.
To give a specific example of something I am trying to map out right now:
Let’s say in normal C# terms, I have a class called Symbol. Every symbol has a name, a sprite, and an Execute command which differs between symbols. I want to be able to define things like the sprite and name through the editor. I’d love to use something like the command pattern to handle the functionality execution for every different symbol, but that’s where things become confusing for me.
I do not want these symbols to be on GameObjects, because they are moreso just data and instructions. GameObjects will use them, but there logic does not need to exist as its own GameObject in scene. In other words, MonoBehaviours are definitely not what I want. ScriptableObjects almost seem like what I want, they allow me to define values and whatnot through the editor, but if I were to create a symbols class and then derive variations of classes from that class, or just create separate classes and use an interface, it results in a setup that feels awkward to use. I would have to create each script, and then create a singular object for each script after that. I COULD do that, but it just seems kind of clunky and weird to create ScriptableObjects just to create a singular object from each of them so that I can define the stats.
I just wonder if there’s a better way and I just don’t know what it is. Hoping someone has a better idea. I could of course also just make a ScriptableObject and throw a switch statement in the execute function with all the logic, but that just feels like taking the easy way out haha. I am trying to learn to use more advanced and scalable patterns in Unity. Maybe I could create normal classes for each of the different symbols with a common interface, and then make a singular ScriptableObject with a switch statement that chooses a class to use based on some Enum designation on the object itself? Still not what I’d call elegant lol.
Thanks!