水电费
This commit is contained in:
47
Hotfix/EntityHelper.cs
Normal file
47
Hotfix/EntityHelper.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Authentication;
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Network;
|
||||
// ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
|
||||
|
||||
namespace System;
|
||||
|
||||
public static class EntityHelper
|
||||
{
|
||||
public static bool CheckInterval(this Entity entity, int interval)
|
||||
{
|
||||
var sessionTimeOutComponent = entity.GetComponent<EntityTimeOutComponent>();
|
||||
|
||||
if (sessionTimeOutComponent == null)
|
||||
{
|
||||
sessionTimeOutComponent = entity.AddComponent<EntityTimeOutComponent>();
|
||||
sessionTimeOutComponent.SetInterval(interval);
|
||||
return true;
|
||||
}
|
||||
|
||||
return sessionTimeOutComponent.CheckInterval();
|
||||
}
|
||||
|
||||
public static void SetTimeout(this Entity entity, int timeout = 3000, Func<FTask>? task = null)
|
||||
{
|
||||
var sessionTimeOutComponent = entity.GetComponent<EntityTimeOutComponent>();
|
||||
|
||||
if (sessionTimeOutComponent == null)
|
||||
{
|
||||
sessionTimeOutComponent = entity.AddComponent<EntityTimeOutComponent>();
|
||||
}
|
||||
|
||||
sessionTimeOutComponent.TimeOut(timeout, task);
|
||||
}
|
||||
|
||||
public static bool IsTimeOutComponent(this Entity entity)
|
||||
{
|
||||
return entity.GetComponent<EntityTimeOutComponent>() != null;
|
||||
}
|
||||
|
||||
public static void CancelTimeout(this Entity entity)
|
||||
{
|
||||
entity.RemoveComponent<EntityTimeOutComponent>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user