-
Notifications
You must be signed in to change notification settings - Fork 0
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
Can U try c# demo? #1
Comments
ok, i will try it later |
@JiepengTan I wonder if it is due to lack of readiness of the c# project : |
sorry. I've been busy with other things for the last few weeks, I have tried building the godot-dotnet repository on Windows, Ubuntu, and Mac (following the instructions in the README), but I failed to build it |
The author mentioned the solution to this problem in the issues. I will add a C# example tomorrow. |
@JiepengTan using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello Libgodot-csharp ! ");
string program = "";
string projectPath = "../../Summator/Game";
if (args.Length > 0)
{
projectPath = args[0];
Console.WriteLine("Project path: " + projectPath);
}
List<string> arguments = new List<string> { program, "--path", projectPath, "--rendering-method", "gl_compatibility", "--rendering-driver", "opengl3" };
IntPtr instance = LibGodot.libgodot_create_godot_instance(arguments.Count, arguments.ToArray(), IntPtr.Zero);
if (instance == IntPtr.Zero)
{
Console.Error.WriteLine("Error creating Godot instance");
Environment.Exit(1);
}
bool success = LibGodot.libgodot_start_godot_instance(instance);
while (LibGodot.libgodot_iteration_godot_instance(instance))
{
}
LibGodot.libgodot_destroy_godot_instance(instance);
Environment.Exit(0);
}
} The essential c# interopt with Windows: libgodot.dll using System;
using System.Runtime.InteropServices;
public enum GDExtensionInitializationLevel
{
GDEXTENSION_INITIALIZATION_CORE,
GDEXTENSION_INITIALIZATION_SERVERS,
GDEXTENSION_INITIALIZATION_SCENE,
GDEXTENSION_INITIALIZATION_EDITOR,
GDEXTENSION_MAX_INITIALIZATION_LEVEL
}
[StructLayout(LayoutKind.Sequential)]
public struct GDExtensionInitialization
{
public GDExtensionInitializationLevel minimum_initialization_level;
public IntPtr userdata;
public Action<IntPtr, GDExtensionInitializationLevel> initialize;
public Action<IntPtr, GDExtensionInitializationLevel> deinitialize;
}
public class LibGodot
{
const string LIBGODOT_LIBRARY_NAME = "libgodot.dll";
[DllImport(LIBGODOT_LIBRARY_NAME)]
public static extern IntPtr libgodot_create_godot_instance(int argc, string[] argv, IntPtr handle);
[DllImport(LIBGODOT_LIBRARY_NAME)]
public static extern void libgodot_destroy_godot_instance(IntPtr instance);
[DllImport(LIBGODOT_LIBRARY_NAME)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool libgodot_start_godot_instance(IntPtr instance);
[DllImport(LIBGODOT_LIBRARY_NAME)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool libgodot_iteration_godot_instance(IntPtr instance);
} |
No description provided.
The text was updated successfully, but these errors were encountered: