예제 #1
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");

            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);
            }
        }
        public override void Action(int instanceId, string pathName, string resourceFile)
        {
            var graph = new GraphData();

            graph.AddNode(new SpriteLitMasterNode());
            File.WriteAllText(pathName, EditorJsonUtility.ToJson(graph));
            AssetDatabase.Refresh();
        }
예제 #3
0
        public override void Action(int instanceId, string pathName, string resourceFile)
        {
            var graph = new GraphData {
                isSubGraph = true
            };

            graph.AddNode(new SubGraphOutputNode());
            graph.path = "Sub Graphs";
            File.WriteAllText(pathName, EditorJsonUtility.ToJson(graph));
            AssetDatabase.Refresh();
        }
예제 #4
0
        public override void Action(int instanceId, string pathName, string resourceFile)
        {
            var graph = new GraphData();

            graph.AddNode(node);
            graph.path = "Shader Graphs";
            FileUtilities.WriteShaderGraphToDisk(pathName, graph);
            AssetDatabase.Refresh();

            UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath <Shader>(pathName);
            Selection.activeObject = obj;
        }
예제 #5
0
        public override void Action(int instanceId, string pathName, string resourceFile)
        {
            var graph = new GraphData {
                isSubGraph = true
            };
            var outputNode = new SubGraphOutputNode();

            graph.AddNode(outputNode);
            outputNode.AddSlot(ConcreteSlotValueType.Vector4);
            graph.path = "Sub Graphs";
            File.WriteAllText(pathName, EditorJsonUtility.ToJson(graph));
            AssetDatabase.Refresh();
        }
        public override void Action(int instanceId, string pathName, string resourceFile)
        {
            var graph = new GraphData {
                isSubGraph = true
            };
            var outputNode = new SubGraphOutputNode();

            graph.AddNode(outputNode);
            outputNode.AddSlot(ConcreteSlotValueType.Vector4);
            graph.path = "Sub Graphs";
            FileUtilities.WriteShaderGraphToDisk(pathName, graph);
            AssetDatabase.Refresh();
        }
예제 #7
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);
            }
        }
예제 #8
0
        // Static version for testability
        public static RedirectNodeData Create(GraphData graph, SlotValueType edgeType, Vector2 absolutePosition, SlotReference inputRef, SlotReference outputRef, Guid groupGuid)
        {
            var nodeData = new RedirectNodeData();
            nodeData.AddSlots(edgeType);
            nodeData.SetPosition(absolutePosition);
            nodeData.groupGuid = groupGuid;

            // Hard-coded for single input-output. Changes would be needed for multi-input redirects
            var nodeInSlotRef = nodeData.GetSlotReference(RedirectNodeData.kInputSlotID);
            var nodeOutSlotRef = nodeData.GetSlotReference(RedirectNodeData.kOutputSlotID);

            graph.owner.RegisterCompleteObjectUndo("Add Redirect Node");
            graph.AddNode(nodeData);

            graph.Connect(outputRef, nodeInSlotRef);
            graph.Connect(nodeOutSlotRef, inputRef);

            return nodeData;
        }
예제 #9
0
        void DragGraphInput(GraphData graphData)
        {
            AssertHelpers.IsNotNull(graphData, "GraphData is null while carrying out DragGraphInputAction");
            AssertHelpers.IsNotNull(graphInputBeingDraggedIn, "GraphInputBeingDraggedIn is null while carrying out DragGraphInputAction");
            graphData.owner.RegisterCompleteObjectUndo("Drag Graph Input");

            switch (graphInputBeingDraggedIn)
            {
            case AbstractShaderProperty property:
            {
                if (property is MultiJsonInternal.UnknownShaderPropertyType)
                {
                    break;
                }

                // This could be from another graph, in which case we add a copy of the ShaderInput to this graph.
                if (graphData.properties.FirstOrDefault(p => p == property) == null)
                {
                    var copyShaderInputAction = new CopyShaderInputAction();
                    copyShaderInputAction.shaderInputToCopy = property;
                    graphData.owner.graphDataStore.Dispatch(copyShaderInputAction);
                    property = (AbstractShaderProperty)copyShaderInputAction.copiedShaderInput;
                }

                var node      = new PropertyNode();
                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                graphData.AddNode(node);

                // Setting the guid requires the graph to be set first.
                node.property = property;
                break;
            }

            case ShaderKeyword keyword:
            {
                // This could be from another graph, in which case we add a copy of the ShaderInput to this graph.
                if (graphData.keywords.FirstOrDefault(k => k == keyword) == null)
                {
                    var copyShaderInputAction = new CopyShaderInputAction();
                    copyShaderInputAction.shaderInputToCopy = keyword;
                    graphData.owner.graphDataStore.Dispatch(copyShaderInputAction);
                    keyword = (ShaderKeyword)copyShaderInputAction.copiedShaderInput;
                }

                var node      = new KeywordNode();
                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                graphData.AddNode(node);

                // Setting the guid requires the graph to be set first.
                node.keyword = keyword;
                break;
            }

            case ShaderDropdown dropdown:
            {
                if (graphData.IsInputAllowedInGraph(dropdown))
                {
                    // This could be from another graph, in which case we add a copy of the ShaderInput to this graph.
                    if (graphData.dropdowns.FirstOrDefault(d => d == dropdown) == null)
                    {
                        var copyShaderInputAction = new CopyShaderInputAction();
                        copyShaderInputAction.shaderInputToCopy = dropdown;
                        graphData.owner.graphDataStore.Dispatch(copyShaderInputAction);
                        dropdown = (ShaderDropdown)copyShaderInputAction.copiedShaderInput;
                    }

                    var node      = new DropdownNode();
                    var drawState = node.drawState;
                    drawState.position = new Rect(nodePosition, drawState.position.size);
                    node.drawState     = drawState;
                    graphData.AddNode(node);

                    // Setting the guid requires the graph to be set first.
                    node.dropdown = dropdown;
                }
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }