public void Initialize(INetworkChannel networkChannel) { m_NetworkChannel = networkChannel; GameEntry.Event.Subscribe(UnityGameFramework.Runtime.NetworkConnectedEventArgs.EventId, OnNetworkConnected); GameEntry.Event.Subscribe(UnityGameFramework.Runtime.NetworkClosedEventArgs.EventId, OnNetworkClosed); GameEntry.Event.Subscribe(UnityGameFramework.Runtime.NetworkMissHeartBeatEventArgs.EventId, OnNetworkMissHeartBeat); GameEntry.Event.Subscribe(UnityGameFramework.Runtime.NetworkErrorEventArgs.EventId, OnNetworkError); GameEntry.Event.Subscribe(UnityGameFramework.Runtime.NetworkCustomErrorEventArgs.EventId, OnNetworkCustomError); m_NetworkChannel.RegisterHandler(new SCHeartBeatHandler()); m_NetworkChannel.RegisterHandler(new SCDataHandler()); }
public void Initialize(INetworkChannel networkChannel) { _networkChannel = networkChannel; _heartPacket = new MOPacket(new MOMsg() { Content = new C2S1().ToByteString() }); Type packetHandlerBaseType = typeof(IPacketHandler); Assembly assembly = Assembly.GetExecutingAssembly(); Type[] types = assembly.GetTypes(); for (int i = 0; i < types.Length; i++) { if (!types[i].IsClass || types[i].IsAbstract) { continue; } if (types[i].GetInterface(typeof(IPacketHandler).Name) == packetHandlerBaseType) { IPacketHandler packetHandler = (IPacketHandler)Activator.CreateInstance(types[i]); _networkChannel.RegisterHandler(packetHandler); } } GameEntry.Event.Subscribe(UnityGameFramework.Runtime.NetworkConnectedEventArgs.EventId, OnNetworkConnected); GameEntry.Event.Subscribe(UnityGameFramework.Runtime.NetworkClosedEventArgs.EventId, OnNetworkClosed); GameEntry.Event.Subscribe(UnityGameFramework.Runtime.NetworkMissHeartBeatEventArgs.EventId, OnNetworkMissHeartBeat); GameEntry.Event.Subscribe(UnityGameFramework.Runtime.NetworkErrorEventArgs.EventId, OnNetworkError); GameEntry.Event.Subscribe(UnityGameFramework.Runtime.NetworkCustomErrorEventArgs.EventId, OnNetworkCustomError); }
/// <summary> /// 初始化网络频道辅助器。 ---自动调用 /// </summary> /// <param name="networkChannel">网络频道。</param> void INetworkChannelHelper.Initialize(INetworkChannel networkChannel) { m_NetworkChannel = networkChannel; // 反射注册包和包处理函数。 Type packetBaseType = typeof(ServerToClientPacketBase); Type packetHandlerBaseType = typeof(PacketHandlerBase); Assembly assembly = Assembly.GetExecutingAssembly(); Type[] types = assembly.GetTypes(); for (int i = 0; i < types.Length; i++) { if (!types[i].IsClass || types[i].IsAbstract) { continue; } if (types[i].BaseType == packetBaseType) { PacketBase packetBase = (PacketBase)Activator.CreateInstance(types[i]); Type packetType = GetServerToClientPacketType(packetBase.Id); if (packetType != null) { Log.Warning("Already exist packet type '{0}', check '{1}' or '{2}'?.", packetBase.Id.ToString(), packetType.Name, packetBase.GetType().Name); continue; } m_ServerToClientPacketTypes.Add(packetBase.Id, types[i]); } else if (types[i].BaseType == packetHandlerBaseType) { IPacketHandler packetHandler = (IPacketHandler)Activator.CreateInstance(types[i]); m_NetworkChannel.RegisterHandler(packetHandler); } } //m_NetworkChannel.NetworkChannelConnected += OnNetworkConnected; //m_NetworkChannel.NetworkChannelClosed += OnNetworkClosed; //m_NetworkChannel.NetworkChannelSended += OnNetworkSendPacket; //m_NetworkChannel.NetworkChannelMissHeartBeat += OnNetworkMissHeartBeat; //m_NetworkChannel.NetworkChannelError += OnNetworkError; //m_NetworkChannel.NetworkChannelCustomError += OnNetworkCustomError; GameEntry.Event.Subscribe(ZFramework.Runtime.NetworkConnectedEventArgs.EventId, OnNetworkConnected); GameEntry.Event.Subscribe(ZFramework.Runtime.NetworkClosedEventArgs.EventId, OnNetworkClosed); GameEntry.Event.Subscribe(ZFramework.Runtime.NetworkSendPacketEventArgs.EventId, OnNetworkSendPacket); GameEntry.Event.Subscribe(ZFramework.Runtime.NetworkMissHeartBeatEventArgs.EventId, OnNetworkMissHeartBeat); GameEntry.Event.Subscribe(ZFramework.Runtime.NetworkErrorEventArgs.EventId, OnNetworkError); GameEntry.Event.Subscribe(ZFramework.Runtime.NetworkCustomErrorEventArgs.EventId, OnNetworkCustomError); }
/// <summary> /// 初始化网络频道辅助器 /// </summary> /// <param name="networkChannel"></param> public void Initialize(INetworkChannel networkChannel) { m_NetworkChannel = networkChannel; //反射查找类型,注册消息包和处理函数 Type packetBaseType = typeof(SCPacketBase); Type packetHandlerBaseType = typeof(PacketHandlerBase); Assembly assembly = Assembly.GetExecutingAssembly(); Type[] types = assembly.GetTypes(); int len = types.Length; for (int i = 0; i < len; i++) { if (!types[i].IsClass || types[i].IsAbstract) { continue; } if (types[i].BaseType == packetBaseType) { //注册消息包 SCPacketBase packetBase = (SCPacketBase)Activator.CreateInstance(types[i]); Type packetType = GetServerToClientPacketType(packetBase.Id); if (packetType != null) { Log.Warning("Already exist packet type '{0}', check '{1}' or '{2}'?.", packetBase.Id.ToString(), packetType.Name, packetBase.GetType().Name); continue; } else { m_ServerToClientPacketTypes.Add(packetBase.Id, types[i]); } } else if (types[i].BaseType == packetHandlerBaseType) { //注册消息处理 IPacketHandler handler = (IPacketHandler)Activator.CreateInstance(types[i]); m_NetworkChannel.RegisterHandler(handler); } } GameManager.Event.Subscribe(UnityGameFramework.Runtime.NetworkConnectedEventArgs.EventId, OnNetworkConnected); GameManager.Event.Subscribe(UnityGameFramework.Runtime.NetworkClosedEventArgs.EventId, OnNetworkClosed); GameManager.Event.Subscribe(UnityGameFramework.Runtime.NetworkErrorEventArgs.EventId, OnNetworkError); GameManager.Event.Subscribe(UnityGameFramework.Runtime.NetworkCustomErrorEventArgs.EventId, OnNetworkCustomError); GameManager.Event.Subscribe(UnityGameFramework.Runtime.NetworkMissHeartBeatEventArgs.EventId, OnNetworkMissHeartBeat); }
public void Initialize(INetworkChannel networkChannel) { m_NetworkChannel = networkChannel; //memoryStream = MemoryStreamManager.GetStream("message", ushort.MaxValue); // 反射注册包和包处理函数。 Type packetBaseType = typeof(SCPacketBase); Type eT_PacketHandlerType = typeof(ET_PacketHandler); Assembly assembly = Assembly.GetExecutingAssembly(); Type[] types = assembly.GetTypes(); for (int i = 0; i < types.Length; i++) { if (!types[i].IsClass || types[i].IsAbstract) { continue; } if (types[i].BaseType == packetBaseType) { PacketBase packetBase = (PacketBase)Activator.CreateInstance(types[i]); Type packetType = GetServerToClientPacketType(packetBase.Id); if (packetType != null) { Log.Warning("Already exist packet type '{0}', check '{1}' or '{2}'?.", packetBase.Id.ToString(), packetType.Name, packetBase.GetType().Name); continue; } m_ServerToClientPacketTypes.Add(packetBase.Id, types[i]); } else if (types[i].BaseType == eT_PacketHandlerType) { IPacketHandler packetHandler = (IPacketHandler)Activator.CreateInstance(types[i]); m_NetworkChannel.RegisterHandler(packetHandler); } } GameEntry.Event.Subscribe(UnityGameFramework.Runtime.NetworkConnectedEventArgs.EventId, OnNetworkConnected); GameEntry.Event.Subscribe(UnityGameFramework.Runtime.NetworkClosedEventArgs.EventId, OnNetworkClosed); GameEntry.Event.Subscribe(UnityGameFramework.Runtime.NetworkMissHeartBeatEventArgs.EventId, OnNetworkMissHeartBeat); GameEntry.Event.Subscribe(UnityGameFramework.Runtime.NetworkErrorEventArgs.EventId, OnNetworkError); GameEntry.Event.Subscribe(UnityGameFramework.Runtime.NetworkCustomErrorEventArgs.EventId, OnNetworkCustomError); }
/// <summary> /// 初始化网络频道辅助器 /// </summary> /// <param name="networkChannel">网络频道。</param> public void Initialize(INetworkChannel networkChannel) { m_NetworkChannel = networkChannel; //反射注册包和包处理函数 Type packetBaseType = typeof(SCPacketBase); Type packetHandlerBaseType = typeof(PacketHandlerBase); Assembly assembly = Assembly.GetExecutingAssembly(); Type[] types = assembly.GetTypes(); for (int i = 0; i < types.Length; i++) { if (!types[i].IsClass || types[i].IsAbstract) { continue; } if (types[i].BaseType == packetBaseType) //服务器发来消息包的所有子类 { SCPacketBase packetBase = Activator.CreateInstance(types[i]) as SCPacketBase; Type packetType = GetServerToClientPacketType(packetBase.Id); if (packetType != null) { Log.Warning("Already exist packet type '{0}', check '{1}' or '{2}'?.", packetBase.Id.ToString(), packetType.Name, packetBase.GetType().Name); continue; } m_ServerToClientPacketTypes.Add(packetBase.Id, types[i]); //保存 } else if (types[i].BaseType == packetHandlerBaseType) //消息包处理方法的所有子类 { IPacketHandler packetHandler = (IPacketHandler)Activator.CreateInstance(types[i]); m_NetworkChannel.RegisterHandler(packetHandler); } } //注册网络事件回调 GameEntry.Event.Subscribe(UnityGameFrame.Runtime.NetworkConnectedEventArgs.EventId, OnNetworkConnected); GameEntry.Event.Subscribe(UnityGameFrame.Runtime.NetworkClosedEventArgs.EventId, OnNetworkClosed); GameEntry.Event.Subscribe(UnityGameFrame.Runtime.NetworkMissHeartBeatEventArgs.EventId, OnNetworkMissHeartBeat); GameEntry.Event.Subscribe(UnityGameFrame.Runtime.NetworkErrorEventArgs.EventId, OnNetworkError); GameEntry.Event.Subscribe(UnityGameFrame.Runtime.NetworkCustomErrorEventArgs.EventId, OnNetworkCustomError); }
public void Initialize(INetworkChannel networkChannel) { networkChannel.RegisterHandler(new RecvHandler()); }