From 2a59a40e6b36b276d4a12a60e67c794d0076b941 Mon Sep 17 00:00:00 2001 From: Alex Lindman Date: Thu, 6 Feb 2020 17:16:20 -0800 Subject: [PATCH 1/7] searcher is now speedy tm --- .../Editor/Drawing/SearchWindowProvider.cs | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs b/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs index 9eeaeb35554..592dcb608c9 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) @@ -206,8 +207,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 +266,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 +297,26 @@ 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; + } + return newNode; + } } } From d23e2f0be009fb0fb3e869f785df5811e4ac3586 Mon Sep 17 00:00:00 2001 From: Alex Lindman Date: Fri, 7 Feb 2020 08:54:00 -0800 Subject: [PATCH 2/7] new or removed properties and keywords regenerate search entries --- com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs b/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs index fcd2985c1de..7a14b26f669 100644 --- a/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs +++ b/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs @@ -562,6 +562,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(); From be7cc054608f75064fb42164e1f76c9ce69e1959 Mon Sep 17 00:00:00 2001 From: Alex Lindman Date: Fri, 7 Feb 2020 13:01:07 -0800 Subject: [PATCH 3/7] register callback to generate subgraph entries --- .../Editor/Drawing/Views/GraphEditorView.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs b/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs index 7a14b26f669..767ffb4745e 100644 --- a/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs +++ b/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs @@ -261,6 +261,11 @@ public GraphEditorView(EditorWindow editorWindow, GraphData graph, MessageManage item => (m_SearchWindowProvider as SearcherProvider).OnSearcherSelectEntry(item, c.screenMousePosition - editorWindow.position.position), c.screenMousePosition - editorWindow.position.position, null); }; + m_GraphView.RegisterCallback( evt => + { + //regenerate entries when graph view is refocused, to propogate subgraph changes + m_SearchWindowProvider.regenerateEntries = true; + }); m_EdgeConnectorListener = new EdgeConnectorListener(m_Graph, m_SearchWindowProvider, editorWindow); From abd06700ed3849086bf384cb90b85a204ccd6b8c Mon Sep 17 00:00:00 2001 From: Alex Lindman Date: Fri, 7 Feb 2020 13:09:14 -0800 Subject: [PATCH 4/7] Update CHANGELOG.md --- com.unity.shadergraph/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.shadergraph/CHANGELOG.md b/com.unity.shadergraph/CHANGELOG.md index 43d94ddd768..fedca993613 100644 --- a/com.unity.shadergraph/CHANGELOG.md +++ b/com.unity.shadergraph/CHANGELOG.md @@ -54,6 +54,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - You can now smoothly edit controls on the `Dielectric Specular` node. - Fixed Blackboard Properties to support scientific notation. - Fixed a bug where the error `Output value 'vert' is not initialized` displayed on all PBR graphs in Universal. [1210710](https://issuetracker.unity3d.com/issues/output-value-vert-is-not-completely-initialized-error-is-thrown-when-pbr-graph-is-created-using-urp) +- 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). ## [7.1.1] - 2019-09-05 ### Added From 4c9c4e1baf866515e691b302e25b40d8a7d54f64 Mon Sep 17 00:00:00 2001 From: Alex Lindman Date: Wed, 26 Feb 2020 09:04:18 -0800 Subject: [PATCH 5/7] make sure keyword owner is cleaned --- com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs b/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs index 592dcb608c9..1a60cc2e50b 100644 --- a/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs +++ b/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs @@ -314,6 +314,7 @@ public AbstractMaterialNode CopyNodeForGraph(AbstractMaterialNode oldNode) { keywordNode.owner = m_Graph; keywordNode.keywordGuid = ((KeywordNode)oldNode).keywordGuid; + keywordNode.owner = null; } return newNode; } From 2310ccca8dd1186f932205b16dfce82cf4ceb1e0 Mon Sep 17 00:00:00 2001 From: Marc Templin Date: Mon, 16 Mar 2020 15:53:41 -0700 Subject: [PATCH 6/7] Use TypeCache to speed up looking for nodes to add to searcher --- .../Editor/Drawing/SearchWindowProvider.cs | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs b/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs index 1a60cc2e50b..51969b4caeb 100644 --- a/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs +++ b/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs @@ -55,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); } } @@ -87,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; From f06c621c66e91fe9a0e00a1dea7d5847e90abd57 Mon Sep 17 00:00:00 2001 From: Alex Lindman Date: Wed, 8 Apr 2020 09:48:40 -0700 Subject: [PATCH 7/7] fix merge error --- com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs b/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs index 7958c9c839e..bc54b058dff 100644 --- a/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs +++ b/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs @@ -257,7 +257,7 @@ public GraphEditorView(EditorWindow editorWindow, GraphData graph, MessageManage 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_GraphView.RegisterCallback( evt => { m_SearchWindowProvider.regenerateEntries = true; }); m_EdgeConnectorListener = new EdgeConnectorListener(m_Graph, m_SearchWindowProvider, editorWindow);