123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System;
- using XGame.Framework.Time;
- namespace XGame.Framework.Network
- {
- /// <summary>
- /// 单实例,有双实例需求再改
- /// </summary>
- 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;
- }
- /// <summary>
- /// 发送请求消息
- /// </summary>
- /// <param name="msg"></param>
- /// <param name="isFilter">过滤参数,默认开启</param>
- 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;
- }
- }
- }
|