NeoSpark314 / godot_oculus_quest_toolkit

An easy to use VR toolkit for Oculus Quest development using the Godot game engine
MIT License
367 stars 38 forks source link

C# bindings #30

Closed knochenhans closed 4 years ago

knochenhans commented 4 years ago

Hi, I’m still new to Godot so I might have overlooked something. Seems though the only way to use the toolkit right now is via GDScript. Thus, it would be great to make the classes etc. available for C# scripts as well.

NeoSpark314 commented 4 years ago

The whole toolkit is written in GDScript. I do not know if it is possible to call GDScript code from C# since I have never used C# in godot. Do you know someone with Godot C# experience who could answer this? Perhaps you can still call functions on nodes even if they are implemented via GDScript. In this case you should be able to call for example all functions on the global vr singleton (and all other nodes) and the full functionality should be available already to C#

knochenhans commented 4 years ago

As far as I understand the Godot docs, mixing is possible between nodes and there is even a way to call GDScript functions from C#. This only seems to work for internal functions, though, not member functions from the vr package. But I’ll give your singleton idea a try, or maybe ask someone with more Godot + C# experience :)

NeoSpark314 commented 4 years ago

I just found these two questions with answers: https://godotengine.org/qa/52761/c%23-how-do-you-access-variables-from-a-gdscript-in-your-c%23-code and https://gamedev.stackexchange.com/questions/169190/how-can-i-reference-c-objects-in-gdscript-and-vice-versa

It seems possible to call arbitrary gd script functions. You first need to get/find the node by name and then can Call a gdscript function. If this works the whole toolkit would be usable from C#; that would be great. If you can try it and it works we should add a wiki entry that explains how to do it.

knochenhans commented 4 years ago

Thanks, the following code works fine to initialize the toolkit from a C# script:

if (GetTree().Root.HasNode("vr"))
{
   Node vr = GetTree().Root.GetNode("vr");            
   vr.Call("initialize");
}

It’s not exactly a convenient solution as it makes things like IntelliSense impossible but I guess writing a C# wrapper class (or classes) for the toolkit would end up rewriting the whole toolkit in C# ^^

NeoSpark314 commented 4 years ago

Yes; and it probably is not necessary for the most projects. At least in my projects I end up calling only very few functions of the vr singleton in most cases. And the plan for the toolkit is to make it customizable directly from the editor for the most common cases.

I created a short wiki page now that documents the findings so far: https://github.com/NeoSpark314/godot_oculus_quest_toolkit/wiki/Using-the-toolkit-with-C%23