浏览代码

Move convert to property / inline node to right click menu.

/main
Tim Cooper 7 年前
当前提交
e9731703
共有 2 个文件被更改,包括 60 次插入56 次删除
  1. 62
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/NodeCreator.cs
  2. 54
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs

62
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/NodeCreator.cs


using System;
using System.Linq;
using System.Reflection;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;

m_Menu.AddItem(new GUIContent(attrs[0].m_Title), false, OnAddNode, type);
}
}
m_Menu.AddSeparator("");
m_Menu.AddItem(new GUIContent("Convert to Property"), false, OnConvertToProperty);
m_Menu.AddItem(new GUIContent("Convert to Inline node"), false, OnConvertToInlineNode);
}
private void OnConvertToInlineNode()
{
if (m_GraphView == null)
return;
var slected = m_GraphView.selection.OfType<MaterialNodeView>()
.Select(x => x.node)
.OfType<PropertyNode>();
foreach (var propNode in slected)
propNode.ReplaceWithConcreteNode();
}
private void OnConvertToProperty()
{
if (m_GraphView == null)
return;
var graph = m_Graph as AbstractMaterialGraph;
if (graph == null)
return;
var slected = m_GraphView.selection.OfType<MaterialNodeView>().Select(x => x.node);
foreach (var node in slected.ToArray())
{
if (!(node is IPropertyFromNode))
continue;
var converter = node as IPropertyFromNode;
var prop = converter.AsShaderProperty();
graph.AddShaderProperty(prop);
var propNode = new PropertyNode();
propNode.drawState = node.drawState;
graph.AddNode(propNode);
propNode.propertyGuid = prop.guid;
var oldSlot = node.FindSlot<MaterialSlot>(converter.outputSlotId);
var newSlot = propNode.FindSlot<MaterialSlot>(PropertyNode.OutputSlotId);
var edges = graph.GetEdges(oldSlot.slotReference).ToArray();
foreach (var edge in edges)
graph.Connect(newSlot.slotReference, edge.inputSlot);
graph.RemoveNode(node);
}
}
void OnAddNode(object userData)

m_Graph.AddNode(node);
}
private GraphView m_GraphView;
var graphView = target as GraphView;
if (graphView == null)
m_GraphView = target as GraphView;
if (m_GraphView == null)
m_ContentViewContainer = graphView.contentViewContainer;
m_ContentViewContainer = m_GraphView.contentViewContainer;
target.RegisterCallback<MouseUpEvent>(OnMouseUp);
}

54
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs


ToolbarView m_ToolbarView;
ToolbarButtonView m_TimeButton;
ToolbarButtonView m_CopyToClipboardButton;
ToolbarButtonView m_InlineSelectedProperties;
ToolbarButtonView m_ConvertToProperty;
PreviewManager m_PreviewManager;
public Action onUpdateAssetClick { get; set; }

}
));
m_InlineSelectedProperties = new ToolbarButtonView() { text = "Inline Property Node" };
m_InlineSelectedProperties.AddManipulator(new Clickable(() =>
{
var slected = graphView.selection.OfType<MaterialNodeView>()
.Select(x => x.node)
.OfType<PropertyNode>();
foreach (var propNode in slected)
propNode.ReplaceWithConcreteNode();
}
));
m_ConvertToProperty = new ToolbarButtonView() { text = "Convert To Property" };
m_ConvertToProperty.AddManipulator(new Clickable(() =>
{
if (graph == null)
return;
var slected = graphView.selection.OfType<MaterialNodeView>().Select(x => x.node);
foreach (var node in slected.ToArray())
{
if (!(node is IPropertyFromNode))
continue;
var converter = node as IPropertyFromNode;
var prop = converter.AsShaderProperty();
graph.AddShaderProperty(prop);
var propNode = new PropertyNode();
propNode.drawState = node.drawState;
graph.AddNode(propNode);
propNode.propertyGuid = prop.guid;
var oldSlot = node.FindSlot<MaterialSlot>(converter.outputSlotId);
var newSlot = propNode.FindSlot<MaterialSlot>(PropertyNode.OutputSlotId);
var edges = graph.GetEdges(oldSlot.slotReference).ToArray();
foreach (var edge in edges)
graph.Connect(newSlot.slotReference, edge.inputSlot);
graph.RemoveNode(node);
}
}
));
m_ToolbarView.Add(m_InlineSelectedProperties);
m_ToolbarView.Add(m_ConvertToProperty);
m_ToolbarView.Add(new ToolbarSeparatorView());
}

正在加载...
取消
保存