public void SetParam(string name, string evaluationString, List <Param> evaluationParameters = null, bool check = true) { float value = 0; value = ExpressionSolver.CalculateFloat(evaluationString, evaluationParameters); SetParam(name, value, check); }
public float CalcParamAfterChange(ParamChanges changer) { List <float> values = new List <float>(); InitParam(changer.aimParam); foreach (Param p in changer.Parameters) { InitParam(p); values.Add(saveInfo.paramsDictionary[p.paramGUID]); } return(ExpressionSolver.CalculateFloat(changer.changeString, values)); }
private void DrawChanges(Path path) { ParamChanges removingChanger = null; for (int i = 0; i < path.changes.Count; i++) { GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) }); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("delete")) { removingChanger = path.changes[i]; } if (GUILayout.Button("add param")) { Undo.RecordObject(p, "add path changer param"); path.changes[i].AddParam(p.Game.parameters[0]); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (!p.Game.parameters.Contains(path.changes[i].aimParam)) { if (p.Game.parameters.Count > 0) { path.changes[i].aimParam = p.Game.parameters[0]; } else { removingChanger = path.changes[i]; continue; } } EditorGUI.BeginChangeCheck(); int paramIndex = EditorGUILayout.Popup(p.Game.parameters.IndexOf(path.changes[i].aimParam), p.Game.parameters.Select(x => x.paramName).ToArray(), GUILayout.Width(100)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(p, "chose path changer param"); path.changes[i].aimParam = p.Game.parameters[paramIndex]; } GUILayout.Label("=", GUILayout.Width(15)); GUI.backgroundColor = Color.white; try { List <float> paramsV = new List <float>(); foreach (Param p in path.changes[i].Parameters) { paramsV.Add(1); } ExpressionSolver.CalculateFloat(path.changes[i].changeString, paramsV); } catch { GUI.color = Color.red; } EditorGUI.BeginChangeCheck(); string changeString = EditorGUILayout.TextField(path.changes[i].changeString); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(p, "change path changer string"); path.changes[i].changeString = changeString; } GUI.color = Color.white; Param removingParam = null; EditorGUILayout.EndHorizontal(); for (int j = 0; j < path.changes[i].Parameters.Count; j++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("[p" + j + "]", GUILayout.Width(35)); if (!p.Game.parameters.Contains(path.changes[i].Parameters[j])) { if (p.Game.parameters.Count > 0) { path.changes[i].setParam(p.Game.parameters[0], j); } else { removingParam = path.changes[i].Parameters[j]; continue; } } EditorGUI.BeginChangeCheck(); int v = EditorGUILayout.Popup(p.Game.parameters.IndexOf(path.changes[i].Parameters[j]), p.Game.parameters.Select(x => x.paramName).ToArray()); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(p, "change path changer sub param"); path.changes[i].setParam(p.Game.parameters[v], j); } GUI.color = Color.red; if (GUILayout.Button("", GUILayout.Height(15), GUILayout.Width(15))) { removingParam = path.changes[i].Parameters[j]; } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); } if (removingParam != null) { Undo.RecordObject(p, "remove path changer sub param"); path.changes[i].RemoveParam(removingParam); } GUI.color = Color.white; } if (removingChanger != null) { Undo.RecordObject(p, "remove path changer param"); path.changes.Remove(removingChanger); } }