├── README.md └── dlls ├── FSharp.Core.dll ├── UnityEngine.dll └── mscorlib.dll /README.md: -------------------------------------------------------------------------------- 1 | How to use F# libraries with Unity 2 | ================================== 3 | 4 | Note: this has only been tested out with Xamarin Studio on Mac OS X 5 | 6 | 1. Create a Unity Project 7 | 2. Create a F# project (lib) and put it in the root of the Unity project 8 | 3. In the Unity 'Assets' folder, create a folder called 'Frameworks' and add the FSharp.Core.dll to it 9 | 4. Open the preferences for the F# project and change the 'Target Framework' to 'Mono / .NET 3.5' 10 | 5. Remove all References in the project, except FSharp.Core (2.3.0), System and System.Core 11 | 6. Add the unity mscorlib.dll to somewhere in the F# project folder, and then to the project References 12 | 7. Make a custom build command (working dir: ${TargetDir}) that copies the resulting dll to the Unity 'Frameworks' folder 13 | 14 | ```bash 15 | cp MyFsharpLib.dll ../../../../Assets/Frameworks/ 16 | ``` 17 | 18 | * You can access namespaces/classes from C# components just like you'd expect 19 | 20 | How to write Unity components in F# 21 | =================================== 22 | 23 | * Copy UnityEngine.dll to the F# project and add it as a reference 24 | * 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) 25 | * Import the Unity namespace 26 | 27 | ```fsharp 28 | open UnityEngine 29 | ``` 30 | 31 | * Inherit from MonoBehaviour, as usual 32 | 33 | ```fsharp 34 | type SimpleComponent() = 35 | inherit MonoBehaviour() 36 | member this.stuff = 42 37 | ``` 38 | 39 | * To show properties in the inspector, make them mutable and serializable 40 | 41 | ```fsharp 42 | [] 43 | let mutable changeSpeed = 2.0f 44 | ``` 45 | 46 | * Override member functions 47 | 48 | ```fsharp 49 | member this.Start () = 50 | this.transform.Translate(1.0f, -1.0f, 2.0f) 51 | ``` 52 | 53 | * Mutate members 54 | 55 | ```fsharp 56 | this.renderer.material.color <- Color.red 57 | ``` 58 | 59 | --- 60 | 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 61 | -------------------------------------------------------------------------------- /dlls/FSharp.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eriksvedang/FSharp-Unity/e6367756f939d66c1282e04f9512cb982515cbc8/dlls/FSharp.Core.dll -------------------------------------------------------------------------------- /dlls/UnityEngine.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eriksvedang/FSharp-Unity/e6367756f939d66c1282e04f9512cb982515cbc8/dlls/UnityEngine.dll -------------------------------------------------------------------------------- /dlls/mscorlib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eriksvedang/FSharp-Unity/e6367756f939d66c1282e04f9512cb982515cbc8/dlls/mscorlib.dll --------------------------------------------------------------------------------