void ConvertToProperty(GraphData graphData)
        {
            AssertHelpers.IsNotNull(graphData, "GraphData is null while carrying out ConvertToPropertyAction");
            AssertHelpers.IsNotNull(inlinePropertiesToConvert, "InlinePropertiesToConvert is null while carrying out ConvertToPropertyAction");
            graphData.owner.RegisterCompleteObjectUndo("Convert to Property");

            foreach (var converter in inlinePropertiesToConvert)
            {
                var convertedProperty = converter.AsShaderProperty();
                var node = converter as AbstractMaterialNode;

                graphData.AddGraphInput(convertedProperty);
                // Add reference to converted property for use in responding to this action later
                convertedPropertyReferences.Add(convertedProperty);

                var propNode = new PropertyNode();
                propNode.drawState = node.drawState;
                propNode.group     = node.group;
                graphData.AddNode(propNode);
                propNode.property = convertedProperty;

                var oldSlot = node.FindSlot <MaterialSlot>(converter.outputSlotId);
                var newSlot = propNode.FindSlot <MaterialSlot>(PropertyNode.OutputSlotId);

                foreach (var edge in graphData.GetEdges(oldSlot.slotReference))
                {
                    graphData.Connect(newSlot.slotReference, edge.inputSlot);
                }

                graphData.RemoveNode(node);
            }
        }
Example #2
0
        void ConvertToProperty(GraphData graphData)
        {
            AssertHelpers.IsNotNull(graphData, "GraphData is null while carrying out ConvertToPropertyAction");
            AssertHelpers.IsNotNull(inlinePropertiesToConvert, "InlinePropertiesToConvert is null while carrying out ConvertToPropertyAction");
            graphData.owner.RegisterCompleteObjectUndo("Convert to Property");

            var defaultCategory = graphData.categories.FirstOrDefault();

            AssertHelpers.IsNotNull(defaultCategory, "Default Category is null while carrying out ConvertToPropertyAction");

            foreach (var converter in inlinePropertiesToConvert)
            {
                var convertedProperty = converter.AsShaderProperty();
                var node = converter as AbstractMaterialNode;

                graphData.AddGraphInput(convertedProperty);

                // Also insert this input into the default category
                if (defaultCategory != null)
                {
                    var addItemToCategoryAction = new AddItemToCategoryAction();
                    addItemToCategoryAction.categoryGuid = defaultCategory.categoryGuid;
                    addItemToCategoryAction.itemToAdd    = convertedProperty;
                    graphData.owner.graphDataStore.Dispatch(addItemToCategoryAction);
                }

                // Add reference to converted property for use in responding to this action later
                convertedPropertyReferences.Add(convertedProperty);

                var propNode = new PropertyNode();
                propNode.drawState = node.drawState;
                propNode.group     = node.group;
                graphData.AddNode(propNode);
                propNode.property = convertedProperty;

                var oldSlot = node.FindSlot <MaterialSlot>(converter.outputSlotId);
                var newSlot = propNode.FindSlot <MaterialSlot>(PropertyNode.OutputSlotId);

                foreach (var edge in graphData.GetEdges(oldSlot.slotReference))
                {
                    graphData.Connect(newSlot.slotReference, edge.inputSlot);
                }

                graphData.RemoveNode(node);
            }
        }