public SerializedNode AddNode(AbstractLogicNodeEditor logicNodeEditor) { _logicGraphEditorObject.RegisterCompleteObjectUndo("Add Node " + logicNodeEditor.NodeType()); SerializedNode serializedNode = new SerializedNode { NodeType = logicNodeEditor.NodeType(), JSON = JsonUtility.ToJson(logicNodeEditor) }; logicNodeEditor.SerializedNode = serializedNode; if (logicNodeEditor is IInputNode) { _logicGraphEditorObject.LogicGraphData.SerializedInputNodes.Add(serializedNode); } else if (logicNodeEditor is IOutputNode) { _logicGraphEditorObject.LogicGraphData.SerializedOutputNodes.Add(serializedNode); } else { _logicGraphEditorObject.LogicGraphData.SerializedNodes.Add(serializedNode); } logicNodeEditor.Owner = _graphView; var nodeView = new LogicNodeView { userData = logicNodeEditor }; _graphView.AddElement(nodeView); nodeView.Initialize(logicNodeEditor, _edgeConnectorListener); nodeView.MarkDirtyRepaint(); return(serializedNode); }
private void OnChangeToggle() { _logicNodeEditor.Owner.LogicGraphEditorObject.RegisterCompleteObjectUndo("Toggle Change " + _logicNodeEditor.NodeType()); var value = (bool)_propertyInfo.GetValue(_logicNodeEditor, null); value = !value; _propertyInfo.SetValue(_logicNodeEditor, value, null); Dirty(ChangeType.Repaint); }
public void Initialize(AbstractLogicNodeEditor logicNodeEditor, IEdgeConnectorListener connectorListener) { this.LoadAndAddStyleSheet("Styles/LogicNodeView"); if (logicNodeEditor is IInputNode) { AddToClassList("input"); } else if (logicNodeEditor is IOutputNode) { AddToClassList("output"); } _connectorListener = connectorListener; LogicNodeEditor = logicNodeEditor; title = LogicNodeEditor.NodeType(); var contents = this.Q("contents"); var controlsContainer = new VisualElement { name = "controls" }; { _controlsDivider = new VisualElement { name = "divider" }; _controlsDivider.AddToClassList("horizontal"); controlsContainer.Add(_controlsDivider); _controlItems = new VisualElement { name = "items" }; controlsContainer.Add(_controlItems); foreach (var propertyInfo in logicNodeEditor.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { foreach (INodeControlAttribute attribute in propertyInfo.GetCustomAttributes(typeof(INodeControlAttribute), false)) { _controlItems.Add(attribute.InstantiateControl(logicNodeEditor, propertyInfo)); } } } contents.Add(controlsContainer); // Add port input container, which acts as a pixel cache for all port inputs _portInputContainer = new VisualElement { name = "portInputContainer", // clippingOptions = ClippingOptions.ClipAndCacheContents, pickingMode = PickingMode.Ignore }; Add(_portInputContainer); List <LogicSlot> foundSlots = new List <LogicSlot>(); logicNodeEditor.GetSlots(foundSlots); AddPorts(foundSlots); SetPosition(new Rect(logicNodeEditor.Position.x, logicNodeEditor.Position.y, 0, 0)); UpdatePortInputs(); base.expanded = logicNodeEditor.Expanded; RefreshExpandedState(); UpdatePortInputVisibilities(); }
void OnValueChanged(ChangeEvent <Enum> evt) { var value = (Enum)_propertyInfo.GetValue(_logicNodeEditor, null); if (!evt.newValue.Equals(value)) { _logicNodeEditor.Owner.LogicGraphEditorObject.RegisterCompleteObjectUndo("Change " + _logicNodeEditor.NodeType()); _propertyInfo.SetValue(_logicNodeEditor, evt.newValue, null); } }