Interface Type

From Resonite Wiki
Revision as of 17:59, 9 February 2024 by 989onan (talk | contribs) (added page section title)

Interface types are reference types that don't refer to a specific Type, but a C# Interface that can be implemented by one or multiple component classes. Interfaces are used to describe a specific common behavior that similar classed may want to implement. Because clases that implement a specific interface are required to implement the methods and properties defined in that interface, they can all be assigned to a variable of the interface type, making them very userful within Resonite.

casting

Interfaces can be casted into a specific variant of what they can possibly wrap, and the cast will try to represent the interface as a non interface type.

For example, you can't cast the contents of an IComponent (interface) storing an ObjectRoot into a CopyGlobalTransform or it will give null. You also can't cast an IButton's contents into a SyncPlayback because a SyncPlayback would never fit under the IButton interface. A SyncPlayback is a playable not a button, essentially.

In C# it is convention to start interface class names with the capital letter 'I'.

Example

An example of an interface type used within Resonite is IButton. It is implemented by multiple button-like components like Button, PhysicalButton and TouchButton. All of those components implement the behavior of a button that can be pressed as defined in IButton. Because of this, you can use either of them as a valid reference to plug into the "Button" input of the Button Events ProtoFlux node, which requires a global of type IButton.