Note: this has only been tested out with Xamarin Studio on Mac OS X
- Create a Unity Project
- In the Unity 'Assets' folder, create a folder called 'Frameworks' and add the FSharp.Core.dll to it
- Create a F# project (lib) and put it in the root of the Unity project
- Open the preferences for the F# project and change the 'Target Framework' to 'Mono / .NET 3.5'
- Remove all References in the project, except FSharp.Core (2.3.0), System and System.Core
- Add the unity mscorlib.dll to somewhere in the F# project folder, and then to the project References
- Make a custom build command (working dir: ${TargetDir}) that copies the resulting dll to the Unity 'Frameworks' folder
cp MyFsharpLib.dll ../../../../Assets/Frameworks/
Note: this has only been tested out on Linux (fsharpc command, which calls fsc.exe)
- Create a Unity Project
- Clone this repo in the root folder of your Unity Project
- Call the prepare.sh script, that'll create the 'Assets/Frameworks' and 'Assets/Editor' folder, and copy the needed files
- Put your F# source code (.fs file) in the 'Assets/Scripts' folder, edit it with your favorite text editor
- Open the F# Compiler Window (from the 'F#/Compiler' menu, or with Shift+Ctrl+3)
- Click the 'Compile F#s' button. Build errors are logged in the Editor's Console
- Wait until complete. Dlls will be put in the 'Assets/Frameworks' folder
- You can access namespaces/classes from C# components just like you'd expect
- The component will show up under the DLL in Unity's Project view, click the little arrow to fold it out (or just add it to a game object using the Add Component menu)
- Set the namespace as the file name
namespace MyFsharpLib
- Import the Unity namespace
open UnityEngine
- Inherit from MonoBehaviour, as usual
type SimpleComponent() =
inherit MonoBehaviour()
member this.stuff = 42
- To show properties in the inspector, make them mutable and serializable
[<SerializeField>]
let mutable changeSpeed = 2.0f
- Override member functions
member this.Start () =
this.transform.Translate(1.0f, -1.0f, 2.0f)
- Mutate members
this.renderer.material.color <- Color.red