private GraphViewChange GraphViewChanged(GraphViewChange graphViewChange)
        {
            if (graphViewChange.edgesToCreate != null)
            {
                Debug.Log("EDGES TO CREATE " + graphViewChange.edgesToCreate.Count);
            }

            if (graphViewChange.movedElements != null)
            {
                _logicGraphEditorObject.RegisterCompleteObjectUndo("Graph Element Moved.");
                foreach (var element in graphViewChange.movedElements)
                {
                    NodeEditor nodeEditor = element.userData as NodeEditor;
                    nodeEditor.Position            = element.GetPosition().position;
                    nodeEditor.SerializedNode.JSON = JsonUtility.ToJson(nodeEditor);
                }
            }

            if (graphViewChange.elementsToRemove != null)
            {
                _logicGraphEditorObject.RegisterCompleteObjectUndo("Deleted Graph Elements.");

                foreach (var nodeView in graphViewChange.elementsToRemove.OfType <LogicNodeView>())
                {
                    _logicGraphEditorObject.LogicGraphData.SerializedNodes.Remove(nodeView.NodeEditor.SerializedNode);
                    _logicGraphEditorObject.LogicGraphData.SerializedInputNodes.Remove(nodeView.NodeEditor
                                                                                       .SerializedNode);
                    _logicGraphEditorObject.LogicGraphData.SerializedOutputNodes.Remove(nodeView.NodeEditor
                                                                                        .SerializedNode);
                }

                foreach (var edge in graphViewChange.elementsToRemove.OfType <Edge>())
                {
                    _logicGraphEditorObject.LogicGraphData.SerializedEdges.Remove(edge.userData as SerializedEdge);
                }
            }

            return(graphViewChange);
        }
        private void AddNodeFromload(SerializedNode serializedNode)
        {
            NodeEditor nodeEditor = null;

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var type in assembly.GetTypes())
                {
                    if (type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(NodeEditor)))
                    {
                        var attrs = type.GetCustomAttributes(typeof(NodeEditorType), false) as NodeEditorType[];
                        if (attrs != null && attrs.Length > 0)
                        {
                            if (attrs[0].NodeType.Name == serializedNode.NodeType)
                            {
                                nodeEditor = (NodeEditor)Activator.CreateInstance(type);
                            }
                        }
                    }
                }
            }

            if (nodeEditor != null)
            {
                JsonUtility.FromJsonOverwrite(serializedNode.JSON, nodeEditor);
                nodeEditor.SerializedNode = serializedNode;
                nodeEditor.Owner          = _graphView;
                var nodeView = new LogicNodeView {
                    userData = nodeEditor
                };
                _graphView.AddElement(nodeView);
                nodeView.Initialize(nodeEditor, _edgeConnectorListener);
                nodeView.Dirty(ChangeType.Repaint);
            }
            else
            {
                Debug.LogWarning("No NodeEditor found for " + serializedNode);
            }
        }
Ejemplo n.º 3
0
        public VectorControlView(string label, string subLabel1, string subLabel2, string subLabel3, string subLabel4, NodeEditor node, PropertyInfo propertyInfo)
        {
            var components = Array.IndexOf(validTypes, propertyInfo.PropertyType) + 1;

            if (components == -1)
            {
                throw new ArgumentException("Property must be of type float, Vector2, Vector3 or Vector4.", "propertyInfo");
            }

            AddStyleSheetPath("Styles/VectorControlView");
            m_Node         = node;
            m_PropertyInfo = propertyInfo;

            label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);
            if (!string.IsNullOrEmpty(label))
            {
                Add(new Label(label));
            }

            m_Value = GetValue();
            AddField(0, subLabel1);
            if (components > 1)
            {
                AddField(1, subLabel2);
            }
            if (components > 2)
            {
                AddField(2, subLabel3);
            }
            if (components > 3)
            {
                AddField(3, subLabel4);
            }
        }
Ejemplo n.º 4
0
 public VisualElement InstantiateControl(NodeEditor nodeEditor, PropertyInfo propertyInfo)
 {
     return(new ToggleControlView(_label, nodeEditor, propertyInfo));
 }
 public BooleanPortDescription(NodeEditor owner, string memberName, string displayName,
                               PortDirection portDirection) : base(owner, memberName, displayName, portDirection)
 {
 }