-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make C# static methods accessible. #81783
Conversation
e714f54
to
6899696
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I've tested with the provided project and works as expected. Just a few comments about the implementation.
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs
Outdated
Show resolved
Hide resolved
modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs
Show resolved
Hide resolved
modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs
Outdated
Show resolved
Hide resolved
6899696
to
2c85940
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Save for this, the style looks good
modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs
Outdated
Show resolved
Hide resolved
2c85940
to
67e1373
Compare
Thanks! |
This doesn't work in tools scripts. Both GDScript and C# using tool attribute. Same error: C#: using Godot;
[Tool]
[GlobalClass]
public partial class DBHAutoload : GodotObject
{
public static void CreateNewDB(string path, string dbName, string namespacename, bool gen_class, string class_name, bool add_default_fields)
{
var content = ".. insert content here ...";
var file = FileAccess.Open(path, FileAccess.ModeFlags.Write);
file.StoreString(content);
file.Close();
}
} GD: @tool
extends Control
@export var create_dialog : Window
func _on_dbh_create_dialog_create(path, dbname, namespacename, gen_class, classname, add_defaultfields):
print("Creating in: " + path)
DBHAutoload.CreateNewDB()#.CreateNewDB(path,dbname,namespacename,gen_class,classname, add_defaultfields) |
Make a separate issue, the PR was closed months ago |
Close #79896.
This PR adds a code generator to generate
InvokeGodotClassStaticMethod
and allows GDScript to access C# static methods viaCSharpScript::callp -> ScriptManagerBridge.CallStatic -> YourClass.InvokeGodotClassStaticMethod -> YourClass.YourStaticMethod
.Example:
csharp_static_method_test.zip