浏览代码

Gradient edges

/main
Peter Bay Bastian 7 年前
当前提交
dc8375d3
共有 4 个文件被更改,包括 120 次插入28 次删除
  1. 50
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  2. 42
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  3. 53
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GradientEdge.cs
  4. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GradientEdge.cs.meta

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


var targetNodeView = m_GraphView.nodes.ToList().OfType<MaterialNodeView>().FirstOrDefault(x => x.node == targetNode);
var targetAnchor = targetNodeView.inputContainer.Children().OfType<NodeAnchor>().FirstOrDefault(x => x.userData is ISlot && (x.userData as ISlot).Equals(targetSlot));
var edgeView = new Edge
var edgeView = new GradientEdge
edgeView.AddToClassList(sourceSlot.concreteValueType.ToString());
edgeView.UpdateClasses(sourceSlot.concreteValueType, targetSlot.concreteValueType);
edgeView.output.Connect(edgeView);
edgeView.input.Connect(edgeView);
m_GraphView.AddElement(edgeView);

while (nodeStack.Any())
{
var nodeView = nodeStack.Pop();
nodeViews.Add(nodeView);
foreach (var child in nodeView.outputContainer.Children())
foreach (var anchorView in nodeView.outputContainer.Children().OfType<NodeAnchor>())
var anchorView = child as NodeAnchor;
if (anchorView == null)
continue;
var slot = (MaterialSlot)anchorView.userData;
var className = slot.concreteValueType.ToString();
foreach (var connection in anchorView.connections)
var sourceSlot = (MaterialSlot)anchorView.userData;
foreach (var edgeView in anchorView.connections.OfType<GradientEdge>())
connection.ClearClassList();
connection.AddToClassList("edge");
connection.AddToClassList(className);
var connectedNodeView = connection.input.node as MaterialNodeView;
if (connectedNodeView != null && !nodeViews.Contains(connectedNodeView))
nodeStack.Push(connectedNodeView);
var targetSlot = (MaterialSlot)edgeView.input.userData;
if (targetSlot.valueType == SlotValueType.Dynamic)
{
edgeView.UpdateClasses(sourceSlot.concreteValueType, targetSlot.concreteValueType);
var connectedNodeView = edgeView.input.node as MaterialNodeView;
if (connectedNodeView != null && !nodeViews.Contains(connectedNodeView))
{
nodeStack.Push(connectedNodeView);
nodeViews.Add(connectedNodeView);
}
}
}
}
foreach (var anchorView in nodeView.inputContainer.Children().OfType<NodeAnchor>())
{
var targetSlot = (MaterialSlot)anchorView.userData;
foreach (var edgeView in anchorView.connections.OfType<GradientEdge>())
{
var sourceSlot = (MaterialSlot)edgeView.output.userData;
if (sourceSlot.valueType == SlotValueType.Dynamic)
{
edgeView.UpdateClasses(targetSlot.concreteValueType, sourceSlot.concreteValueType);
var connectedNodeView = edgeView.output.node as MaterialNodeView;
if (connectedNodeView != null && !nodeViews.Contains(connectedNodeView))
{
nodeStack.Push(connectedNodeView);
nodeViews.Add(connectedNodeView);
}
}
}
}
}

42
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss


background-color: rgb(0, 225, 25);
}
.edge.Matrix4, .edge.Matrix3, .edge.Matrix2 {
edge-color: #8FC1DF;
.edge.fromMatrix4, .edge.fromMatrix3, .edge.fromMatrix2 {
edge-output-color: #8FC1DF;
}
.edge.toMatrix4, .edge.toMatrix3, .edge.toMatrix2 {
edge-input-color: #8FC1DF;
.edge.Texture2D {
edge-color: #FF8B8B;
.edge.fromTexture2D {
edge-output-color: #FF8B8B;
}
.edge.toTexture2D {
edge-input-color: #FF8B8B;
.edge.Vector4 {
edge-color: #FBCBF4;
.edge.fromVector4 {
edge-output-color: #FBCBF4;
}
.edge.toVector4 {
edge-input-color: #FBCBF4;
.edge.Vector3 {
edge-color: #F6FF9A;
.edge.fromVector3 {
edge-output-color: #F6FF9A;
}
.edge.toVector3 {
edge-input-color: #F6FF9A;
.edge.Vector2 {
edge-color: #9AEF92;
.edge.fromVector2 {
edge-output-color: #9AEF92;
}
.edge.toVector2 {
edge-input-color: #9AEF92;
.edge.Vector1 {
edge-color: #84E4E7;
.edge.fromVector1 {
edge-output-color: #84E4E7;
}
.edge.toVector1 {
edge-input-color: #84E4E7;
}
GraphInspectorView {

53
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GradientEdge.cs


using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.Experimental.UIElements.StyleSheets;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
public class GradientEdge : Edge
{
const string k_InputColorProperty = "edge-input-color";
const string k_OutputColorProperty = "edge-output-color";
StyleValue<Color> m_InputColor;
StyleValue<Color> m_OutputColor;
public Color inputColor
{
get { return m_InputColor.GetSpecifiedValueOrDefault(defaultColor); }
}
public Color outputColor
{
get { return m_OutputColor.GetSpecifiedValueOrDefault(defaultColor); }
}
public void UpdateClasses(ConcreteSlotValueType outputType, ConcreteSlotValueType inputType)
{
ClearClassList();
AddToClassList("edge");
AddToClassList("from" + outputType);
AddToClassList("to" + inputType);
}
protected override void OnStyleResolved(ICustomStyle styles)
{
base.OnStyleResolved(styles);
styles.ApplyCustomProperty(k_InputColorProperty, ref m_InputColor);
styles.ApplyCustomProperty(k_OutputColorProperty, ref m_OutputColor);
}
protected override void DrawEdge()
{
if (!UpdateEdgeControl())
return;
edgeControl.edgeWidth = edgeWidth;
edgeControl.inputColor = isGhostEdge ? ghostColor : (selected ? selectedColor : inputColor);
edgeControl.outputColor = isGhostEdge ? ghostColor : (selected ? selectedColor : outputColor);
edgeControl.startCapColor = edgeControl.outputColor;
edgeControl.endCapColor = edgeControl.inputColor;
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GradientEdge.cs.meta


fileFormatVersion: 2
guid: 161180898f1d444880080d666ab7be1d
timeCreated: 1509019463
正在加载...
取消
保存