/// <summary> /// 判断变量格式是否正确,并赋值给`variable`。 /// `isExist`: 指定变量在使用之前,是否存在。 /// </summary> /// <param name="varStr"></param> /// <param name="isExist"></param> /// <param name="variable"></param> /// <param name="error"></param> /// <returns></returns> protected bool IsMatchVar(string varStr, bool isExist, ref string variable, out string error) { if (!RegexUtility.IsMatchVariable(varStr)) { error = GetMatchVariableErrorString(varStr); return(false); } if (ScenarioBlackboard.Contains(varStr) != isExist) { error = GetVariableExistErrorString(varStr, !isExist); return(false); } variable = varStr; error = null; return(true); }
/// <summary> /// 如果是数字,直接赋值;如果是变量,就获取变量 /// </summary> /// <param name="numOrVar"></param> /// <param name="value"></param> /// <param name="error"></param> /// <returns></returns> protected bool ParseOrGetVarValue(string numOrVar, ref int value, out string error) { if (!int.TryParse(numOrVar, out value)) { if (!RegexUtility.IsMatchVariable(numOrVar)) { error = GetMatchVariableErrorString(numOrVar); return(false); } if (!ScenarioBlackboard.TryGet(numOrVar, out value)) { error = GetVariableExistErrorString(numOrVar, false); return(false); } } error = null; return(true); }
protected override ActionStatus Run(IGameAction gameAction, IScenarioContent content, MenuArgs args, out string error) { ScenarioAction action; if (!ParseAction <ScenarioAction>(gameAction, out action, out error)) { return(ActionStatus.Error); } // 重置变量为-1 ScenarioBlackboard.Set(args.menuName, -1); // 打开UI UIMenuPanel panel = UIManager.views.OpenView <UIMenuPanel>(UINames.k_UIMenuPanel, false); // 设置选项并传入选择后的处理方法 if (!panel.SetOptions(args.options, selected => { // 选择完成后的处理 // 关闭菜单UI UIManager.views.CloseView(UINames.k_UIMenuPanel); // 设置选择的按钮 ScenarioBlackboard.Set(args.menuName, selected); // 继续剧本 action.MenuDone(); })) { error = string.Format( "{0} ParseArgs error: set menu options error.", typeName); return(ActionStatus.Error); } error = null; return(ActionStatus.WaitMenuOption); }