godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.11k stars 21.18k forks source link

Creating new plugin C# doesn't create the correct file #37867

Open git2013vb opened 4 years ago

git2013vb commented 4 years ago

Godot version: 3.2.1 stable mono OS/device including version: Debian 10 Issue description: Following the instruction from documentation here Godot does not create the correct file:

using Godot;
using System;

public class plugin : EditorPlugin
{
    // Declare member variables here. Examples:
    // private int a = 2;
    // private string b = "text";

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {

    }

//  // Called every frame. 'delta' is the elapsed time since the previous frame.
//  public override void _Process(float delta)
//  {
//      
//  }
}

Expected:

#if TOOLS
using Godot;
using System;

[Tool]
public class CustomNode : EditorPlugin
{
    public override void _EnterTree()
    {
        // Initialization of the plugin goes here
    }

    public override void _ExitTree()
    {
        // Clean-up of the plugin goes here
    }
}
#endif

Steps to reproduce: follow the instructions on the page Minimal reproduction project: NA

YuriSizov commented 4 years ago

I'm guessing this is known:

// TODO Use script templates. Right now, this code won't add the 'tool' annotation to other languages.
// TODO Better support script languages with named classes (has_named_classes).

// FIXME: It's hacky to have hardcoded access to the GDScript module here.
// The editor code should not have to know what languages are enabled.

Basically, for GDScript the plugin code is generated by hand ad hoc, and for everything else whatever is default is used. This example of yours is straight from modules\mono\csharp_script.cpp.

git2013vb commented 4 years ago

I'm wondering where that example in page came from because I read "Thankfully, the dialog generates these callbacks for you. Your script should look something like this:"

YuriSizov commented 4 years ago

@git2013vb The example code was probably adapted from the GDScript example without checking. Or it was made ahead of any improvement to plugin.cs generation that never came.

It seems to be a good opportunity for a first PR, btw. Needs some consensus on how to implement a plugin template into base classes, but otherwise rather simple task.

aaronfranke commented 4 years ago

Related: https://github.com/godotengine/godot/issues/28799. Right now the template is hard-coded and there is only one.