For few months i was working on a C# bindings generator for Urho3D. I am at the point where while still experimental it already looks like it could be usable. Be aware that project is made with my fork in mind, which is a little bit different from upstream Urho3D. However things generator depends upon are few and minor and i would love to get them upstreamed.
A recap on the features: https://github.com/rokups/Urho3D/wiki/C%23-support
Repository with bindings generator: https://github.com/rokups/Urho3D, build with -DURHO3D_CSHARP=ON
.
Repository contains sample 102_CSharpProject
written in C#.
Differences from urhosharp:
- Also works with .net framework
- Supports inheriting c++ classes and overriding their virtual methods
- Supports multiple inheritance
- Supports serializing and deserializing managed objects without magical patches to the source
- Supports access of protected class members
- Getters and setters are converted to C# properties
Demo:
using System;
using System.Diagnostics;
using System.IO;
using Urho3D;
namespace DemoApplication
{
[ObjectFactory]
class RotateObject : LogicComponent
{
public RotateObject(Context context) : base(context)
{
UpdateEventMask = UseUpdate;
}
public override void Update(float timeStep)
{
var d = new Quaternion(10 * timeStep, 20 * timeStep, 30 * timeStep);
Node.Rotate(d);
}
}
class DemoApplication : Application
{
private Scene _scene;
private Viewport _viewport;
private Node _camera;
private Node _cube;
private Node _light;
public DemoApplication(Context context) : base(context)
{
}
public override void Setup()
{
var currentDir = Directory.GetCurrentDirectory();
EngineParameters[EngineDefs.EpFullScreen] = false;
EngineParameters[EngineDefs.EpWindowWidth] = 1920;
EngineParameters[EngineDefs.EpWindowHeight] = 1080;
EngineParameters[EngineDefs.EpWindowTitle] = "Hello C#";
EngineParameters[EngineDefs.EpResourcePrefixPaths] = $"{currentDir};{currentDir}/..";
}
public override void Start()
{
Input.SetMouseVisible(true);
// Viewport
_scene = new Scene(Context);
_scene.CreateComponent<Octree>();
_camera = _scene.CreateChild("Camera");
_viewport = new Viewport(Context, _scene, _camera.CreateComponent<Camera>());
Renderer.SetViewport(0, _viewport);
// Background
Renderer.DefaultZone.FogColor = new Color(0.5f, 0.5f, 0.7f);
// Scene
_camera.Position = new Vector3(0, 2, -2);
_camera.LookAt(Vector3.Zero);
// Cube
_cube = _scene.CreateChild("Cube");
var model = _cube.CreateComponent<StaticModel>();
model.Model = Cache.GetResource<Model>("Models/Box.mdl");
model.SetMaterial(0, Cache.GetResource<Material>("Materials/Stone.xml"));
_cube.CreateComponent<RotateObject>();
// Light
_light = _scene.CreateChild("Light");
_light.CreateComponent<Light>();
_light.Position = new Vector3(0, 2, -1);
_light.LookAt(Vector3.Zero);
SubscribeToEvent(CoreEvents.E_UPDATE, args =>
{
var timestep = args[Update.P_TIMESTEP].Float;
Debug.Assert(this != null);
});
}
}
internal class Program
{
public static void Main(string[] args)
{
using (var context = new Context())
{
using (var application = new DemoApplication(context))
{
application.Run();
}
}
}
}
}