diff --git a/com.unity.shadergraph/CHANGELOG.md b/com.unity.shadergraph/CHANGELOG.md index 79ca08ff163..02c273697f1 100644 --- a/com.unity.shadergraph/CHANGELOG.md +++ b/com.unity.shadergraph/CHANGELOG.md @@ -88,6 +88,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed a bug where adding a HDRP Master Node to a Shader Graph would softlock the Shader Graph. - Fixed a bug where shaders fail to compile due to `#pragma target` generation when your system locale uses commas instead of periods. - Fixed a compilation error when using Hybrid Renderer due to incorrect positioning of macros. +- Fixed a bug where the `Create Node Menu` lagged on load. Entries are now only generated when property, keyword, or subgraph changes are detected. [1209567](https://issuetracker.unity3d.com/issues/shadergraph-opening-node-search-window-is-unnecessarily-slow). - Fixed a bug with the `Transform` node where converting from `Absolute World` space in a sub graph causes invalid subscript errors. [1190813](https://issuetracker.unity3d.com/issues/shadergraph-invalid-subscript-errors-are-thrown-when-connecting-a-subgraph-with-transform-node-with-unlit-master-node) - Fixed a bug where the `Position` node would change coordinate spaces from `World` to `Absolute World` when shaders recompile. [1184617](https://issuetracker.unity3d.com/product/unity/issues/guid/1184617/) - Fixed a bug where instanced shaders wouldn't compile on PS4. diff --git a/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs b/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs index 9eeaeb35554..51969b4caeb 100644 --- a/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs +++ b/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs @@ -31,6 +31,7 @@ class SearchWindowProvider : ScriptableObject public bool nodeNeedsRepositioning { get; set; } public SlotReference targetSlotReference { get; internal set; } public Vector2 targetPosition { get; internal set; } + public bool regenerateEntries { get; set; } private const string k_HiddenFolderName = "Hidden"; public void Initialize(EditorWindow editorWindow, GraphData graph, GraphView graphView) @@ -54,30 +55,26 @@ void OnDestroy() m_Icon = null; } } - + List m_Ids; List m_Slots = new List(); public void GenerateNodeEntries() { // First build up temporary data structure containing group & title as an array of strings (the last one is the actual title) and associated node type. - List nodeEntries = new List(); - foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) + var nodeEntries = new List(); + foreach (var type in TypeCache.GetTypesDerivedFrom()) { - foreach (var type in assembly.GetTypesOrNothing()) + if ((!type.IsClass || type.IsAbstract) + || type == typeof(PropertyNode) + || type == typeof(KeywordNode) + || type == typeof(SubGraphNode)) + continue; + + if (type.GetCustomAttributes(typeof(TitleAttribute), false) is TitleAttribute[] attrs && attrs.Length > 0) { - if (type.IsClass && !type.IsAbstract && (type.IsSubclassOf(typeof(AbstractMaterialNode))) - && type != typeof(PropertyNode) - && type != typeof(KeywordNode) - && type != typeof(SubGraphNode)) - { - var attrs = type.GetCustomAttributes(typeof(TitleAttribute), false) as TitleAttribute[]; - if (attrs != null && attrs.Length > 0) - { - var node = (AbstractMaterialNode)Activator.CreateInstance(type); - AddEntries(node, attrs[0].title, nodeEntries); - } - } + var node = (AbstractMaterialNode) Activator.CreateInstance(type); + AddEntries(node, attrs[0].title, nodeEntries); } } @@ -86,7 +83,7 @@ public void GenerateNodeEntries() var asset = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid)); var node = new SubGraphNode { asset = asset }; var title = asset.path.Split('/').ToList(); - + if (asset.descendents.Contains(m_Graph.assetGuid) || asset.assetGuid == m_Graph.assetGuid) { continue; @@ -206,8 +203,11 @@ class SearcherProvider : SearchWindowProvider { public Searcher.Searcher LoadSearchWindow() { - GenerateNodeEntries(); - + if (regenerateEntries) + { + GenerateNodeEntries(); + regenerateEntries = false; + } //create empty root for searcher tree var root = new List(); var dummyEntry = new NodeEntry(); @@ -262,7 +262,7 @@ public bool OnSearcherSelectEntry(SearcherItem entry, Vector2 screenMousePositio return false; var nodeEntry = (entry as SearchNodeItem).NodeGUID; - var node = nodeEntry.node; + var node = CopyNodeForGraph(nodeEntry.node); var drawState = node.drawState; @@ -293,6 +293,27 @@ public bool OnSearcherSelectEntry(SearcherItem entry, Vector2 screenMousePositio return true; } + public AbstractMaterialNode CopyNodeForGraph(AbstractMaterialNode oldNode) + { + var newNode = (AbstractMaterialNode)Activator.CreateInstance(oldNode.GetType()); + if (newNode is SubGraphNode subgraphNode) + { + subgraphNode.asset = ((SubGraphNode)oldNode).asset; + } + else if(newNode is PropertyNode propertyNode) + { + propertyNode.owner = m_Graph; + propertyNode.propertyGuid = ((PropertyNode)oldNode).propertyGuid; + propertyNode.owner = null; + } + else if(newNode is KeywordNode keywordNode) + { + keywordNode.owner = m_Graph; + keywordNode.keywordGuid = ((KeywordNode)oldNode).keywordGuid; + keywordNode.owner = null; + } + return newNode; + } } } diff --git a/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs b/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs index 7f4a8ca0ec3..bc54b058dff 100644 --- a/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs +++ b/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs @@ -256,6 +256,8 @@ public GraphEditorView(EditorWindow editorWindow, GraphData graph, MessageManage m_SearchWindowProvider = ScriptableObject.CreateInstance(); m_SearchWindowProvider.Initialize(editorWindow, m_Graph, m_GraphView); m_GraphView.nodeCreationRequest = NodeCreationRequest; + //regenerate entries when graph view is refocused, to propogate subgraph changes + m_GraphView.RegisterCallback( evt => { m_SearchWindowProvider.regenerateEntries = true; }); m_EdgeConnectorListener = new EdgeConnectorListener(m_Graph, m_SearchWindowProvider, editorWindow); @@ -562,6 +564,8 @@ public void HandleGraphChanges() } previewManager.RenderPreviews(); + if(m_Graph.addedInputs.Count() > 0 || m_Graph.removedInputs.Count() > 0) + m_SearchWindowProvider.regenerateEntries = true; m_BlackboardProvider.HandleGraphChanges(); m_GroupHashSet.Clear();