1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

C#: Add global class support

Co-authored-by: willnationsdev <willnationsdev@gmail.com>
This commit is contained in:
Raul Santos
2023-02-02 00:54:16 +01:00
parent 2eec9a67d5
commit a1f454fee3
15 changed files with 201 additions and 25 deletions

View File

@@ -40,6 +40,10 @@
#include "core/os/os.h"
#include "core/string/string_name.h"
#ifdef TOOLS_ENABLED
#include "editor/editor_file_system.h"
#endif
#include "../interop_types.h"
#include "modules/mono/csharp_script.h"
@@ -57,6 +61,10 @@ static_assert(sizeof(SafeRefCount) == sizeof(uint32_t));
typedef Object *(*godotsharp_class_creation_func)();
bool godotsharp_dotnet_module_is_initialized() {
return GDMono::get_singleton()->is_initialized();
}
MethodBind *godotsharp_method_bind_get_method(const StringName *p_classname, const StringName *p_methodname) {
return ClassDB::get_method(*p_classname, *p_methodname);
}
@@ -304,6 +312,20 @@ void godotsharp_internal_new_csharp_script(Ref<CSharpScript> *r_dest) {
memnew_placement(r_dest, Ref<CSharpScript>(memnew(CSharpScript)));
}
void godotsharp_internal_editor_file_system_update_file(const String *p_script_path) {
#if TOOLS_ENABLED
// If the EditorFileSystem singleton is available, update the file;
// otherwise, the file will be updated when the singleton becomes available.
EditorFileSystem *efs = EditorFileSystem::get_singleton();
if (efs) {
efs->update_file(*p_script_path);
}
#else
// EditorFileSystem is only available when running in the Godot editor.
DEV_ASSERT(false);
#endif
}
bool godotsharp_internal_script_load(const String *p_path, Ref<CSharpScript> *r_dest) {
Ref<Resource> res = ResourceLoader::load(*p_path);
if (res.is_valid()) {
@@ -1391,11 +1413,13 @@ void godotsharp_object_to_string(Object *p_ptr, godot_string *r_str) {
// The order in this array must match the declaration order of
// the methods in 'GodotSharp/Core/NativeInterop/NativeFuncs.cs'.
static const void *unmanaged_callbacks[]{
(void *)godotsharp_dotnet_module_is_initialized,
(void *)godotsharp_method_bind_get_method,
(void *)godotsharp_get_class_constructor,
(void *)godotsharp_engine_get_singleton,
(void *)godotsharp_stack_info_vector_resize,
(void *)godotsharp_stack_info_vector_destroy,
(void *)godotsharp_internal_editor_file_system_update_file,
(void *)godotsharp_internal_script_debugger_send_error,
(void *)godotsharp_internal_script_debugger_is_active,
(void *)godotsharp_internal_object_get_associated_gchandle,