static public string GetMatchExpValue(ActorBrain actorBrain, string text, string def) { Debug.Log("Compare.GetMatchExpValue. text = '" + text + "', def = " + def); string varname = GetMatchVarName(text); Debug.Log("Compare.GetMatchExpValue. varname = '" + varname + "'"); if (varname != null && varname.Length > 0) { string varvalue = actorBrain.GetVarValue(varname); Debug.Log("Compare.GetMatchExpValue. varvalue = '" + varvalue + "'"); if (varvalue != null) { return(varvalue); } } else { string funcname = GetMatchFuncName(text); Debug.Log("Compare.GetMatchExpValue. funcname = '" + funcname + "'"); if (funcname != null && funcname.Length > 0) { string funcvalue = actorBrain.GetFuncValue(funcname); Debug.Log("Compare.GetMatchExpValue. funcvalue = '" + funcvalue + "'"); if (funcvalue != null) { return(funcvalue); } } } Debug.Log("Compare.GetMatchExpValue. return def = '" + def + "'"); return(def); }
static public string ResolveMatchExpresions(ActorBrain actorBrain, string text) { if (text == null) { return(null); } MatchCollection matchListVars = regexVar.Matches(text); MatchCollection matchListFunc = regexFunc.Matches(text); List <string> listTmpVars = new List <string>(); List <string> listTmpFunc = new List <string>(); // Obtiene los nombres de variables y los añade a la lista foreach (Match match in matchListVars) { GroupCollection groups = match.Groups; string varname = groups[2].Value; listTmpVars.Add(varname); // Debug.Log("GAIMLLoader. var = " + varname); } // Sustituye cada nombre de variable por su valor foreach (string varname in listTmpVars) { string varvalue = actorBrain.GetVarValue(varname); if (varvalue == null) { varvalue = "VAR \"" + varname + "\" NO EXISTS!"; } text = Regex.Replace(text, "\\$\\{" + varname + "\\}", varvalue); } // Obtiene los nombres de las funciones y los añade a la lista foreach (Match match in matchListFunc) { GroupCollection groups = match.Groups; string funcname = groups[2].Value.Substring("ffunc:".Length); listTmpFunc.Add(funcname); // Debug.Log("GAIMLLoader. func = " + funcname); } // Sustituye cada nombre de función por su valor foreach (string funcname in listTmpFunc) { string funcvalue = actorBrain.GetFuncValue(funcname); if (funcvalue == null) { funcvalue = "FUNC \"" + funcname + "\" NO EXISTS!"; } text = Regex.Replace(text, "\\$\\{ffunc\\:" + funcname + "\\}", funcvalue); } return(text); }