added more info to interfaces, explaining their casting ability |
m added page section title |
||
Line 1: | Line 1: | ||
Interface types are [[Reference Type|reference types]] that don't refer to a specific [[:Category:Type|Type]], but a [https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interface 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. | Interface types are [[Reference Type|reference types]] that don't refer to a specific [[:Category:Type|Type]], but a [https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interface 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. | 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. | ||
Revision as of 17:59, 9 February 2024
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.
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.