/// <summary> /// 发送网络消息 /// </summary> public void SendHotfixMsg(IHotfixNetMessage msg) { HotfixLogger.Log($"Send hotfix net message : {msg.GetType()}"); int msgID = _types.GetKeyByValue(msg.GetType()); DefaultNetworkPackage package = new DefaultNetworkPackage(); package.IsHotfixPackage = true; package.MsgID = msgID; package.BodyBytes = ProtobufHelper.Encode(msg); NetworkManager.Instance.SendMessage(package); }
/// <summary> /// 接收消息回调函数 /// </summary> private void OnHandleHotfixMsg(INetworkPackage pack) { DefaultNetworkPackage package = pack as DefaultNetworkPackage; Type msgType = _types.GetValueByKey(package.MsgID); HotfixLogger.Log($"Handle hotfix net message : {msgType}"); object instance = Activator.CreateInstance(msgType); var message = ProtobufHelper.Decode(instance, package.BodyBytes); HotfixLogger.Log(message.ToString()); }
public static void Start() { HotfixLogger.Log("Hello ILRuntime World"); HotfixNetManager.Instance.Start(); Demo.Instance.Start(); }