Note: this has only been tested out with Xamarin Studio on Mac OS X
- Create a Unity Project
- Create a F# project (lib) and put it in the root of the Unity project
- In the Unity 'Assets' folder, create a folder called 'Frameworks' and add the FSharp.Core.dll to it
- 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/
- You can access namespaces/classes from C# components just like you'd expect
- Copy UnityEngine.dll to the F# project and add it as a reference
- 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)
- 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
Hey, if you like this repo maybe you'd be interested in the language I'm working on. It's a functional language aimed at game development. Read more about it here: https://github.com/eriksvedang/Carp