public static float GetValueFromINI(string key) { if (string.IsNullOrEmpty(key)) { return(0f); } else { if (key.IndexOf('(') >= 0) { var solver = new TGExpressionParser(); int start = key.IndexOf('(') + 1; int end = key.IndexOf(')'); var sliced = key.Substring(start, end - start).Split(','); Debug.Log("Sliced string: " + sliced); for (int i = 0; i < sliced.Length; i++) { string cutkey = sliced[i]; Debug.Log("Cut Key: " + cutkey); key = key.Replace(cutkey, TGController.Instance.gameConfig.GetValue(cutkey, 0f).ToString()); } Debug.Log("String Converted: " + key); return((float)solver.EvaluateExpression(key).Value); } else { float retval = 0f; if (float.TryParse(key, out retval)) { return(retval); } else { return(TGController.Instance.gameConfig.GetValue(key, 0)); } } } }
public float ResolveEquation(string equation) { string resolved = equation; foreach (var i in inputs) { if (resolved.IndexOf(i.key) >= 0) { string v = i.GetValue().ToString(); if (string.IsNullOrEmpty(v)) { v = "0"; } resolved = resolved.Replace(i.key, v); } } return((float)m_solver.EvaluateExpression(resolved).Value); }