///Replace the text of the statement found in brackets, with blackboard variables ToString and returns a Statement copy public IStatement BlackboardReplace(IBlackboard bb) { var copy = ParadoxNotion.Serialization.JSONSerializer.Clone <Statement>(this); copy.text = copy.text.ReplaceWithin('[', ']', (input) => { object o = null; if (bb != null) //referenced blackboard replace { var v = bb.GetVariable(input, typeof(object)); if (v != null) { o = v.value; } } if (input.Contains("/")) //global blackboard replace { var globalBB = GlobalBlackboard.Find(input.Split('/').First()); if (globalBB != null) { var v = globalBB.GetVariable(input.Split('/').Last(), typeof(object)); if (v != null) { o = v.value; } } } return(o != null ? o.ToString() : input); }); return(copy); }
///Replace the text of the statement found in brackets, with blackboard variables ToString and returns a Statement copy public Statement BlackboardReplace(IBlackboard bb) { var copy = ParadoxNotion.Serialization.JSONSerializer.Clone <Statement>(this); var s = text; var i = 0; while ((i = s.IndexOf('[', i)) != -1) { var end = s.Substring(i + 1).IndexOf(']'); var input = s.Substring(i + 1, end); //what's in the brackets var output = s.Substring(i, end + 2); //what should be replaced (includes brackets) object o = null; if (bb != null) //referenced blackboard replace { var v = bb.GetVariable(input, typeof(object)); if (v != null) { o = v.value; } } if (input.Contains("/")) //global blackboard replace { var globalBB = GlobalBlackboard.Find(input.Split('/').First()); if (globalBB != null) { var v = globalBB.GetVariable(input.Split('/').Last(), typeof(object)); if (v != null) { o = v.value; } } } s = s.Replace(output, o != null? o.ToString() : output); i++; } copy.text = s; return(copy); }
public override void OnInspectorGUI() { EditorGUILayout.PropertyField(identifierProp); var existing = GlobalBlackboard.Find(bb.name); if (existing != bb && existing != null && !EditorUtility.IsPersistent(bb)) { EditorUtils.MarkLastFieldError("Another Global Blackboard has the same identifier name. Please rename either."); } EditorGUILayout.PropertyField(dontDestroyProp); BlackboardEditor.ShowVariables(bb); EditorUtils.EndOfInspector(); serializedObject.ApplyModifiedProperties(); if (Event.current.isMouse) { Repaint(); } }