-
Notifications
You must be signed in to change notification settings - Fork 1
Usage.Godot Projects
Run the following command in the console of your .NET project to add the package:
dotnet add package JuDelCo.Lib.Core
To use services you need to register them first. One way you can automatically register the services on runtime is creating this static class anywhere in your project and register it as an autoload, so it will run before any scene so it's the perfect entry point for the services to setup:
using System;
using System.Globalization;
using System.Threading;
using Godot;
using Ju.Services;
// Autoload
public partial class Bootstrap : Node
{
public override void _EnterTree()
{
// Core services
ServiceContainer.RegisterService<ITaskService, TaskService>();
ServiceContainer.RegisterService<ICoroutineService, CoroutineService>();
ServiceContainer.RegisterService<ICacheService, CacheService>();
// Godot related services
ServiceContainer.RegisterService<ILogGodotService, LogGodotService>();
ServiceContainer.RegisterService<ITimeService, GodotTimeService>();
ServiceContainer.RegisterService<IInputService, InputGodotService>();
GodotService.SetProcessProxyNodeType(typeof(GodotProcessProxyNode));
ServiceContainer.RegisterService<IGodotService, GodotService>();
ServiceContainer.RegisterService<INodePoolService, NodePoolService>();
// Register your custom services here
}
public partial class GodotProcessProxyNode : Node, IGodotProcessProxyNode
{
public event Action<int> OnNotificationEvent;
public event Action<InputEvent> OnInputEvent;
private Action deferredAction;
public override void _Notification(int what)
{
OnNotificationEvent?.Invoke(what);
}
public override void _Input(InputEvent inputEvent)
{
OnInputEvent?.Invoke(inputEvent);
}
public void ProxyCallDeferred(Action action)
{
deferredAction = action;
this.CallDeferred(nameof(RunDeferredAction));
}
private void RunDeferredAction()
{
if (deferredAction != null)
{
deferredAction();
}
deferredAction = null;
}
}
}
You can rename the class and the method to whatever you want. Please note that the GodotProcessProxyNode
class is essential for connecting to specific Godot events in the GodotService
.
You can register the services in your own entry point method to control whenever the services get registered like it's done in native C# projects. Just keep in mind that the GodotService
will fire all the update loop events and dispose the Service Container automatically.
Read how to use the Service Container and how to create your own Services.
After that, read about the Update Loop Events you can use, how to do logging and what LinkHandlers are.
Return to [Home]
- Home
- Install
- Manual
-
Core API
- Services:
- Util:
-
Unity API
- Services:
- Integrations: