Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 41 additions & 20 deletions com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -54,30 +55,26 @@ void OnDestroy()
m_Icon = null;
}
}

List<int> m_Ids;
List<ISlot> m_Slots = new List<ISlot>();

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<NodeEntry> nodeEntries = new List<NodeEntry>();
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
var nodeEntries = new List<NodeEntry>();
foreach (var type in TypeCache.GetTypesDerivedFrom<AbstractMaterialNode>())
{
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);
}
}

Expand All @@ -86,7 +83,7 @@ public void GenerateNodeEntries()
var asset = AssetDatabase.LoadAssetAtPath<SubGraphAsset>(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;
Expand Down Expand Up @@ -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<SearcherItem>();
var dummyEntry = new NodeEntry();
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}

}
7 changes: 7 additions & 0 deletions com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FocusInEvent>( 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);

Expand Down Expand Up @@ -562,6 +567,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();

Expand Down