void Update() { if (sEvents.Count > 0) { while (sEvents.Count > 0) { KeyValuePair <int, ByteBuffer> _event = sEvents.Dequeue(); int msgID = _event.Key; ByteBuffer msg = _event.Value; //处理C#中的网络回调 if (m_CSharpCallback.ContainsKey(msgID)) { m_CSharpCallback[msgID](new MemoryStream(msg.ToBytes())); } //处理Lua中的网络回调 else if (m_LuaCallback.ContainsKey(msgID)) { LuaNetCallback evt = m_LuaCallback[msgID]; //调用lua中的函数 形如: module.func(msg) Util.CallMethod(evt.module, evt.func, msg); } else { Log.Error("未处理的消息 : " + msgID); } } } }
//绑定Lua网络事件回调,仅在lua中调用 public void BindLuaCallback(int id, string module, string func) { LuaNetCallback evt = new LuaNetCallback(); evt.module = module; evt.func = func; m_LuaCallback[id] = evt; }