浏览代码

Add converter from v1,v2,v3,v4,col nodes -> properties.

/main
Tim Cooper 7 年前
当前提交
92a955c3
共有 8 个文件被更改,包括 107 次插入7 次删除
  1. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/ColorNode.cs
  2. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector1Node.cs
  3. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector2Node.cs
  4. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector3Node.cs
  5. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector4Node.cs
  6. 36
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  7. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/IPropertyFromNode.cs
  8. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/IPropertyFromNode.cs.meta

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/ColorNode.cs


namespace UnityEditor.ShaderGraph
{
[Title("Input/Color")]
public class ColorNode : AbstractMaterialNode, IGeneratesBodyCode
public class ColorNode : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
[SerializeField]
private Color m_Color;

m_Color = color
});
}
public IShaderProperty AsShaderProperty()
{
var prop = new ColorShaderProperty();
prop.value = color;
return prop;
}
public int outputSlotId { get { return outputSlotId; } }
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector1Node.cs


namespace UnityEditor.ShaderGraph
{
[Title("Input/Vector/Vector 1")]
public class Vector1Node : AbstractMaterialNode, IGeneratesBodyCode
public class Vector1Node : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
[SerializeField]
private float m_Value;

m_Float = m_Value
});
}
public IShaderProperty AsShaderProperty()
{
var prop = new FloatShaderProperty();
prop.value = value;
return prop;
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector2Node.cs


namespace UnityEditor.ShaderGraph
{
[Title("Input/Vector/Vector 2")]
public class Vector2Node : AbstractMaterialNode, IGeneratesBodyCode
public class Vector2Node : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
[SerializeField]
private Vector2 m_Value;

m_Vector4 = m_Value
});
}
public IShaderProperty AsShaderProperty()
{
var prop = new Vector2ShaderProperty();
prop.value = value;
return prop;
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector3Node.cs


using System;
using System.Collections.Generic;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;

{
[Title("Input/Vector/Vector 3")]
public class Vector3Node : AbstractMaterialNode, IGeneratesBodyCode
{
public class Vector3Node : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
[SerializeField]
private Vector3 m_Value;

m_Vector4 = m_Value
});
}
public IShaderProperty AsShaderProperty()
{
var prop = new Vector3ShaderProperty();
prop.value = value;
return prop;
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector4Node.cs


namespace UnityEditor.ShaderGraph
{
[Title("Input/Vector/Vector 4")]
public class Vector4Node : AbstractMaterialNode, IGeneratesBodyCode
public class Vector4Node : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
[SerializeField]
private Vector4 m_Value;

m_Vector4 = m_Value
});
}
public IShaderProperty AsShaderProperty()
{
var prop = new Vector4ShaderProperty();
prop.value = value;
return prop;
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

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


ToolbarButtonView m_CopyToClipboardButton;
ToolbarButtonView m_InlineSelectedProperties;
ToolbarButtonView m_ConvertToProperty;
PreviewManager m_PreviewManager;

}
));
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_ConvertToProperty);
m_ToolbarView.Add(new ToolbarSeparatorView());
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/IPropertyFromNode.cs


namespace UnityEditor.ShaderGraph
{
interface IPropertyFromNode
{
IShaderProperty AsShaderProperty();
int outputSlotId { get; }
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/IPropertyFromNode.cs.meta


fileFormatVersion: 2
guid: 01ab4daa0c099e24e90bbb8623a4198b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存