protected override void OnPlayerLogin(LiteNetLibManager.Player player) { foreach (var mData in invokeMothodsInfos) { List <MethodInfo> methods = mData.Value; foreach (MethodInfo m in methods) { RemoteInvokingAttribute attribute = GetCustomAttribute <RemoteInvokingAttribute>(m); MethodData2Client msg = new MethodData2Client(); msg.data.methodType = attribute.methodType; msg.data.showName = attribute.name; msg.data.description = attribute.description; msg.data.classFullName = mData.Key.FullName; msg.data.methodName = m.Name; ParameterInfo[] parameters = m.GetParameters(); IEnumerable <ParamsDescriptionAttribute> paramsDescriptions = GetCustomAttributes <ParamsDescriptionAttribute>(m); for (int i = 0; i < parameters.Length; i++) { ParameterInfo p = parameters[i]; ParamsData paramsData = new ParamsData(); ParamsDescriptionAttribute paramsDescription = ParamsDescriptionAttribute.GetParamsDescription(paramsDescriptions, p.Name);; if (paramsDescription != null) { paramsData.descriptionName = paramsDescription.paramsDescriptionName; } paramsData.paraName = p.Name; paramsData.paraTypeFullName = p.ParameterType.FullName; try { paramsData.defaultValueStr = GetDefaultValueString(mData.Key, p.ParameterType, paramsDescription); } catch (Exception e) { Debug.LogError(mData.Key.FullName + "." + m.Name + "\n" + e); } paramsData.selectItemValues = GetTypeSelectItemValues(p.ParameterType, paramsDescription); msg.data.paramsDatas.Add(paramsData); } Debug.Log("Send MethodData2Client:" + JsonUtility.ToJson(msg)); netManager.Send(player, msg); } } }
public override void OnStart() { invokeMothodsInfos.Clear(); Assembly asm = Assembly.GetAssembly(typeof(RemoteInvokingAttribute)); Type[] types = asm.GetExportedTypes(); foreach (var t in types) { MethodInfo[] infos = t.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); foreach (var m in infos) { RemoteInvokingAttribute attribute = GetCustomAttribute <RemoteInvokingAttribute>(m); if (attribute != null) { //Debug.Log("RemoteInvokingAttribute=========>" + t.FullName+"."+m.Name); AddMethodInfo(t, m); } } } msgManager.RegisterMessage <UseMethod2Server>(OnRemoteInvokingEvent); }