Delsin-Yu / CSharp-Wrapper-Generator-for-GDExtension

This editor plugin generates C# wrappers for classes from the GDExtension plugins.
MIT License
11 stars 2 forks source link

Explain: Instantiate() method instead #17

Closed GeorgeS2019 closed 2 months ago

GeorgeS2019 commented 2 months ago

GDExtension: GDMP

If possible, provide example in redme.md

var cameraHelper = new  MediaPipeCameraHelper()

var cameraHelper = MediaPipeCameraHelper.Instantiate();

Second method, result in auto generated csharp file error, VS2022 will not compile

public partial class MediaPipeCameraHelper : RefCounted
{
    public static readonly StringName GDExtensionName = "MediaPipeCameraHelper";

    [Obsolete("Wrapper classes cannot be constructed with Ctor (it only instantiate the underlying RefCounted), please use the Instantiate() method instead.")]
    protected MediaPipeCameraHelper() { }

    /// <summary>
    /// Creates an instance of the GDExtension <see cref="MediaPipeCameraHelper"/> type, and attaches the wrapper script to it.
    /// </summary>
    /// <returns>The wrapper instance linked to the underlying GDExtension type.</returns>
    public static MediaPipeCameraHelper Instantiate()
    {
        return GDExtensionHelper.Instantiate<MediaPipeCameraHelper>(GDExtensionName);
    }

    /// <summary>
    /// Try to cast the script on the supplied <paramref name="godotObject"/> to the <see cref="MediaPipeCameraHelper"/> wrapper type,
    /// if no script has attached to the type, or the script attached to the type does not inherit the <see cref="MediaPipeCameraHelper"/> wrapper type,
    /// a new instance of the <see cref="MediaPipeCameraHelper"/> wrapper script will get attaches to the <paramref name="godotObject"/>.
    /// </summary>
    /// <remarks>The developer should only supply the <paramref name="godotObject"/> that represents the correct underlying GDExtension type.</remarks>
    /// <param name="godotObject">The <paramref name="godotObject"/> that represents the correct underlying GDExtension type.</param>
    /// <returns>The existing or a new instance of the <see cref="MediaPipeCameraHelper"/> wrapper script attached to the supplied <paramref name="godotObject"/>.</returns>
    public static MediaPipeCameraHelper Bind(GodotObject godotObject)
    {
        return GDExtensionHelper.Bind<MediaPipeCameraHelper>(godotObject);
    }
Delsin-Yu commented 2 months ago

The readme file is outdated and will get an update later.

Second method, result in auto generated csharp file error, VS2022 will not compile

I'm unable to understand this part, please elaborate.