示例#1
0
        GraphViewChange GraphViewChanged(GraphViewChange graphViewChange)
        {
            if (graphViewChange.edgesToCreate != null)
            {
                foreach (var edge in graphViewChange.edgesToCreate)
                {
                    var leftSlot  = edge.output.GetSlot();
                    var rightSlot = edge.input.GetSlot();
                    if (leftSlot != null && rightSlot != null)
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Connect Edge");
                        m_Graph.Connect(leftSlot.slotReference, rightSlot.slotReference);
                    }
                }
                graphViewChange.edgesToCreate.Clear();
            }

            if (graphViewChange.movedElements != null)
            {
                foreach (var element in graphViewChange.movedElements)
                {
                    var node = element.userData as INode;
                    if (node == null)
                    {
                        continue;
                    }

                    var drawState = node.drawState;
                    drawState.position = element.GetPosition();
                    node.drawState     = drawState;
                }
            }

            var nodesToUpdate = m_NodeViewHashSet;

            nodesToUpdate.Clear();

            if (graphViewChange.elementsToRemove != null)
            {
                m_Graph.owner.RegisterCompleteObjectUndo("Remove Elements");
                m_Graph.RemoveElements(graphViewChange.elementsToRemove.OfType <MaterialNodeView>().Select(v => (INode)v.node),
                                       graphViewChange.elementsToRemove.OfType <Edge>().Select(e => (IEdge)e.userData));
                foreach (var edge in graphViewChange.elementsToRemove.OfType <Edge>())
                {
                    if (edge.input != null)
                    {
                        var materialNodeView = edge.input.node as MaterialNodeView;
                        if (materialNodeView != null)
                        {
                            nodesToUpdate.Add(materialNodeView);
                        }
                    }
                    if (edge.output != null)
                    {
                        var materialNodeView = edge.output.node as MaterialNodeView;
                        if (materialNodeView != null)
                        {
                            nodesToUpdate.Add(materialNodeView);
                        }
                    }
                }
            }

            foreach (var node in nodesToUpdate)
            {
                node.UpdatePortInputVisibilities();
            }

            UpdateEdgeColors(nodesToUpdate);

            return(graphViewChange);
        }