Daily Progress: Creating an Interface to communicate to all panels.
Implementing the program flow, we can either have processInfo() as an abstract class or an interface. An interface may be easier so we’ll create that.
We’ll create a folder in scripts called Interface and then create a script inside of it called IPanel. Best practices say that all Interfaces begin with a capital I.
Unlike regular classes that have the class type, name and then extend from MonoBehaviour, Interfaces are a public name and then type Interface:
As stated a few articles back, an Interface is a contract for classes. When it’s implemented, the Interface gives the class a set of rules it MUST comply with. In our case, we want our panels to always have a ProcessInfo() function, so we’ll put that into our interface.
We’re good to go! Now we just need to attach this interface to all of our panel scripts! We do this by just adding a comma and placing it next to the Monobehaviour extension.
Now that Ipanel is attached to this panels script, we must have the ProcessInfo() function to comply with Ipanel, which it does, so we’re good!
Note: You can have multiple interfaces in any script, unlike extensions where you’re limited to just one.
Speaking of just one, the reason we’re doing this is so the UIManager won’t be cluttered with every panels specific interface. While we’ll have references to each panel, we’ll communicate with every one with a single IPanel interface!