Eintoo/GameServer/Server/Hotfix/Outter/Entity/EntityTimeOutHelper.cs

35 lines
1014 B
C#

using Fantasy.Async;
using Fantasy.Entitas;
using Fantasy.Network;
namespace Hotfix;
public static class EntityTimeOutHelper
{
public static bool CheckInterval(this Entity self, int interval)
{
var entityTimeOut = self.GetComponent<EntityTimeOutComponent>();
if (entityTimeOut == null)
{
entityTimeOut = self.AddComponent<EntityTimeOutComponent>();
entityTimeOut.SetInterval(interval);
}
return entityTimeOut.CheckInterval();
}
public static void SetTimeout(this Entity self, long timeout,Func<FTask>? callback = null)
{
var entityTimeOut = self.GetComponent<EntityTimeOutComponent>();
if (entityTimeOut == null)
{
entityTimeOut = self.AddComponent<EntityTimeOutComponent>();
}
entityTimeOut.TimeOut(timeout,callback);
}
public static bool IsHasTimeout(this Entity self)
{
return self.GetComponent<EntityTimeOutComponent>() != null;
}
}