|
|
|
|
|
|
public class SearchWindowProvider : ScriptableObject, ISearchWindowProvider |
|
|
|
{ |
|
|
|
EditorWindow m_EditorWindow; |
|
|
|
IGraph m_Graph; |
|
|
|
AbstractMaterialGraph m_Graph; |
|
|
|
GraphView m_GraphView; |
|
|
|
Texture2D m_Icon; |
|
|
|
|
|
|
|
|
|
|
const string k_ConvertToInlineNode = "Convert To Inline Node"; |
|
|
|
const string k_ConvertToSubgraph = "Convert To Sub-graph"; |
|
|
|
const string k_CopyShader = "Copy Shader To Clipboard"; |
|
|
|
public void Initialize(EditorWindow editorWindow, IGraph graph, GraphView graphView) |
|
|
|
public void Initialize(EditorWindow editorWindow, AbstractMaterialGraph graph, GraphView graphView) |
|
|
|
{ |
|
|
|
m_EditorWindow = editorWindow; |
|
|
|
m_Graph = graph; |
|
|
|
|
|
|
var asset = AssetDatabase.LoadAssetAtPath<MaterialSubGraphAsset>(AssetDatabase.GUIDToAssetPath(guid)); |
|
|
|
nestedEntries.Add(new NestedEntry |
|
|
|
{ |
|
|
|
title = new [] {"Sub-graph Assets", asset.name}, |
|
|
|
title = new[] { "Sub-graph Assets", asset.name }, |
|
|
|
userData = asset |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
// Add in contextual node actions
|
|
|
|
var selection = m_GraphView.selection.OfType<MaterialNodeView>().ToList(); |
|
|
|
if (selection.Any()) |
|
|
|
tree.Add(new SearchTreeEntry(new GUIContent(k_ConvertToSubgraph, m_Icon)) { level = 1 }); |
|
|
|
if (selection.Count == 1 && selection.First().node.hasPreview) |
|
|
|
tree.Add(new SearchTreeEntry(new GUIContent(k_CopyShader, m_Icon)) { level = 1 }); |
|
|
|
|
|
|
|
foreach (var nestedEntry in nestedEntries) |
|
|
|
{ |
|
|
|
|
|
|
return OnConvertToProperty(); |
|
|
|
if (entry.name == k_ConvertToInlineNode) |
|
|
|
return OnConvertToInlineNode(); |
|
|
|
if (entry.name == k_ConvertToSubgraph) |
|
|
|
return OnConvertToSubgraph(); |
|
|
|
if (entry.name == k_CopyShader) |
|
|
|
return OnCopyShader(); |
|
|
|
bool OnCopyShader() |
|
|
|
{ |
|
|
|
var copyFromNode = m_GraphView.selection.OfType<MaterialNodeView>().First().node; |
|
|
|
|
|
|
|
List<PropertyCollector.TextureInfo> textureInfo; |
|
|
|
var masterNode = copyFromNode as MasterNode; |
|
|
|
if (masterNode != null) |
|
|
|
{ |
|
|
|
var shader = masterNode.GetShader(GenerationMode.ForReals, masterNode.name, out textureInfo); |
|
|
|
GUIUtility.systemCopyBuffer = shader; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
PreviewMode previewMode; |
|
|
|
FloatShaderProperty outputIdProperty; |
|
|
|
var shader = m_Graph.GetShader(copyFromNode, GenerationMode.ForReals, copyFromNode.name, out textureInfo, out previewMode, out outputIdProperty); |
|
|
|
GUIUtility.systemCopyBuffer = shader; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
bool OnConvertToSubgraph() |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
var graph = m_Graph as AbstractMaterialGraph; |
|
|
|
if (graph == null) |
|
|
|
return false; |
|
|
|
|
|
|
|
var selectedNodeViews = m_GraphView.selection.OfType<MaterialNodeView>().Select(x => x.node); |
|
|
|
|
|
|
|
foreach (var node in selectedNodeViews.ToArray()) |
|
|
|
var selectedNodeViews = m_GraphView.selection.OfType<MaterialNodeView>().Select(x => x.node).ToList(); |
|
|
|
foreach (var node in selectedNodeViews) |
|
|
|
{ |
|
|
|
if (!(node is IPropertyFromNode)) |
|
|
|
continue; |
|
|
|
|
|
|
graph.AddShaderProperty(prop); |
|
|
|
m_Graph.AddShaderProperty(prop); |
|
|
|
graph.AddNode(propNode); |
|
|
|
m_Graph.AddNode(propNode); |
|
|
|
var edges = graph.GetEdges(oldSlot.slotReference).ToArray(); |
|
|
|
var edges = m_Graph.GetEdges(oldSlot.slotReference).ToArray(); |
|
|
|
graph.Connect(newSlot.slotReference, edge.inputSlot); |
|
|
|
m_Graph.Connect(newSlot.slotReference, edge.inputSlot); |
|
|
|
graph.RemoveNode(node); |
|
|
|
m_Graph.RemoveNode(node); |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|