Unity's Roll-A-Ball tutorial implemented in Swift
- Unity 5.4.0f3 to run the project
- RemObjects Fire 8.4.96.2033 (beta) to modify source and game logic DLL
The project leverages Unity's support for managed plugins. This allows usage of DLLs generated by external compilers. To create a DLL, the project uses the RemObjects Elements compiler and their Swift implementation, Silver.
Since Assets/Plugins/GameLogic.dll
is provided in the repo, you should be able to just run
the Unity project as is. I only tested on macOS and iOS however. For iOS, the
game builds but there is no touch input implemented.
In addition to the standard Unity project directories, the GameLogicSolution solution includes GameLogic and UnityAspect projects.
The GameLogic project implements the game logic. Similar to Roll-a-ball-FSharp, the source is a direct translation of the tutorial's C# to Swift. Also, the source is in one file since it's so trivial.
The UnityAspect project uses Element's support for
Aspects. It
exposes an attribute that will publicize a Swift class property's underlying
field for the Unity editor. This is necessary because Swift properties translate
to properties, but Unity editor seems to work with serialized fields. In order
to edit a property in the Unity editor, you will need to add the
@UnityAspect.PublicizeField
attribute to it.
RemObjects provides an optional Swift Base Library.
It provides some of the core types, classes and functions that, while not part of the Swift language spec per se, are commonly used in Swift apps (and provided in a similar Swift Base Library in Apple's implementation).
Unfortunately, it requires .NET 4.0 which Unity does not use.