public void SetCommand(GMCommandWrap commandWrap) { this.m_detailCommandWrap = commandWrap; this.m_lbCommandDesc.Text = commandWrap.conf.messageDesc; string[] paramsList = commandWrap.conf.messageFormat.Split(';'); this.m_gmCommandParamContainer.EnsureSize <GMCommandParamItem>(paramsList.Length); for (int i = 0; i < paramsList.Length; ++i) { GMCommandParamItem item = this.m_gmCommandParamContainer.GetChild <GMCommandParamItem>(i); item.SetParamName(paramsList[i]); item.Visible = true; } }
private void OnBtnSendGMCommandClick(GameObject btnSendCommand) { Dictionary <string, string> injectorParams = new Dictionary <string, string>(); IMessage gmMessage = Activator.CreateInstance(this.m_detailCommandWrap.MessageType) as IMessage; PropertyInfo[] fieldInfos = this.m_detailCommandWrap.MessageType.GetProperties(BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public); if (fieldInfos.Length != this.m_gmCommandParamContainer.ChildCount) { Debug.LogError($"command :{this.m_detailCommandWrap.CommandName} params error"); } for (int i = 0; i < this.m_gmCommandParamContainer.ChildCount; ++i) { GMCommandParamItem paramItem = this.m_gmCommandParamContainer.GetChild <GMCommandParamItem>(i); string paramValue = string.IsNullOrEmpty(paramItem.ParamValue) ? "0" : paramItem.ParamValue; fieldInfos[i].SetValue(gmMessage, Convert.ChangeType(paramValue, fieldInfos[i].PropertyType)); injectorParams.Add(fieldInfos[i].Name.ToLower(), paramItem.ParamValue); } //执行各个模块的注入操作 if (this.m_detailCommandWrap.GMCommandInjector != null) { List <IMessage> messageList = this.m_detailCommandWrap.GMCommandInjector(injectorParams); if (messageList == null) { return; } this.sendMessageList.Clear(); this.sendMessageList.AddRange(messageList); BatchSend(); } else { GameEvents.NetWorkEvents.SendAsyncMsg.SafeInvoke(gmMessage); TimeModule.Instance.SetTimeout(() => { GameEvents.NetWorkEvents.SendAsyncMsg.SafeInvoke(new CSPlayerInfoRequest()); }, 0.5f); } }