Quellcode durchsuchen

Added Extentions for Godot 3.x LTS / 4

pull/116/head
oguendeli vor 8 Monaten
Ursprung
Commit
a52721e060
2 geänderte Dateien mit 89 neuen und 0 gelöschten Zeilen
  1. +59
    -0
      com.sebaslab.svelto.ecs/Extensions/Godot/GodotEntitySubmissionScheduler.cs
  2. +30
    -0
      com.sebaslab.svelto.ecs/Extensions/Godot/GodotScheduler.cs

+ 59
- 0
com.sebaslab.svelto.ecs/Extensions/Godot/GodotEntitySubmissionScheduler.cs Datei anzeigen

@@ -0,0 +1,59 @@
#if GODOT
using System;
using Godot;

namespace Svelto.ECS.Schedulers.Godot
{
//The EntitySubmissionScheduler has been introduced to make the entity components submission logic platform independent
//You can customize the scheduler if you wish
public class GodotEntitySubmissionScheduler : EntitiesSubmissionScheduler
{
readonly GodotScheduler _scheduler;
EnginesRoot.EntitiesSubmitter _onTick;

/// <summary>
/// Unlike unity. Creating a gameObject with new GameObject(name) will not add it to the current scene
/// It needs to be added as a child to the scene (which is also a ~~gameObject~~Node)
/// </summary>
/// <param name="name"></param>
/// <param name="parent"></param>
public GodotEntitySubmissionScheduler(string name, Node parent)
{
_scheduler = new GodotScheduler();
_scheduler.onTick = SubmitEntities;
parent.AddChild(_scheduler);
}

private void SubmitEntities()
{
try
{
_onTick.SubmitEntities();
}
catch (Exception e)
{
paused = true;
Svelto.Console.LogException(e);

throw;
}
}

protected internal override EnginesRoot.EntitiesSubmitter onTick
{
set => _onTick = value;
}

public override void Dispose()
{
if (_scheduler != null)
{
_scheduler.QueueFree();
}
}
}

}
#endif

+ 30
- 0
com.sebaslab.svelto.ecs/Extensions/Godot/GodotScheduler.cs Datei anzeigen

@@ -0,0 +1,30 @@
#if GODOT
using Godot;

namespace Svelto.ECS.Schedulers.Godot
{
/// <summary>
/// Unlike Unity, in godot Everything is a Node. Monobehaviour = Node, GameObject = Node etc.
/// </summary>
public partial class GodotScheduler : Node
{
internal System.Action onTick;

public override void _Process(double delta)
{
Routine();
}

public async void Routine()
{
while (true)
{
await ToSignal(GetTree(), "process_frame");
onTick();
}
}
}
}
#endif

Laden…
Abbrechen
Speichern