A Bevy plugin that adds a .NET C# Scripting runtime
Warning
This project is in early development and is very experimental
Current progress:
- Compiling custom runtime, engine api, and scripts
- Loading engine api and scripts
- Binding runtime api
- Loads class from scripts
- Executes method on Class instance on component add and on update
Look at
src/bin/simple.rs,assets/engine/Bevy.cs, andassets/scripts/Player.csfor example implementation
Run with cargo run --bin=simple and optionally add --features=always-compile-runtime to force compile the custom runtime each build
- Finds an appropriate .Net version on the users system
- Builds the runtime, engine, and scripts into dll files
- Loads and manages dll files
- Hot re-compile scripts
- Binds script methods to lifetime and event hooks
- Customizable to the users components and setup
Currently the .Net Runtime distrobution format of this plugin only supports desktop targets (windows, linux, macos). With more research this may expand to mobile and web, or making it compatible with Mono could allow for Mono to be used for mobile and web targets.
- How to dynamically bind and generate the
EngineC# api. This includes user defined types that implementReflectand isReflectable - Will this plugin provide most of bevy builtin types or will the user have to expose what they want?
- How third party plugins and types can be reflected and registered
- Dynamically generate the .Net project file,
csprojandsln, so it imports theEngineapi - How to bind method params both for objects and native types as a
object?[]to send toMethodInfo.Invoke - How to map structs and enums to c# types. When they are passed to c# managed code how will modification and interaction work?
- Simple:
cargo run --example simpleWITH dynamically compiled.csfilescargo run --example simple -F distributeWITHOUT dynamically compiled.csfiles
- Find .Net and Hostfxr version
- Write a .Net runtime similar to
Monoto allow for the following:- scoping
- loading dll
- searching and validating types
- fetching and calling methods
- Error return values
- Optimal memory management.
- Is
GCHandle.AllocwithGCHandle.FreeonDropgood enough? - Is it better to find a way to make the data returned raw pointers which can be pinned with the runtime api similar to Mono?
- Is
- Compiled runtime dll
- Compiled once for the given .Net version
- Bind runtime
- Bind interop functions
- Bind interop data
- Generate Engine API bindings
- Compile Engine API
- Compile dll to
targetdirectory - Gracefully handle errors
- Compile dll to
- Load Engine API
- Compile user scripts
- Compile dll to
targetdirectory - Gracefully handle errors
- Compile dll to
- Load user Scripts
- Bind user script methods to hooks
- Hot reload and compile user scripts on file changes
- Build script for distrobution (production) builds
- Lock behind feature flag
- Bundle the users selected .Net
- Compiled and bundle
- Runtime dll and runtimeconfig
- Engine.dll
- Scripts.dll
- Optionally use Mono for all platforms or mobile and web
- Opting to bind Runtime methods by writing a delegate signature with
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]and a matching method with the same signature to allow foroutc# params - C#
Enginenamespace will have a staticInteropclass with a table of unmanaged delegates that point to rust functions that can be called from Managed code. - C#
Enginenamespace will have a staticInteropclass with a pointer to the currentworldto allow for context sensitiveinteropcalls to manipulate and query theworld
