void OpenSubGraph(DropdownMenuAction action)
        {
            SubGraphNode subgraphNode = selection.OfType<MaterialNodeView>().First().node as SubGraphNode;

            var path = AssetDatabase.GetAssetPath(subgraphNode.subGraphAsset);
            ShaderGraphImporterEditor.ShowGraphEditWindow(path);
        }
예제 #2
0
        public void LoadGraph()
        {
            List <PropertyCollector.TextureInfo> lti;
            var assetCollection = new AssetCollection();

            ShaderGraphImporter.GetShaderText(kGraphName, out lti, assetCollection, out m_Graph);
            Assert.NotNull(m_Graph, $"Invalid graph data found for {kGraphName}");

            m_Graph.ValidateGraph();

            m_Collector = new PropertyCollector();
            m_Graph.CollectShaderProperties(m_Collector, GenerationMode.ForReals);

            // Open up the window
            if (!ShaderGraphImporterEditor.ShowGraphEditWindow(kGraphName))
            {
                Assert.Fail("ShaderGraphImporterEditor.ShowGraphEditWindow could not open " + kGraphName);
            }

            m_Window = EditorWindow.GetWindow <MaterialGraphEditWindow>();

            if (m_Window == null)
            {
                Assert.Fail("Could not open window");
            }

            // EditorWindow.GetWindow will return a new window if one is not found. A new window will have graphObject == null.
            if (m_Window.graphObject == null)
            {
                Assert.Fail("Existing Shader Graph window of " + kGraphName + " not found.");
            }

            m_GraphEditorView = m_Window.graphEditorView;
        }
 public override void OnInspectorGUI()
 {
     if (GUILayout.Button("Open Shader Editor"))
     {
         AssetImporter importer = target as AssetImporter;
         Debug.Assert(importer != null, "importer != null");
         ShaderGraphImporterEditor.ShowGraphEditWindow(importer.assetPath);
     }
 }
        void OnSubGraphDoubleClick(MouseDownEvent evt)
        {
            if (evt.clickCount == 2 && evt.button == 0)
            {
                SubGraphNode subgraphNode = node as SubGraphNode;

                var path = AssetDatabase.GUIDToAssetPath(subgraphNode.subGraphGuid);
                ShaderGraphImporterEditor.ShowGraphEditWindow(path);
            }
        }
예제 #5
0
        // returns the asset path the file was saved to, or NULL if nothing was saved
        string SaveAsImplementation(bool openWhenSaved)
        {
            string savedFilePath = null;

            if (selectedGuid != null && graphObject?.graph != null)
            {
                var oldFilePath = AssetDatabase.GUIDToAssetPath(selectedGuid);
                if (string.IsNullOrEmpty(oldFilePath) || graphObject == null)
                {
                    return(null);
                }

                // The asset's name needs to be removed from the path, otherwise SaveFilePanel assumes it's a folder
                string oldDirectory = Path.GetDirectoryName(oldFilePath);

                var extension   = graphObject.graph.isSubGraph ? ShaderSubGraphImporter.Extension : ShaderGraphImporter.Extension;
                var newFilePath = EditorUtility.SaveFilePanelInProject("Save Graph As...", Path.GetFileNameWithoutExtension(oldFilePath), extension, "", oldDirectory);
                newFilePath = newFilePath.Replace(Application.dataPath, "Assets");

                if (newFilePath != oldFilePath)
                {
                    if (!string.IsNullOrEmpty(newFilePath))
                    {
                        // If the newPath already exists, we are overwriting an existing file, and could be creating recursions. Let's check.
                        if (GraphUtil.CheckForRecursiveDependencyOnPendingSave(newFilePath, graphObject.graph.GetNodes <SubGraphNode>(), "Save As"))
                        {
                            return(null);
                        }

                        bool success = (FileUtilities.WriteShaderGraphToDisk(newFilePath, graphObject.graph) != null);
                        AssetDatabase.ImportAsset(newFilePath);
                        if (success)
                        {
                            if (openWhenSaved)
                            {
                                ShaderGraphImporterEditor.ShowGraphEditWindow(newFilePath);
                            }
                            OnSaveGraph(newFilePath);
                            savedFilePath = newFilePath;
                        }
                    }
                }
                else
                {
                    // saving to the current path
                    if (SaveAsset())
                    {
                        graphObject.isDirty = false;
                        savedFilePath       = oldFilePath;
                    }
                }
            }
            return(savedFilePath);
        }
