/// <summary> /// 获取标题提示(信息为 权限+当前所有命令模块) /// </summary> /// <returns></returns> public string GetCheatCommandTips() { //string com = ""; //for (int i = 0; i < _cheatItems.Count; i++) //{ // com += ConstLanguage.Get(ConstLanguage.CommandName, _cheatItems[i].GetType().Name) + " "; //} return(ConstLanguage.Get(ConstLanguage.CommandTips, GetRootLevelDetail(CurrenLevel).Name)); }
/// <summary> /// 获取指定命令的帮助信息 /// </summary> public string GetTargetCommandHelp(string cmdName) { CheatItem item = _cheatItems.Find((i) => i.GetType().Name == cmdName); if (item == null) { return(ConstLanguage.Get(ConstLanguage.ErrorNotFindCommand, cmdName)); } CommandInfo expl = (CommandInfo)System.Attribute.GetCustomAttribute(item.GetType(), typeof(CommandInfo)); return(ConstLanguage.Get("{0}>>>>>{1}\n\n{2}", string.IsNullOrEmpty(expl.Name) ? item.GetType().Name : expl.Name, expl.Explain, item.GetCommandDescList())); }
private string RunMethod(CheatItem item, string name, object[] parms) { try { //获取模块信息 MethodInfo met = item.GetType().GetMethod(name); CommandInfo info = GetCommandInfo(met); if (info != null && !info.CanExecute) { return(ConstLanguage.Get(ConstLanguage.ErrorCommandPolicy, info.RequireLevelName)); } ParameterInfo[] paramsInfo = met.GetParameters(); if (parms != null) { if (parms.Length != paramsInfo.Length) { Array.Resize <object>(ref parms, paramsInfo.Length); } for (int i = 0; i < paramsInfo.Length; i++) { if (parms[i] != null) { parms[i] = Convert.ChangeType(parms[i], paramsInfo[i].ParameterType); } else { parms[i] = paramsInfo[i].DefaultValue; } } } object res = met.Invoke(item, parms); return(res == null ? "" : ConstLanguage.Get(ConstLanguage.CommandResult, res.ToString())); } catch (Exception ex) { string cmdList = item.GetCommandDescList(); if (string.IsNullOrEmpty(cmdList)) { return(ConstLanguage.Get(ConstLanguage.ErrorCommand, ex.Message)); } return(ConstLanguage.Get(ConstLanguage.ErrorCommandParams, ex.Message, cmdList)); } }
/// <summary> /// 获取所有命令列表 /// </summary> /// <returns></returns> public string GetCommandList() { string com = ""; for (int i = 0; i < _cheatItems.Count; i++) { CommandInfo expl = (CommandInfo)System.Attribute.GetCustomAttribute(_cheatItems[i].GetType(), typeof(CommandInfo)); if (!expl.CanExecute) { continue; } com += ConstLanguage.Get(ConstLanguage.CommandName, _cheatItems[i].GetType().Name); if (expl != null) { com += ": " + expl.Explain + "\n"; } } return(ConstLanguage.Get(ConstLanguage.CommandHelp, com)); }
/// <summary> /// 执行命令 /// </summary> /// <param name="command"></param> /// <returns></returns> public string RunCommand(string command) { if (string.IsNullOrEmpty(command)) { return(ConstLanguage.ErrorNullCommand); } command = command.Trim(); string[] cmds = command.Split(' '); CheatItem item = _cheatItems.Find((i) => i.GetType().Name == cmds[0]); if (item == null) { return(ConstLanguage.Get(ConstLanguage.ErrorNotFindCommand, cmds[0])); } //无参数默认命令 if (cmds.Length == 1) { #region 处理只有一个单位的默认命令 return(RunMethod(item, "DefaultSingleMethod", null)); #endregion } //有一个参数默认命令 if (item.GetCommandNameList().FindIndex((cmdName) => cmdName == cmds[1]) == -1) { object[] vals = new object[cmds.Length - 1]; Array.Copy(cmds, 1, vals, 0, vals.Length); return(RunMethod(item, "DefaultOneParamsMethod", vals)); } string name = cmds[1]; object[] parms = new object[cmds.Length - 2]; Array.Copy(cmds, 2, parms, 0, parms.Length); return(RunMethod(item, name, parms)); }
public void RefreshTips() { _targetText.text = ConstLanguage.Get(ConstLanguage.TargetInfo, GetCurrentTargetName()); _tipsText.text = CheatSystemManager.GetInstance.GetCheatCommandTips(); }