You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

using Godot;
using static Godot.GD;
using System;
using System.Collections.Generic;
namespace EGFramework{
public partial class EGThread : Node,IModule,IEGFramework{
public EasyEventOnce EventPool = new EasyEventOnce();
public Dictionary<Action,SceneTreeTimer> EventDelayPool = new Dictionary<Action, SceneTreeTimer>();
public void Init()
{
}
public override void _Ready()
{
}
public override void _Process(double delta)
{
//base._Process(delta);
EventPool.Invoke();
}
public void ExecuteInMainThread(Action action){
//ActionQueue.Enqueue(action);
EventPool.Register(action);
}
public void ExecuteAfterSecond(Action action,double delay){
SceneTreeTimer timer = this.GetTree().CreateTimer(delay);
timer.Timeout += action;
timer.Timeout += () => EventDelayPool.Remove(action);
EventDelayPool.Add(action,timer);
}
public IArchitecture GetArchitecture()
{
return EGArchitectureImplement.Interface;
}
}
public static class EGThreadExtension
{
public static void ExecuteInMainThread(this Node self, Action action){
//action.Invoke();
self.NodeModule<EGThread>().ExecuteInMainThread(action);
}
public static void ExecuteAfterSecond(this Node self, Action action,double delay){
self.NodeModule<EGThread>().ExecuteAfterSecond(action,delay);
}
public static void EGEnabledThread(this Node self){
self.NodeModule<EGThread>();
}
}
}