예제 #6
0
        // Returns true if the same file as replaced, false if a new file was created or an error occured
        bool SaveAsImplementation()
        {
            if (selectedGuid != null && graphObject != null)
            {
                var pathAndFile = AssetDatabase.GUIDToAssetPath(selectedGuid);
                if (string.IsNullOrEmpty(pathAndFile) || graphObject == null)
                {
                    return(false);
                }

                // The asset's name needs to be removed from the path, otherwise SaveFilePanel assumes it's a folder
                string path = Path.GetDirectoryName(pathAndFile);

                var extension = graphObject.graph.isSubGraph ? ShaderSubGraphImporter.Extension : ShaderGraphImporter.Extension;
                var newPath   = EditorUtility.SaveFilePanelInProject("Save Graph As...", Path.GetFileNameWithoutExtension(pathAndFile), extension, "", path);
                newPath = newPath.Replace(Application.dataPath, "Assets");

                if (newPath != path)
                {
                    if (!string.IsNullOrEmpty(newPath))
                    {
                        var success = FileUtilities.WriteShaderGraphToDisk(newPath, graphObject.graph);
                        AssetDatabase.ImportAsset(newPath);
                        if (success)
                        {
                            ShaderGraphImporterEditor.ShowGraphEditWindow(newPath);
                            // This is for updating material dependencies so we exclude subgraphs here.
                            if (GraphData.onSaveGraph != null && extension != ShaderSubGraphImporter.Extension)
                            {
                                var shader = AssetDatabase.LoadAssetAtPath <Shader>(newPath);
                                // Retrieve graph context, note that if we're here the output node will always be a master node
                                GraphData.onSaveGraph(shader, (graphObject.graph.outputNode as AbstractMaterialNode).saveContext);
                            }
                        }
                    }

                    graphObject.isDirty = false;
                    return(false);
                }
                else
                {
                    UpdateAsset();
                    graphObject.isDirty = false;
                    return(true);
                }
            }

            return(false);
        }
예제 #7
0
        // Returns true if the same file as replaced, false if a new file was created or an error occured
        bool SaveAsImplementation()
        {
            if (selectedGuid != null && graphObject != null)
            {
                var pathAndFile = AssetDatabase.GUIDToAssetPath(selectedGuid);
                if (string.IsNullOrEmpty(pathAndFile) || graphObject == null)
                {
                    return(false);
                }

                // The asset's name needs to be removed from the path, otherwise SaveFilePanel assumes it's a folder
                string path = Path.GetDirectoryName(pathAndFile);

                var extension = graphObject.graph.isSubGraph ? ShaderSubGraphImporter.Extension : ShaderGraphImporter.Extension;
                var newPath   = EditorUtility.SaveFilePanelInProject("Save Graph As...", Path.GetFileNameWithoutExtension(pathAndFile), extension, "", path);
                newPath = newPath.Replace(Application.dataPath, "Assets");

                if (newPath != path)
                {
                    if (!string.IsNullOrEmpty(newPath))
                    {
                        // If the newPath already exists, we are overwriting an existing file, and could be creating recursions. Let's check.
                        if (GraphUtil.CheckForRecursiveDependencyOnPendingSave(newPath, graphObject.graph.GetNodes <SubGraphNode>(), "Save As"))
                        {
                            return(false);
                        }

                        var success = FileUtilities.WriteShaderGraphToDisk(newPath, graphObject.graph);
                        AssetDatabase.ImportAsset(newPath);
                        if (success)
                        {
                            ShaderGraphImporterEditor.ShowGraphEditWindow(newPath);
                            OnSaveGraph(newPath);
                        }
                    }

                    graphObject.isDirty = false;
                    return(false);
                }
                else
                {
                    UpdateAsset();
                    graphObject.isDirty = false;
                    return(true);
                }
            }

            return(false);
        }
