39 lines
1010 B
C#
39 lines
1010 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace ET
|
|
{
|
|
public class OnLineComponentAwakeSystem : AwakeSystem<OnLineComponent>
|
|
{
|
|
public override void Awake(OnLineComponent self)
|
|
{
|
|
OnLineComponent.Instance = self;
|
|
}
|
|
}
|
|
|
|
public class OnLineComponent : Entity
|
|
{
|
|
public static OnLineComponent Instance { get; set; }
|
|
private Dictionary<long, Session> sessionDic = new Dictionary<long, Session>();
|
|
|
|
public void OnLine(long id, Session session)
|
|
{
|
|
sessionDic[id] = session;
|
|
}
|
|
public Session GetSession(long id)
|
|
{
|
|
sessionDic.TryGetValue(id, out Session session);
|
|
return session;
|
|
}
|
|
public bool isOnLine(long id) => sessionDic.ContainsKey(id);
|
|
public void OffLine(long id)
|
|
{
|
|
sessionDic.Remove(id);
|
|
}
|
|
public IEnumerable<Session> GetAll()
|
|
{
|
|
return sessionDic.Values;
|
|
}
|
|
}
|
|
}
|