diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 43f57a7caaf7..304156101481 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -1454,6 +1454,41 @@ Map::Element *CSharpLanguage::insert_script_bindi return script_bindings.insert(p_object, p_script_binding); } +bool CSharpLanguage::handles_global_class_type(const String &p_type) const { + return p_type == "CSharpScript"; +} + +String CSharpLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const { + if (!p_path.is_empty()) { + Ref script = ResourceLoader::load(p_path, "CSharpScript"); + + if (script.is_valid()) { + GDMonoClass *top = script->script_class; + + if (top && top != script->native) { + MonoClass *parent_mono_class = mono_class_get_parent(top->get_mono_ptr()); + + if (r_base_type && parent_mono_class) { + *r_base_type = String::utf8(mono_class_get_name(parent_mono_class)); + } + + if (r_icon_path) { + *r_icon_path = script->get_script_class_icon_path(); + } + + return String(top->get_name()); + } + } + if (r_base_type) { + *r_base_type = String(); + } + if (r_icon_path) { + *r_icon_path = String(); + } + } + return String(); +} + void CSharpLanguage::free_instance_binding_data(void *p_data) { if (GDMono::get_singleton() == nullptr) { #ifdef DEBUG_ENABLED diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h index dd93a86d7a3d..552227fea309 100644 --- a/modules/mono/csharp_script.h +++ b/modules/mono/csharp_script.h @@ -129,6 +129,7 @@ class CSharpScript : public Script { String source; StringName name; + String _icon_path; SelfList script_list = this; @@ -202,6 +203,14 @@ class CSharpScript : public Script { String get_source_code() const override; void set_source_code(const String &p_code) override; + String get_script_class_name() const { + return name; + } + + String get_script_class_icon_path() const { + return _icon_path; + } + #ifdef TOOLS_ENABLED virtual const Vector &get_documentation() const override { // TODO @@ -533,6 +542,8 @@ class CSharpLanguage : public ScriptLanguage { void free_instance_binding_data(void *p_data) override; void refcount_incremented_instance_binding(Object *p_object) override; bool refcount_decremented_instance_binding(Object *p_object) override; + virtual bool handles_global_class_type(const String &p_type) const; + virtual String get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const; Map::Element *insert_script_binding(Object *p_object, const CSharpScriptBinding &p_script_binding); bool setup_csharp_script_binding(CSharpScriptBinding &r_script_binding, Object *p_object);