using System;
using XGame.Framework.Time;
namespace XGame.Framework.Network
{
///
/// 单实例,有双实例需求再改
///
public partial class NetModule
{
private static INetModule _instance;
//public static INetModule Instance
//{
// get
// {
// Assert.IsNotNull(_instance, $"NetModule 实例为空, 需要先执行NetModule.Init()");
// return _instance;
// }
//}
public static INetModule Init(ITimeModule time, IMsgGenerator generator, INetModuleListener listener)
{
var netModule = new NetModule(time, generator, listener);
netModule.IsDebug = AppManager.IsSessionDebug;
_instance = netModule;
return netModule;
}
///
/// 发送请求消息
///
///
/// 过滤参数,默认开启
public static void Request(IMsgRequest msg, bool isFilter = true)
{
Assert.IsNotNull(_instance, $"NetModule 实例为空, 需要先执行NetModule.Init()");
_instance.Send(msg, isFilter);
}
public static void Dispose()
{
if (_instance == null) return;
_instance.Disconnect();
(_instance as IDisposable)?.Dispose();
_instance = null;
}
}
}