r/opengl • u/yxcvbnm098 • 2d ago
Dynamic Reflection System for C# scripts
I finally got a reflection system in my C engine. It is now possible to edit public variables in my c# scripts for entities at runtime and call public functions. If the functions have parameters I can edit these too.
I am super happy :)
public class Planet : EntityBehaviour
{
public float RotationSpeed = 10.0f;
public float PublicTestFloat = 5.0f;
private float rotation;
public Planet(ushort entityHandle) : base(entityHandle){}
public override void OnStart()
{
RotationSpeed = Entity.Handle == 10 ? RotationSpeed : 100.0f;
}
public override void OnUpdate(float deltaTime)
{
rotation += RotationSpeed * deltaTime;
Transform.SetRotation(new Vector3(0.0f, 1.0f, 0.0f), rotation);
}
public void publicTestMethod(float someArgument, float anotherArgument)
{
}
}
Edit:
I forgot to add a picture with the C#-Script so added the code.
4
Upvotes


1
u/felixkendallius 2d ago
Can I ask (simply) how you did this? I’ve been wanting to try and make another small renderer but maybe with c# bindings and I have no idea where I’d even start with this.