public void NotifyFieldChange(MathBookField field, MathBookField.Change change) { if (mathBook == null) { return; } foreach (IMathBookFieldNode fieldNode in mathBook.nodes.OfType <IMathBookFieldNode>()) { if (change.role == MathBookField.DataRole.Name) { var oldName = (string)change.oldValue; if (fieldNode.fieldName == oldName) { fieldNode.fieldName = (string)change.newValue; } } if (fieldNode.fieldName == field.name) { fieldNode.NotifyChange(); } } if (change.role == MathBookField.DataRole.Value) { ComputeOutputs(); } }
public void RemoveField(MathBookField field) { if (field == null || ((field.direction == MathBookField.Direction.Input) && m_Inputs == null) || ((field.direction == MathBookField.Direction.Output) && m_Outputs == null)) { return; } if (field.direction == MathBookField.Direction.Input) { if (m_Inputs == null) { return; } m_Inputs.Remove(field); } else { if (m_Outputs == null) { return; } m_Outputs.Remove(field); } field.mathBook = null; NotifyChange(); }
public void AddField(MathBookField field) { if (field == null) { return; } if (field.direction == MathBookField.Direction.Input) { if (m_Inputs == null) { m_Inputs = new List <MathBookField>(); } m_Inputs.Add(field); } else { if (m_Outputs == null) { m_Outputs = new List <MathBookField>(); } m_Outputs.Add(field); } field.mathBook = mathBook; NotifyChange(); }
public BlackboardFieldPropertyView(MathBookField field) { m_Field = field; m_ExposedToggle = new Toggle(); m_ExposedToggle.RegisterValueChangedCallback(OnExposedToggle); AddRow("Exposed", m_ExposedToggle); if (field.direction == MathBookField.Direction.Input) { AddRow("Value", m_ValueField = new TextField()); m_ValueField.RegisterCallback <ChangeEvent <string> >(e => OnDefaultValueChanged()); } else { AddRow("Value", m_ValueLabel = new Label()); } AddRow("Tooltip", m_TooltipField = new TextField()); AddToClassList("blackboardFieldPropertyView"); UpdateData(); field.changed += (e, c) => UpdateData(); m_TooltipField.RegisterCallback <ChangeEvent <string> >(e => OnToolTipChanged()); }
private void OnDragPerformEvent(DragPerformEvent e) { var selection = DragAndDrop.GetGenericData("DragSelection") as List <ISelectable>; if (selection == null) { return; } IEnumerable <BlackboardField> fields = selection.OfType <BlackboardField>(); if (!fields.Any()) { return; } Vector2 localPos = (e.currentTarget as VisualElement).ChangeCoordinatesTo(m_GraphView.contentViewContainer, e.localMousePosition); foreach (BlackboardField field in fields) { MathBookField bookField = field.userData as MathBookField; if (bookField == null) { continue; } MathNode fieldNode = null; if (bookField.direction == MathBookField.Direction.Input) { var varFieldNode = ScriptableObject.CreateInstance <MathBookInputNode>(); varFieldNode.fieldName = bookField.name; fieldNode = varFieldNode; } else { var resFieldNode = ScriptableObject.CreateInstance <MathBookOutputNode>(); resFieldNode.fieldName = bookField.name; fieldNode = resFieldNode; } fieldNode.m_Position = localPos; m_GraphView.window.AddNode(fieldNode); var visualNode = m_GraphView.window.CreateNode(fieldNode) as Node; m_GraphView.AddElement(visualNode); localPos += new Vector2(0, 25); } }
public MathBookField FindField(string name) { MathBookField field = inputs.Find(e => e.name == name); if (field == null) { field = outputs.Find(e => e.name == name); } return(field); }
public void ReorderField(int index, MathBookField field) { List <MathBookField> list = field.direction == MathBookField.Direction.Input ? m_Inputs : m_Outputs; if (index > list.IndexOf(field)) { index--; } list.Remove(field); list.Insert(index, field); NotifyChange(); }
public void ComputeOutputs() { if (mathBook == null) { return; } foreach (MathBookOutputNode outputNode in mathBook.nodes.OfType <MathBookOutputNode>()) { MathBookField field = outputNode.field; if (field != null) { field.value = outputNode.Evaluate(); } } }