예제 #8
0
        public void LoadGraph()
        {
            List <PropertyCollector.TextureInfo> lti;
            var assetCollection = new AssetCollection();

            ShaderGraphImporter.GetShaderText(kGraphName, out lti, assetCollection, out m_Graph);
            Assert.NotNull(m_Graph, $"Invalid graph data found for {kGraphName}");

            m_Graph.ValidateGraph();

            m_Collector = new PropertyCollector();
            m_Graph.CollectShaderProperties(m_Collector, GenerationMode.ForReals);

            // Open up the window
            if (!ShaderGraphImporterEditor.ShowGraphEditWindow(kGraphName))
            {
                Assert.Fail("ShaderGraphImporterEditor.ShowGraphEditWindow could not open " + kGraphName);
            }

            m_Window = EditorWindow.GetWindow <MaterialGraphEditWindow>();
            if (m_Window == null)
            {
                Assert.Fail("Could not open window");
            }

            // EditorWindow.GetWindow will return a new window if one is not found. A new window will have graphObject == null.
            if (m_Window.graphObject == null)
            {
                Assert.Fail("Existing Shader Graph window of " + kGraphName + " not found.");
            }

            m_GraphEditorView = m_Window.graphEditorView;

            // Create the blackboard test controller
            var blackboardViewModel = new BlackboardViewModel()
            {
                parentView = m_Window.graphEditorView.graphView, model = m_Window.graphObject.graph, title = m_Window.assetName
            };

            m_BlackboardTestController = new BlackboardTestController(m_Window, m_Graph, blackboardViewModel, m_Window.graphObject.graphDataStore);

            // Remove the normal blackboard
            m_GraphEditorView.blackboardController.blackboard.RemoveFromHierarchy();

            // And override reference to the blackboard controller to point at the test controller
            m_GraphEditorView.blackboardController = m_BlackboardTestController;
        }
        public void SaveAs()
        {
            if (selectedGuid != null && graphObject != null)
            {
                var path = AssetDatabase.GUIDToAssetPath(selectedGuid);
                if (string.IsNullOrEmpty(path) || graphObject == null)
                {
                    return;
                }

                var extension = graphObject.graph.isSubGraph ? ShaderSubGraphImporter.Extension : ShaderGraphImporter.Extension;
                var newPath   = EditorUtility.SaveFilePanel("Save Graph As", path, Path.GetFileNameWithoutExtension(path), extension);
                newPath = newPath.Replace(Application.dataPath, "Assets");
                if (newPath != path)
                {
                    if (!string.IsNullOrEmpty(newPath))
                    {
                        var success = FileUtilities.WriteShaderGraphToDisk(newPath, graphObject.graph);
                        AssetDatabase.ImportAsset(newPath);
                        if (success)
                        {
                            ShaderGraphImporterEditor.ShowGraphEditWindow(newPath);
                            // This is for updating material dependencies so we exclude subgraphs here.
                            if (GraphData.onSaveGraph != null && extension != ShaderSubGraphImporter.Extension)
                            {
                                var shader = AssetDatabase.LoadAssetAtPath <Shader>(newPath);
                                // Retrieve graph context, note that if we're here the output node will always be a master node
                                GraphData.onSaveGraph(shader, (graphObject.graph.outputNode as MasterNode).saveContext);
                            }
                        }
                    }
                }
                else
                {
                    UpdateAsset();
                }

                graphObject.isDirty = false;
            }
        }
        public void SaveAs()
        {
            if (selectedGuid != null && graphObject != null)
            {
                var path = AssetDatabase.GUIDToAssetPath(selectedGuid);
                if (string.IsNullOrEmpty(path) || graphObject == null)
                {
                    return;
                }

                var extension = graphObject.graph.isSubGraph ? ShaderSubGraphImporter.Extension : ShaderGraphImporter.Extension;
                var newPath   = EditorUtility.SaveFilePanel("Save Graph As", path, Path.GetFileNameWithoutExtension(path), extension);
                newPath = newPath.Replace(Application.dataPath, "Assets");
                if (newPath != path)
                {
                    if (!string.IsNullOrEmpty(newPath))
                    {
                        var success = FileUtilities.WriteShaderGraphToDisk(newPath, graphObject.graph);
                        AssetDatabase.ImportAsset(newPath);
                        if (success)
                        {
                            ShaderGraphImporterEditor.ShowGraphEditWindow(newPath);
                            if (GraphData.onSaveGraph != null)
                            {
                                var shader = AssetDatabase.LoadAssetAtPath <Shader>(newPath);
                                GraphData.onSaveGraph(shader);
                            }
                        }
                    }
                }
                else
                {
                    UpdateAsset();
                }

                graphObject.isDirty = false;
            }
        }
예제 #11
0
        public void OpenGraphWindow(string graphName)
        {
            // Open up the window
            if (!ShaderGraphImporterEditor.ShowGraphEditWindow(graphName))
            {
                Assert.Fail("ShaderGraphImporterEditor.ShowGraphEditWindow could not open " + graphName);
            }

            m_Window = EditorWindow.GetWindow <MaterialGraphEditWindow>();

            if (m_Window == null)
            {
                Assert.Fail("Could not open MaterialGraphEditWindow");
            }

            // EditorWindow.GetWindow will return a new window if one is not found. A new window will have graphObject == null.
            if (m_Window.graphObject == null)
            {
                Assert.Fail("Existing Shader Graph window of " + graphName + " not found.");
            }

            m_GraphEditorView = m_Window.graphEditorView;
        }