49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using Fantasy.Entitas.Interface;
|
|
|
|
namespace NB.Gate.System;
|
|
|
|
public sealed class GameAccountManageComponentDestroySystem : DestroySystem<GameAccountManageComponent>
|
|
{
|
|
protected override void Destroy(GameAccountManageComponent self)
|
|
{
|
|
foreach (var (_, gameAccount) in self.Accounts)
|
|
{
|
|
gameAccount.Dispose();
|
|
}
|
|
|
|
self.Accounts.Clear();
|
|
}
|
|
}
|
|
|
|
public static class GameAccountManageComponentSystem
|
|
{
|
|
public static void Add(this GameAccountManageComponent self, GameAccount account)
|
|
{
|
|
self.Accounts.Add(account.Id, account);
|
|
}
|
|
|
|
public static GameAccount? Get(this GameAccountManageComponent self, long accountId)
|
|
{
|
|
return self.Accounts.GetValueOrDefault(accountId);
|
|
}
|
|
|
|
public static bool TryGet(this GameAccountManageComponent self, long accountId, out GameAccount? account)
|
|
{
|
|
return self.Accounts.TryGetValue(accountId, out account);
|
|
}
|
|
|
|
public static void Remove(this GameAccountManageComponent self, long accountId, bool isDispose = true)
|
|
{
|
|
if (!self.Accounts.Remove(accountId, out var account))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!isDispose)
|
|
{
|
|
return;
|
|
}
|
|
|
|
account.Dispose();
|
|
}
|
|
} |