public void AddNode(NodeEditor nodeEditor)
        {
            _logicGraphEditorObject.RegisterCompleteObjectUndo("Add Node " + nodeEditor.NodeType());

            SerializedNode serializedNode = new SerializedNode
            {
                NodeType = nodeEditor.NodeType(),
                JSON     = JsonUtility.ToJson(nodeEditor)
            };

            nodeEditor.SerializedNode = serializedNode;
            if (nodeEditor is IInputNode)
            {
                _logicGraphEditorObject.LogicGraphData.SerializedInputNodes.Add(serializedNode);
            }
            else if (nodeEditor is IOutputNode)
            {
                _logicGraphEditorObject.LogicGraphData.SerializedOutputNodes.Add(serializedNode);
            }
            else
            {
                _logicGraphEditorObject.LogicGraphData.SerializedNodes.Add(serializedNode);
            }

            nodeEditor.Owner = _graphView;
            var nodeView = new LogicNodeView {
                userData = nodeEditor
            };

            _graphView.AddElement(nodeView);
            nodeView.Initialize(nodeEditor, _edgeConnectorListener);
            nodeView.Dirty(ChangeType.Repaint);
        }
Пример #2
0
        public void Initialize(NodeEditor nodeEditor, IEdgeConnectorListener connectorListener)
        {
            AddStyleSheetPath("Styles/LogicNodeView");

            _connectorListener = connectorListener;
            NodeEditor         = nodeEditor;
            title = NodeEditor.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
                         nodeEditor.GetType().GetProperties(BindingFlags.Instance |
                                                            BindingFlags.Public |
                                                            BindingFlags.NonPublic))
                {
                    foreach (INodeControlAttribute attribute in
                             propertyInfo.GetCustomAttributes(typeof(INodeControlAttribute), false))
                    {
                        _controlItems.Add(attribute.InstantiateControl(nodeEditor, propertyInfo));
                    }
                }
            }
            contents.Add(controlsContainer);

            List <PortDescription> foundSlots = new List <PortDescription>();

            nodeEditor.GetSlots(foundSlots);
            AddSlots(foundSlots);

            SetPosition(new Rect(nodeEditor.Position.x, nodeEditor.Position.y, 0, 0));
            base.expanded = nodeEditor.Expanded;
            RefreshExpandedState();
        }
Пример #3
0
        private void OnChangeToggle()
        {
            _nodeEditor.Owner.LogicGraphEditorObject.RegisterCompleteObjectUndo("Toggle Change " + _nodeEditor.NodeType());
            var value = (bool)_propertyInfo.GetValue(_nodeEditor, null);

            value = !value;
            _propertyInfo.SetValue(_nodeEditor, value, null);
            Dirty(ChangeType.Repaint);
        }
Пример #4
0
        void OnValueChanged(ChangeEvent <Enum> evt)
        {
            var value = (Enum)_propertyInfo.GetValue(_nodeEditor, null);

            if (!evt.newValue.Equals(value))
            {
                _nodeEditor.Owner.LogicGraphEditorObject.RegisterCompleteObjectUndo("Change " + _nodeEditor.NodeType());
                _propertyInfo.SetValue(_nodeEditor, evt.newValue, null);
            }
        }