Syntax Transformer
Unity Playworks Plugin uses Bridge.NET to compile C# code into JavaScript. Bridge.NET is a powerful tool that allows developers to write C# code and compile it into JavaScript. However, Bridge.NET does not support the latest C# features. To overcome this limitation, Unity Playworks Plugin has developed a tool called the Syntax Transformer.
The Syntax Transformer is a tool that allows developers to use the latest C# features in their Unity Playworks Plugin projects. The tool transforms the latest C# syntax into an older version of C# that is supported by Bridge.NET. This allows developers to take advantage of the latest C# features without worrying about compatibility issues.
C# features: Bridge.NET vs. Bridge.NET with Syntax Transformer
Feature | Bridge | Bridge + SyntaxTransformer |
---|---|---|
C# 7.0-7.3 features | ||
Out variables | Supported | Supported |
Tuples and deconstruction | Unsupported | Supported |
Pattern matching | Supported | Supported |
Local functions | Unsupported | Supported |
Expanded expression bodied members | Supported | Supported |
Ref locals and returns | Supported | Supported |
Discards | Unsupported | Supported |
Throw expressions | Unsupported | Supported |
default literal expressions | Unsupported | Supported |
in modifier on parameters | Supported | Supported |
Non-trailing named arguments | Supported | Supported |
== and != with tuple types | Supported | Supported |
C# 8.0 features | ||
Null-coalescing assignment | Unsupported | Supported |
Pattern-matching enhancements | Unsupported | Unsupported |
Readonly members | Unsupported | Supported |
Static local functions | Unsupported | Supported |
Using declarations | Unsupported | Supported |
Enhancement of interpolated verbatim strings | Unsupported | Supported |
Disposable ref structs | Unsupported | Unsupported |
Stackalloc in nested expressions | Unsupported | Unsupported |
Unmanaged constructed types | Unsupported | Unsupported |
Default interface methods | Unsupported | Unsupported |
Indices and ranges | Unsupported | Unsupported |
Asynchronous streams | Unsupported | Unsupported |
Asynchronous disposable | Unsupported | Unsupported |
C# 9.0 features | ||
Lambda discard parameters | Unsupported | Supported |
Target-typed new | Unsupported | Supported |
Pattern-matching enhancements | Unsupported | Unsupported |
Static anonymous functions | Unsupported | Supported |
Lambda discard parameters | Unsupported | Supported |
Target-typed conditional expression | Unsupported | Unsupported |
Local function attribute | Unsupported | Unsupported |
Native-sized integers | Unsupported | Unsupported |
Skip localsinit | Unsupported | Unsupported |
Records | Unsupported | Unsupported |
Init-only setters | Unsupported | Unsupported |
Covariant returns | Unsupported | Unsupported |
Top-level statements | Unsupported | Unsupported |
Function Pointers | Unsupported | Unsupported |
Syntax Transformer: How it works
Syntax Transformer is integrated into the Unity Playworks Plugin and runs automatically when you compile your project. The Syntax Transformer is designed to be transparent and seamless, so you don't need to worry about configuring or using it. When you compile your project, the Syntax Transformer all the C# sources are copied into a temporary directory (LunaTemp/stage3/processed-scripts
) and transformed into an older version of C# that is supported by Bridge.NET. The transformed sources are then compiled into JavaScript using Bridge.NET.
Syntax Transformer: Troubleshooting
If Syntax Transformer cannot process your C# source, it will issue an LP2008 error in the project diagnostics. In this case, the compilation process will continue, but you will be limited to using C# features up to version 7.3. Please report the issue to the Unity Playworks Plugin team so that we can investigate and fix it.