Interfaces
Unity interfaces was a feature I underappreciated for years. Coming from a traditional C# background, I was writing my own way to interface with different types of Unity Monobehaviors. However, once it came time to intermingle this with the Unity inspector, it was nothing but headaches.
Originally, I was manually running specific commands from a MonoBehavior reference like so:
Then:
This requires multiple direct references to the MonoBehavior. While this is a fine approach for what it was originally for, there is a much better implementation using Interfaces.
For instance, while working with game commands embedded within a string
i.e.
it quickly became a pain to deal with multiple edge cases.
The solution to this was an Interface like so:
Then creating multiple classes containing the implementation for each form of command:
This is a much cleaner way to handle inheritance.
Additionally the Interface class can contain other useful data-types that need to be re-used. Such as enums, static references, and generalized variables.