private void OnRemoteInvokingEvent(NetMessageHandler msgHandler) { UseMethod2Server msg = msgHandler.GetMessage <UseMethod2Server>(); //Debug.Log("Server接收到UseMethod2Server:" + JsonUtils.ToJson(msg)); int code = 0; string error = ""; try { MethodInfo mInfo = null; foreach (var mData in invokeMothodsInfos) { if (mData.Key.FullName == msg.classFullName) { List <MethodInfo> methods = mData.Value; foreach (var m in methods) { if (m.Name == msg.methodName) { mInfo = m; break; } } } } if (mInfo != null) { List <object> pValues = new List <object>(); ParameterInfo[] parameters = mInfo.GetParameters(); for (int i = 0; i < parameters.Length; i++) { ParameterInfo p = parameters[i]; object v = SimpleJsonUtils.FromJson(p.ParameterType, msg.paramNameValues[p.Name]); pValues.Add(v); } mInfo.Invoke(null, pValues.ToArray()); } else { code = -2; } } catch (Exception e) { code = -1; error = e.ToString(); Debug.LogError(e); } UseMethod2Client toMsg = new UseMethod2Client(); toMsg.code = code; toMsg.error = error; netManager.Send(msgHandler.player, toMsg); //Debug.Log("发送UseMethod2Client:" + JsonUtils.ToJson(toMsg)); }
private void OnMsgFunctionSwitch(NetMessageHandler msgHandler) { FunctionSwitch2Server msg = msgHandler.GetMessage <FunctionSwitch2Server>(); if (msg.functionName == FunctionName) { IsOpenFunction = msg.isOpenFunction; SendSwitchState2Client(msgHandler.player); } }