initial commit, 4.5 stable
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
using System.Text;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
|
||||
namespace Godot.SourceGenerators
|
||||
{
|
||||
[Generator]
|
||||
public class GodotPluginsInitializerGenerator : ISourceGenerator
|
||||
{
|
||||
public void Initialize(GeneratorInitializationContext context)
|
||||
{
|
||||
}
|
||||
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
if (context.IsGodotToolsProject() || context.IsGodotSourceGeneratorDisabled("GodotPluginsInitializer"))
|
||||
return;
|
||||
|
||||
string source =
|
||||
@"using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Godot.Bridge;
|
||||
using Godot.NativeInterop;
|
||||
|
||||
namespace GodotPlugins.Game
|
||||
{
|
||||
internal static partial class Main
|
||||
{
|
||||
[UnmanagedCallersOnly(EntryPoint = ""godotsharp_game_main_init"")]
|
||||
private static godot_bool InitializeFromGameProject(IntPtr godotDllHandle, IntPtr outManagedCallbacks,
|
||||
IntPtr unmanagedCallbacks, int unmanagedCallbacksSize)
|
||||
{
|
||||
try
|
||||
{
|
||||
DllImportResolver dllImportResolver = new GodotDllImportResolver(godotDllHandle).OnResolveDllImport;
|
||||
|
||||
var coreApiAssembly = typeof(global::Godot.GodotObject).Assembly;
|
||||
|
||||
NativeLibrary.SetDllImportResolver(coreApiAssembly, dllImportResolver);
|
||||
|
||||
NativeFuncs.Initialize(unmanagedCallbacks, unmanagedCallbacksSize);
|
||||
|
||||
ManagedCallbacks.Create(outManagedCallbacks);
|
||||
|
||||
ScriptManagerBridge.LookupScriptsInAssembly(typeof(global::GodotPlugins.Game.Main).Assembly);
|
||||
|
||||
return godot_bool.True;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
global::System.Console.Error.WriteLine(e);
|
||||
return false.ToGodotBool();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
context.AddSource("GodotPlugins.Game.generated",
|
||||
SourceText.From(source, Encoding.UTF8));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user