Esempio n. 1
0
        void DeleteSelectionImplementation(string operationName, GraphView.AskUser askUser)
        {
            foreach (var selectable in selection)
            {
                var field = selectable as BlackboardField;
                if (field != null && field.userData != null)
                {
                    if (graph.isSubGraph)
                    {
                        if (EditorUtility.DisplayDialog("Sub Graph Will Change", "If you remove a property and save the sub graph, you might change other graphs that are using this sub graph.\n\nDo you want to continue?", "Yes", "No"))
                        {
                            break;
                        }
                        return;
                    }
                }
            }

            graph.owner.RegisterCompleteObjectUndo(operationName);
            graph.RemoveElements(selection.OfType <MaterialNodeView>().Where(v => !(v.node is SubGraphOutputNode) && v.node.canDeleteNode).Select(x => x.node),
                                 selection.OfType <Edge>().Select(x => x.userData).OfType <IEdge>(),
                                 selection.OfType <ShaderGroup>().Select(x => x.userData));

            foreach (var selectable in selection)
            {
                var field = selectable as BlackboardField;
                if (field != null && field.userData != null)
                {
                    var property = (AbstractShaderProperty)field.userData;
                    graph.RemoveShaderProperty(property.guid);
                }
            }

            selection.Clear();
        }
Esempio n. 2
0
        private void DeleteSelectionImplementation(string operationName, GraphView.AskUser askUser)
        {
            GraphElement[] selected = _graphView.selection.Where(e => e is GraphElement).Cast <GraphElement>().ToArray();

            foreach (var sel in selected)
            {
                switch (sel)
                {
                case BaseNode node:
                case Edge edge:
                    sel.RemoveFromHierarchy();
                    break;

                case Group group:
                    var children = group.Children().ToArray();
                    foreach (var n in children)
                    {
                        n.RemoveFromHierarchy();
                        group.parent.Add(n);
                    }
                    group.RemoveFromHierarchy();
                    break;
                }
            }
            _graphView.selection.Clear();
        }
Esempio n. 3
0
 void DeleteSelectionImplementation(string operationName, GraphView.AskUser askUser)
 {
     graph.owner.RegisterCompleteObjectUndo(operationName);
     graph.RemoveElements(selection.OfType <MaterialNodeView>().Select(x => (INode)x.node), selection.OfType <Edge>().Select(x => x.userData).OfType <IEdge>());
     foreach (var selectable in selection)
     {
         var field = selectable as BlackboardField;
         if (field != null && field.userData != null)
         {
             var property = (IShaderProperty)field.userData;
             graph.RemoveShaderProperty(property.guid);
         }
     }
 }
Esempio n. 4
0
        void DeleteSelectionImplementation(string operationName, GraphView.AskUser askUser)
        {
            bool containsProperty = false;

            foreach (var selectable in selection)
            {
                var field = selectable as BlackboardField;
                if (field != null && field.userData != null)
                {
                    switch (field.userData)
                    {
                    case AbstractShaderProperty property:
                        containsProperty = true;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }

            if (containsProperty)
            {
                if (graph.isSubGraph)
                {
                    if (!EditorUtility.DisplayDialog("Sub Graph Will Change", "If you remove a property and save the sub graph, you might change other graphs that are using this sub graph.\n\nDo you want to continue?", "Yes", "No"))
                    {
                        return;
                    }
                }
            }

            graph.owner.RegisterCompleteObjectUndo(operationName);
            graph.RemoveElements(selection.OfType <IShaderNodeView>().Where(v => !(v.node is SubGraphOutputNode) && v.node.canDeleteNode).Select(x => x.node).ToArray(),
                                 selection.OfType <Edge>().Select(x => x.userData).OfType <IEdge>().ToArray(),
                                 selection.OfType <ShaderGroup>().Select(x => x.userData).ToArray(),
                                 selection.OfType <StickyNote>().Select(x => x.userData).ToArray());

            foreach (var selectable in selection)
            {
                var field = selectable as BlackboardField;
                if (field != null && field.userData != null)
                {
                    var input = (ShaderInput)field.userData;
                    graph.RemoveGraphInput(input);
                }
            }

            selection.Clear();
        }
        void DeleteSelectionImplementation(string operationName, GraphView.AskUser askUser)
        {
            bool containsProperty = false;

            // Keywords need to be tested against variant limit based on multiple factors
            bool keywordsDirty = false;

            // Track dependent keyword nodes to remove them
            List <KeywordNode> keywordNodes = new List <KeywordNode>();

            foreach (var selectable in selection)
            {
                var field = selectable as BlackboardField;
                if (field != null && field.userData != null)
                {
                    switch (field.userData)
                    {
                    case AbstractShaderProperty property:
                        containsProperty = true;
                        break;

                    case ShaderKeyword keyword:
                        keywordNodes.AddRange(graph.GetNodes <KeywordNode>().Where(x => x.keywordGuid == keyword.guid));
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }

            if (containsProperty)
            {
                if (graph.isSubGraph)
                {
                    if (!EditorUtility.DisplayDialog("Sub Graph Will Change", "If you remove a property and save the sub graph, you might change other graphs that are using this sub graph.\n\nDo you want to continue?", "Yes", "No"))
                    {
                        return;
                    }
                }
            }

            // Filter nodes that cannot be deleted
            var nodesToDelete = selection.OfType <IShaderNodeView>().Where(v => !(v.node is SubGraphOutputNode) && v.node.canDeleteNode).Select(x => x.node);

            // Add keyword nodes dependent on deleted keywords
            nodesToDelete = nodesToDelete.Union(keywordNodes);

            // If deleting a Sub Graph node whose asset contains Keywords test variant limit
            foreach (SubGraphNode subGraphNode in nodesToDelete.OfType <SubGraphNode>())
            {
                if (subGraphNode.asset == null)
                {
                    continue;
                }
                if (subGraphNode.asset.keywords.Count > 0)
                {
                    keywordsDirty = true;
                }
            }

            graph.owner.RegisterCompleteObjectUndo(operationName);
            graph.RemoveElements(nodesToDelete.ToArray(),
                                 selection.OfType <Edge>().Select(x => x.userData).OfType <IEdge>().ToArray(),
                                 selection.OfType <ShaderGroup>().Select(x => x.userData).ToArray(),
                                 selection.OfType <StickyNote>().Select(x => x.userData).ToArray());

            foreach (var selectable in selection)
            {
                var field = selectable as BlackboardField;
                if (field != null && field.userData != null)
                {
                    var input = (ShaderInput)field.userData;
                    graph.RemoveGraphInput(input);

                    // If deleting a Keyword test variant limit
                    if (input is ShaderKeyword keyword)
                    {
                        keywordsDirty = true;
                    }
                }
            }

            // Test Keywords against variant limit
            if (keywordsDirty)
            {
                graph.OnKeywordChangedNoValidate();
            }

            selection.Clear();
        }
 void DeleteSelectionImplementation(string operationName, GraphView.AskUser askUser)
 {
     graph.owner.RegisterCompleteObjectUndo(operationName);
     graph.RemoveElements(selection.OfType <MaterialNodeView>().Select(x => (INode)x.node), selection.OfType <Edge>().Select(x => x.userData).OfType <IEdge>());
 }