├── Cargo.lock ├── unity-example ├── ProjectSettings │ ├── ProjectVersion.txt │ ├── TagManager.asset │ ├── AudioManager.asset │ ├── InputManager.asset │ ├── NavMeshAreas.asset │ ├── TimeManager.asset │ ├── DynamicsManager.asset │ ├── EditorSettings.asset │ ├── NetworkManager.asset │ ├── ProjectSettings.asset │ ├── QualitySettings.asset │ ├── GraphicsSettings.asset │ ├── Physics2DSettings.asset │ └── EditorBuildSettings.asset └── Assets │ ├── RustExample.unity │ ├── RustExample.unity.meta │ ├── Plugins.meta │ ├── RustBehaviour.cs.meta │ └── RustBehaviour.cs ├── README.md ├── Cargo.toml ├── src └── lib.rs ├── Makefile └── .gitignore /Cargo.lock: -------------------------------------------------------------------------------- 1 | [root] 2 | name = "unity-to-rust" 3 | version = "0.1.0" 4 | 5 | -------------------------------------------------------------------------------- /unity-example/ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.0.2f1 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /unity-example/Assets/RustExample.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimfleming/unity-to-rust/HEAD/unity-example/Assets/RustExample.unity -------------------------------------------------------------------------------- /unity-example/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimfleming/unity-to-rust/HEAD/unity-example/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /unity-example/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimfleming/unity-to-rust/HEAD/unity-example/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /unity-example/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimfleming/unity-to-rust/HEAD/unity-example/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /unity-example/ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimfleming/unity-to-rust/HEAD/unity-example/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /unity-example/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimfleming/unity-to-rust/HEAD/unity-example/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /unity-example/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimfleming/unity-to-rust/HEAD/unity-example/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /unity-example/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimfleming/unity-to-rust/HEAD/unity-example/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /unity-example/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimfleming/unity-to-rust/HEAD/unity-example/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /unity-example/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimfleming/unity-to-rust/HEAD/unity-example/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /unity-example/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimfleming/unity-to-rust/HEAD/unity-example/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /unity-example/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimfleming/unity-to-rust/HEAD/unity-example/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /unity-example/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimfleming/unity-to-rust/HEAD/unity-example/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /unity-example/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimfleming/unity-to-rust/HEAD/unity-example/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | How to use Unity’s Native Plugin interface to call fast, safe code in Rust: 2 | 3 | [Rust(lang) from Unity3D](https://medium.com/@jimfleming/rust-lang-in-unity3d-eeaeb47f3a77) 4 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "unity-to-rust" 3 | version = "0.1.0" 4 | authors = ["Jim Fleming "] 5 | 6 | [lib] 7 | name = "unity_rust" 8 | crate-type = ["dylib"] 9 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #[no_mangle] 2 | pub extern fn double_input(input: i32) -> i32 { 3 | input * 2 4 | } 5 | 6 | #[no_mangle] 7 | pub extern fn triple_input(input: i32) -> i32 { 8 | input * 3 9 | } 10 | -------------------------------------------------------------------------------- /unity-example/Assets/RustExample.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2ec1f5e0962384e8a945a5f36d31fa83 3 | timeCreated: 1432880017 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-example/Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9a523b04dcbb846a6bbefed0b4a63def 3 | folderAsset: yes 4 | timeCreated: 1432866349 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | DYLIB=target/debug/libunity_rust.dylib 2 | BUNDLE=unity-example/Assets/Plugins/libunity_rust.bundle 3 | 4 | all: $(DYLIB) $(BUNDLE) 5 | 6 | $(DYLIB): src/lib.rs Cargo.toml 7 | cargo build 8 | 9 | $(BUNDLE): $(DYLIB) 10 | cp $< $@ 11 | 12 | clean: 13 | rm -rf target/ 14 | rm -f $(BUNDLE) 15 | rm -f $(BUNDLE).meta 16 | -------------------------------------------------------------------------------- /unity-example/Assets/RustBehaviour.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 591a1615deb1e47aba067c7193cd0728 3 | timeCreated: 1432866431 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /unity-example/Assets/RustBehaviour.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Runtime.InteropServices; 4 | 5 | public class RustBehaviour : MonoBehaviour { 6 | 7 | // The plugin referenced by `DLLImport` must be compiled 8 | // and placed in your project's Assets/Plugins/ folder. 9 | 10 | // Make sure that you rename the lib.dylib to 11 | // lib.bundle so that Unity can find it. 12 | 13 | [DllImport("libunity_rust")] 14 | private static extern int double_input(int x); 15 | 16 | [DllImport("libunity_rust")] 17 | private static extern int triple_input(int x); 18 | 19 | void Start() { 20 | Debug.Log(double_input(4)); // 8 21 | Debug.Log(triple_input(4)); // 12 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | unity-example/Assets/Plugins/libunity_rust.bundle 2 | unity-example/Assets/Plugins/libunity_rust.bundle.meta 3 | 4 | # Created by https://www.gitignore.io 5 | 6 | ### OSX ### 7 | .DS_Store 8 | 9 | ### Unity ### 10 | [Ll]ibrary/ 11 | [Tt]emp/ 12 | [Oo]bj/ 13 | [Bb]uild/ 14 | 15 | # Autogenerated VS/MD solution and project files 16 | *.csproj 17 | *.unityproj 18 | *.sln 19 | *.suo 20 | *.tmp 21 | *.user 22 | *.userprefs 23 | *.pidb 24 | *.booproj 25 | 26 | # Unity3D generated meta files 27 | *.pidb.meta 28 | 29 | # Unity3D Generated File On Crash Reports 30 | sysinfo.txt 31 | 32 | ### Rust ### 33 | # Compiled files 34 | *.o 35 | *.so 36 | *.rlib 37 | *.dll 38 | 39 | # Executables 40 | *.exe 41 | 42 | # Generated by Cargo 43 | target/ 44 | --------------------------------------------------------------------------------