浏览代码

Merge branch 'attribute-controls'

# Conflicts:
#	MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
/main
Peter Bay Bastian 7 年前
当前提交
9f5fba90
共有 54 个文件被更改,包括 1086 次插入629 次删除
  1. 5
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/BlendModeNode.cs
  2. 2
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/ConstantsNode.cs
  3. 223
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/GradientNode.cs
  4. 3
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/SamplerStateNode.cs
  5. 3
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/TransformNode.cs
  6. 28
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/ColorNode.cs
  7. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/UVNode.cs
  8. 46
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix2Node.cs
  9. 56
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix3Node.cs
  10. 62
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix4Node.cs
  11. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/MatrixCommonNode.cs
  12. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector1Node.cs
  13. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector2Node.cs
  14. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector3Node.cs
  15. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector4Node.cs
  16. 261
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Logic/IFNode.cs
  17. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyNode.cs
  18. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/MasterRemapNode.cs
  19. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphNode.cs
  20. 39
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphOutputNode.cs
  21. 53
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  22. 42
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
  23. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls.meta
  24. 42
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Gradient.ShaderGraph
  25. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Gradient.ShaderGraph.meta
  26. 53
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ColorControl.cs
  27. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ColorControl.cs.meta
  28. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/DefaultControl.cs.meta
  29. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/IControlAttribute.cs
  30. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/IControlAttribute.cs.meta
  31. 165
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/VectorControl.cs
  32. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/VectorControl.cs.meta
  33. 52
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumControl.cs
  34. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumControl.cs.meta
  35. 44
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/PropertyControl.cs
  36. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/PropertyControl.cs.meta
  37. 89
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/GradientControl.cs
  38. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/GradientControl.cs.meta
  39. 53
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ObjectControl.cs
  40. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ObjectControl.cs.meta
  41. 29
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/DefaultControl.cs
  42. 12
      MaterialGraphProject/Assets/NewNodes/Editor/ConstantsNodePresenter.cs.meta
  43. 12
      MaterialGraphProject/Assets/NewNodes/Editor/BlendModeNodePresenter.cs.meta
  44. 12
      MaterialGraphProject/Assets/NewNodes/Editor/ToggleNodePresenter.cs.meta
  45. 12
      MaterialGraphProject/Assets/NewNodes/Editor/TransformNodePresenter.cs.meta
  46. 43
      MaterialGraphProject/Assets/NewNodes/Editor/BlendModeNodePresenter.cs
  47. 49
      MaterialGraphProject/Assets/NewNodes/Editor/ConstantsNodePresenter.cs
  48. 41
      MaterialGraphProject/Assets/NewNodes/Editor/TransformNodePresenter.cs
  49. 45
      MaterialGraphProject/Assets/NewNodes/Editor/ToggleNodePresenter.cs
  50. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs.meta
  51. 49
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs
  52. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes.meta

5
MaterialGraphProject/Assets/NewNodes/Editor/Keep/BlendModeNode.cs


using System.Reflection;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

}
[SerializeField]
private BlendModesEnum m_BlendMode;
BlendModesEnum m_BlendMode;
[EnumControl("")]
public BlendModesEnum blendMode
{
get { return m_BlendMode; }

2
MaterialGraphProject/Assets/NewNodes/Editor/Keep/ConstantsNode.cs


using System.Collections.Generic;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.MaterialGraph;
using UnityEngine.Graphing;

private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Constant";
[EnumControl("")]
public ConstantType constant
{
get { return m_constant; }

223
MaterialGraphProject/Assets/NewNodes/Editor/Keep/GradientNode.cs


using System.Reflection;
using System.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.MaterialGraph.Drawing.Controls;
public class GradientNode : CodeFunctionNode
public class GradientNode : AbstractMaterialNode, IGeneratesBodyCode
Gradient m_Gradient;
private Gradient m_gradient;
Vector4[] m_SerializableColorKeys = { new Vector4(1f, 1f, 1f, 0f), new Vector4(0f, 0f, 0f, 1f), };
[SerializeField]
Vector2[] m_SerializableAlphaKeys = { new Vector2(1f, 0f), new Vector2(1f, 1f) };
[GradientControl("")]
get { return m_gradient; }
get
{
return m_Gradient;
}
if (m_gradient == value)
return;
var scope = ModificationScope.Nothing;
m_gradient = value;
if (onModified != null)
onModified(this, ModificationScope.Graph);
var currentColorKeys = m_Gradient.colorKeys;
var currentAlphaKeys = m_Gradient.alphaKeys;
var newColorKeys = value.colorKeys;
var newAlphaKeys = value.alphaKeys;
if (currentColorKeys.Length != newColorKeys.Length || currentAlphaKeys.Length != newAlphaKeys.Length)
{
scope = scope < ModificationScope.Graph ? ModificationScope.Graph : scope;
}
else
{
for (var i = 0; i < currentColorKeys.Length; i++)
{
if (currentColorKeys[i].color != newColorKeys[i].color || Math.Abs(currentColorKeys[i].time - newColorKeys[i].time) > 1e-9)
scope = scope < ModificationScope.Node ? ModificationScope.Node : scope;
}
for (var i = 0; i < currentAlphaKeys.Length; i++)
{
if (Math.Abs(currentAlphaKeys[i].alpha - newAlphaKeys[i].alpha) > 1e-9 || Math.Abs(currentAlphaKeys[i].time - newAlphaKeys[i].time) > 1e-9)
scope = scope < ModificationScope.Node ? ModificationScope.Node : scope;
}
}
if (scope > ModificationScope.Nothing)
{
gradient.SetKeys(newColorKeys, newAlphaKeys);
if (onModified != null)
onModified(this, scope);
}
public void UpdateGradient()
{
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
public const int TimeInputSlotId = 0;
const string k_TimeInputSlotName = "Time";
// Debug.Log("UPDATED GRAPH");
}
public const int RGBAOutputSlotId = 1;
const string k_RGBAOutputSlotName = "RGBA";
public const int ROutputSlotId = 2;
const string k_ROutputSlotName = "R";
public const int GOutputSlotId = 3;
const string k_GOutputSlotName = "G";
public const int BOutputSlotId = 4;
const string k_BOutputSlotName = "B";
public const int AOutputSlotId = 5;
const string k_AOutputSlotName = "A";
UpdateNodeAfterDeserialization();
protected override MethodInfo GetFunctionToConvert()
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(TimeInputSlotId, k_TimeInputSlotName, k_TimeInputSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(RGBAOutputSlotId, k_RGBAOutputSlotName, k_RGBAOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(ROutputSlotId, k_ROutputSlotName, k_ROutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(GOutputSlotId, k_GOutputSlotName, k_GOutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(BOutputSlotId, k_BOutputSlotName, k_BOutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(AOutputSlotId, k_AOutputSlotName, k_AOutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { TimeInputSlotId, RGBAOutputSlotId, ROutputSlotId, GOutputSlotId, BOutputSlotId, AOutputSlotId });
m_Gradient = new Gradient();
var colorKeys = m_SerializableColorKeys.Select(k => new GradientColorKey(new Color(k.x, k.y, k.z, 1f), k.w)).ToArray();
var alphaKeys = m_SerializableAlphaKeys.Select(k => new GradientAlphaKey(k.x, k.y)).ToArray();
m_Gradient.SetKeys(colorKeys, alphaKeys);
}
public override void OnBeforeSerialize()
{
base.OnBeforeSerialize();
m_SerializableColorKeys = gradient.colorKeys.Select(k => new Vector4(k.color.r, k.color.g, k.color.b, k.time)).ToArray();
m_SerializableAlphaKeys = gradient.alphaKeys.Select(k => new Vector2(k.alpha, k.time)).ToArray();
}
string GetColorKeyName(int index)
{
return string.Format("{0}_ck{1}", GetVariableNameForNode(), index);
}
string GetAlphaKeyName(int index)
return GetType().GetMethod("Unity_Gradient", BindingFlags.NonPublic | BindingFlags.Instance);
return string.Format("{0}_ak{1}", GetVariableNameForNode(), index);
string Unity_Gradient(
[Slot(0, Binding.None)] Vector1 value,
[Slot(1, Binding.None)] out Vector4 result)
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
result = Vector4.zero;
base.CollectShaderProperties(properties, generationMode);
var colorKeys = m_Gradient.colorKeys;
var alphaKeys = m_Gradient.alphaKeys;
GradientColorKey[] colorkeys = m_gradient.colorKeys;
GradientAlphaKey[] alphakeys = m_gradient.alphaKeys;
for (var i = 0; i < colorKeys.Length; i++)
{
var colorKey = colorKeys[i];
properties.AddShaderProperty(new Vector4ShaderProperty
{
overrideReferenceName = GetColorKeyName(i),
generatePropertyBlock = false,
value = new Vector4(colorKey.color.r, colorKey.color.g, colorKey.color.b, colorKey.time)
});
}
//Start
StringBuilder outputString = new StringBuilder();
string start = @"
{
";
outputString.Append(start);
//Color
Color c;
float cp;
for (int i = 0; i < colorkeys.Length; i++)
for (var i = 0; i < alphaKeys.Length; i++)
c = colorkeys[i].color;
cp = colorkeys[i].time;
outputString.AppendLine(string.Format("\t{{precision}}3 color{0}=float3({1},{2},{3});", i, c.r, c.g, c.b));
outputString.AppendLine(string.Format("\t{{precision}} colorp{0}={1};", i, cp));
properties.AddShaderProperty(new Vector2ShaderProperty
{
overrideReferenceName = GetAlphaKeyName(i),
generatePropertyBlock = false,
value = new Vector2(alphaKeys[i].alpha, alphaKeys[i].time)
});
}
outputString.AppendLine("\t{precision}3 gradcolor = color0;");
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
base.CollectPreviewMaterialProperties(properties);
for (int i = 0; i < colorkeys.Length - 1; i++)
var colorKeys = m_Gradient.colorKeys;
var alphaKeys = m_Gradient.alphaKeys;
for (var i = 0; i < colorKeys.Length; i++)
int j = i + 1;
outputString.AppendLine(string.Format("\t{{precision}} colorLerpPosition{0}=smoothstep(colorp{0},colorp{1},value);", i, j));
outputString.AppendLine(string.Format("\tgradcolor = lerp(gradcolor,color{0},colorLerpPosition{1});", j, i));
var colorKey = colorKeys[i];
properties.Add(new PreviewProperty()
{
m_Name = GetColorKeyName(i),
m_PropType = PropertyType.Vector4,
m_Vector4 = new Vector4(colorKey.color.r, colorKey.color.g, colorKey.color.b, colorKey.time)
});
//Alpha
float a;
float ap;
for (int i = 0; i < alphakeys.Length; i++)
for (var i = 0; i < alphaKeys.Length; i++)
a = alphakeys[i].alpha;
ap = alphakeys[i].time;
outputString.AppendLine(string.Format("\t{{precision}} alpha{0}={1};", i, a));
outputString.AppendLine(string.Format("\t{{precision}} alphap{0}={1};", i, ap));
properties.Add(new PreviewProperty
{
m_Name = GetAlphaKeyName(i),
m_PropType = PropertyType.Vector2,
m_Vector4 = new Vector2(alphaKeys[i].alpha, alphaKeys[i].time)
});
}
outputString.AppendLine("\t{precision} gradalpha = alpha0;");
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
var rgbaOutputName = GetVariableNameForSlot(RGBAOutputSlotId);
visitor.AddShaderChunk(string.Format("{0}4 {1} = {0}4({2}.rgb, {3}.r);", precision, rgbaOutputName, GetColorKeyName(0), GetAlphaKeyName(0)), false);
for (int i = 0; i < alphakeys.Length - 1; i++)
visitor.AddShaderChunk("{", false);
visitor.Indent();
int j = i + 1;
outputString.AppendLine(string.Format("\t{{precision}} alphaLerpPosition{0}=smoothstep(alphap{0},alphap{1},value);", i, j));
outputString.AppendLine(string.Format("\tgradalpha = lerp(gradalpha,alpha{0},alphaLerpPosition{1});", j, i));
var timeInputValue = GetSlotValue(TimeInputSlotId, generationMode);
// Color interpolation
for (var i = 0; i < m_Gradient.colorKeys.Length - 1; i++)
visitor.AddShaderChunk(string.Format("{3}.rgb = lerp({3}.rgb, {1}.rgb, smoothstep({0}.a, {1}.a, {2}));", GetColorKeyName(i), GetColorKeyName(i + 1), timeInputValue, rgbaOutputName), false);
// Alpha interpolation
for (var i = 0; i < m_Gradient.alphaKeys.Length - 1; i++)
visitor.AddShaderChunk(string.Format("{3}.a = lerp({3}.a, {1}.r, smoothstep({0}.g, {1}.g, {2}));", GetAlphaKeyName(i), GetAlphaKeyName(i + 1), timeInputValue, rgbaOutputName), false);
visitor.Deindent();
visitor.AddShaderChunk("}", false);
//Result
outputString.AppendLine("\tresult = float4(gradcolor,gradalpha);");
outputString.AppendLine("}");
return outputString.ToString();
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.r;", precision, GetVariableNameForSlot(ROutputSlotId), rgbaOutputName), false);
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.g;", precision, GetVariableNameForSlot(GOutputSlotId), rgbaOutputName), false);
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.b;", precision, GetVariableNameForSlot(BOutputSlotId), rgbaOutputName), false);
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.a;", precision, GetVariableNameForSlot(AOutputSlotId), rgbaOutputName), false);
}
}
}

3
MaterialGraphProject/Assets/NewNodes/Editor/Keep/SamplerStateNode.cs


using System;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

[SerializeField]
private TextureSamplerState.FilterMode m_filter = TextureSamplerState.FilterMode.Linear;
[EnumControl]
public TextureSamplerState.FilterMode filter
{
get { return m_filter; }

[SerializeField]
private TextureSamplerState.WrapMode m_wrap = TextureSamplerState.WrapMode.Repeat;
[EnumControl]
public TextureSamplerState.WrapMode wrap
{
get { return m_wrap; }

3
MaterialGraphProject/Assets/NewNodes/Editor/Keep/TransformNode.cs


using UnityEngine.Graphing;
using System.Collections.Generic;
using UnityEditor.MaterialGraph.Drawing.Controls;
namespace UnityEngine.MaterialGraph
{

private const string kInputSlotName = "Input";
private const string kOutputSlotName = "Output";
[EnumControl("From")]
public SimpleMatrixType spaceFrom
{
get { return m_spaceListFrom; }

get { return false; }
}
[EnumControl("To")]
public SimpleMatrixType spaceTo
{
get { return m_spaceListTo; }

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


using System.Collections.Generic;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

{
[SerializeField]
private bool m_HDR;
[SerializeField]
private Color m_Color;

public bool HDR
{
get { return m_HDR; }
set
{
if (m_HDR == value)
return;
m_HDR = value;
if (onModified != null)
{
onModified(this, ModificationScope.Node);
}
}
}
public ColorNode()
{
name = "Color";

public override bool hasPreview
{
get { return true; }
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));

[ColorControl("")]
public Color color
{
get { return m_Color; }

overrideReferenceName = GetVariableNameForNode(),
generatePropertyBlock = false,
value = color,
HDR = HDR
HDR = false
});
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/UVNode.cs


using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

[SerializeField]
private UVChannel m_OutputChannel;
[EnumControl("")]
public UVChannel uvChannel
{
get { return m_OutputChannel; }

46
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix2Node.cs


using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

{
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Value";
const int kOutputSlotId = 0;
const string kOutputSlotName = "Value";
private Vector2[] m_Value = new Vector2[2];
Vector2 m_Row0;
public Vector2 this[int index]
[SerializeField]
Vector2 m_Row1;
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector2 row0
get { return m_Value[index]; }
set
{
if (m_Value[index] == value)
return;
get { return m_Row0; }
set { SetRow(ref m_Row0, value); }
}
m_Value[index] = value;
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector2 row1
{
get { return m_Row1; }
set { SetRow(ref m_Row1, value); }
}
if (onModified != null)
onModified(this, ModificationScope.Node);
}
void SetRow(ref Vector2 row, Vector2 value)
{
if (value == row)
return;
row = value;
if (onModified != null)
onModified(this, ModificationScope.Graph);
}
public Matrix2Node()

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Matrix2, Vector4.zero));
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Matrix2, Vector2.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

//if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
// return;
visitor.AddShaderChunk(precision + "2 " + name + " = " + precision + "2x2 (" + m_Value[0].x + ", " + m_Value[0].y + ", " + m_Value[1].x + ", " + m_Value[1].y + ");", true);
visitor.AddShaderChunk(precision + "2 " + name + " = " + precision + "2x2 (" + m_Row0.x + ", " + m_Row0.y + ", " + m_Row1.x + ", " + m_Row1.y + ");", true);
private string m_Description = string.Empty;
string m_Description = string.Empty;
public string description
{

{
m_Name = propertyName,
m_PropType = PropertyType.Vector2,
m_Vector4 = m_Value
m_Vector2 = m_Value
};
}*/
}

56
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix3Node.cs


using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

{
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Value";
const int kOutputSlotId = 0;
const string kOutputSlotName = "Value";
private Vector3[] m_Value = new Vector3[3];
Vector3 m_Row0;
public Vector3 this[int index]
[SerializeField]
Vector3 m_Row1;
[SerializeField]
Vector3 m_Row2;
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector3 row0
get { return m_Value[index]; }
set
{
if (m_Value[index] == value)
return;
get { return m_Row0; }
set { SetRow(ref m_Row0, value); }
}
m_Value[index] = value;
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector3 row1
{
get { return m_Row1; }
set { SetRow(ref m_Row1, value); }
}
if (onModified != null)
onModified(this, ModificationScope.Node);
}
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector3 row2
{
get { return m_Row2; }
set { SetRow(ref m_Row2, value); }
}
void SetRow(ref Vector3 row, Vector3 value)
{
if (value == row)
return;
row = value;
if (onModified != null)
onModified(this, ModificationScope.Graph);
}
public Matrix3Node()

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Matrix3, Vector4.zero));
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Matrix3, Vector3.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

//if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
// return;
visitor.AddShaderChunk(precision + "3x3 " + propertyName + " = " + precision + "3x3 (" + m_Value[0].x + ", " + m_Value[0].y + ", " + m_Value[0].z + ", " + m_Value[1].x + ", " + m_Value[1].y + ", " + m_Value[1].z + ", " + m_Value[2].x + ", " + m_Value[2].y + ", " + m_Value[2].z + ");", true);
visitor.AddShaderChunk(precision + "3x3 " + propertyName + " = " + precision + "3x3 (" + m_Row0.x + ", " + m_Row0.y + ", " + m_Row0.z + ", " + m_Row1.x + ", " + m_Row1.y + ", " + m_Row1.z + ", " + m_Row2.x + ", " + m_Row2.y + ", " + m_Row2.z + ");", true);
private string m_Description = string.Empty;
string m_Description = string.Empty;
public string description
{

{
m_Name = propertyName,
m_PropType = PropertyType.Vector2,
m_Vector4 = m_Value
m_Vector3 = m_Value
};
}*/
}

62
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix4Node.cs


using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

{
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Value";
const int kOutputSlotId = 0;
const string kOutputSlotName = "Value";
private Vector4[] m_Value = new Vector4[4];
Vector4 m_Row0;
[SerializeField]
Vector4 m_Row1;
[SerializeField]
Vector4 m_Row2;
[SerializeField]
Vector4 m_Row3;
public Vector4 this[int index]
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector4 row0
get { return m_Value[index]; }
set
{
if (m_Value[index] == value)
return;
get { return m_Row0; }
set { SetRow(ref m_Row0, value); }
}
m_Value[index] = value;
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector4 row1
{
get { return m_Row1; }
set { SetRow(ref m_Row1, value); }
}
if (onModified != null)
onModified(this, ModificationScope.Node);
}
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector4 row2
{
get { return m_Row2; }
set { SetRow(ref m_Row2, value); }
}
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector4 row3
{
get { return m_Row3; }
set { SetRow(ref m_Row3, value); }
}
void SetRow(ref Vector4 row, Vector4 value)
{
if (value == row)
return;
row = value;
if (onModified != null)
onModified(this, ModificationScope.Graph);
}
public Matrix4Node()

//if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
// return;
visitor.AddShaderChunk(precision + "4x4 " + propertyName + " = " + precision + "4x4 (" + m_Value[0].x + ", " + m_Value[0].y + ", " + m_Value[0].z + ", " + m_Value[0].w + ", " + m_Value[1].x + ", " + m_Value[1].y + ", " + m_Value[1].z + ", " + m_Value[1].w + ", " + m_Value[2].x + ", " + m_Value[2].y + ", " + m_Value[2].z + ", " + m_Value[2].w + ", " + m_Value[3].x + ", " + m_Value[3].y + ", " + m_Value[3].z + ", " + m_Value[3].w + ");", true);
visitor.AddShaderChunk(precision + "4x4 " + propertyName + " = " + precision + "4x4 (" + row0.x + ", " + row0.y + ", " + row0.z + ", " + row0.w + ", " + m_Row1.x + ", " + m_Row1.y + ", " + m_Row1.z + ", " + m_Row1.w + ", " + m_Row2.x + ", " + m_Row2.y + ", " + m_Row2.z + ", " + m_Row2.w + ", " + m_Row3.x + ", " + m_Row3.y + ", " + m_Row3.z + ", " + m_Row3.w + ");", true);
private string m_Description = string.Empty;
string m_Description = string.Empty;
public string description
{

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/MatrixCommonNode.cs


using System.ComponentModel;
using UnityEngine.Graphing;
using System.Collections.Generic;
using UnityEditor.MaterialGraph.Drawing.Controls;
namespace UnityEngine.MaterialGraph
{

public override bool hasPreview { get { return false; } }
[EnumControl("")]
public CommonMatrixType matrix
{
get { return m_matrix; }

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


using System.Collections.Generic;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[MultiFloatControl("")]
public float value
{
get { return m_Value; }

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


using System.Collections.Generic;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[MultiFloatControl("")]
public Vector2 value
{
get { return m_Value; }

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


using System;
using System.Collections.Generic;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[MultiFloatControl("")]
public Vector3 value
{
get { return m_Value; }

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


using System.Collections.Generic;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[MultiFloatControl("")]
public Vector4 value
{
get { return m_Value; }

261
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Logic/IFNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Logic/If")]
public class IfNode : CodeFunctionNode
{
public enum ComparisonOperationType
{
Equal = 0,
NotEqual,
GreaterThan,
GreaterThanOrEqual,
LessThan,
LessThanOrEqual
}
[SerializeField]
private ComparisonOperationType m_comparisonOperation = ComparisonOperationType.Equal;
public ComparisonOperationType ComparisonOperation
{
get { return m_comparisonOperation; }
set
{
if (m_comparisonOperation == value)
return;
m_comparisonOperation = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public IfNode()
{
name = "If";
}
protected override MethodInfo GetFunctionToConvert()
{
switch (ComparisonOperation)
{
case ComparisonOperationType.Equal:
return GetType().GetMethod("Unity_IfEqual", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonOperationType.NotEqual:
return GetType().GetMethod("Unity_IfNotEqual", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonOperationType.GreaterThan:
return GetType().GetMethod("Unity_IfGreaterThan", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonOperationType.GreaterThanOrEqual:
return GetType().GetMethod("Unity_IfGreaterThanOrEqual", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonOperationType.LessThan:
return GetType().GetMethod("Unity_IfLessThan", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonOperationType.LessThanOrEqual:
return GetType().GetMethod("Unity_IfLessThanOrEqual", BindingFlags.Static | BindingFlags.NonPublic);
default:
throw new ArgumentOutOfRangeException();
}
}
const string functionTemplate = @"
{
if({comparitor})
{
result = trueValue;
}
else
{
result = falseValue;
}
}
";
static string Unity_IfEqual(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result)
{
return functionTemplate.Replace("{comparitor}", "a == b");
}
static string Unity_IfNotEqual(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result)
{
return functionTemplate.Replace("{comparitor}", "a != b");
}
static string Unity_IfGreaterThan(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result)
{
return functionTemplate.Replace("{comparitor}", "a > b");
}
static string Unity_IfGreaterThanOrEqual(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result)
{
return functionTemplate.Replace("{comparitor}", "a >= b");
}
static string Unity_IfLessThan(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result)
{
return functionTemplate.Replace("{comparitor}", "a < b");
}
static string Unity_IfLessThanOrEqual(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result)
{
return functionTemplate.Replace("{comparitor}", "a <= b");
}
}
// PROBABLY USEFUL, BUT BROKEN AT THE MOMENT
// [Title("Logic/If")]
// public class IfNode : CodeFunctionNode
// {
// public enum ComparisonOperationType
// {
// Equal = 0,
// NotEqual,
// GreaterThan,
// GreaterThanOrEqual,
// LessThan,
// LessThanOrEqual
// }
//
// [SerializeField]
// private ComparisonOperationType m_comparisonOperation = ComparisonOperationType.Equal;
//
// public ComparisonOperationType ComparisonOperation
// {
// get { return m_comparisonOperation; }
// set
// {
// if (m_comparisonOperation == value)
// return;
//
// m_comparisonOperation = value;
// if (onModified != null)
// {
// onModified(this, ModificationScope.Graph);
// }
// }
// }
//
// public IfNode()
// {
// name = "If";
// }
//
// protected override MethodInfo GetFunctionToConvert()
// {
// switch (ComparisonOperation)
// {
// case ComparisonOperationType.Equal:
// return GetType().GetMethod("Unity_IfEqual", BindingFlags.Static | BindingFlags.NonPublic);
// case ComparisonOperationType.NotEqual:
// return GetType().GetMethod("Unity_IfNotEqual", BindingFlags.Static | BindingFlags.NonPublic);
// case ComparisonOperationType.GreaterThan:
// return GetType().GetMethod("Unity_IfGreaterThan", BindingFlags.Static | BindingFlags.NonPublic);
// case ComparisonOperationType.GreaterThanOrEqual:
// return GetType().GetMethod("Unity_IfGreaterThanOrEqual", BindingFlags.Static | BindingFlags.NonPublic);
// case ComparisonOperationType.LessThan:
// return GetType().GetMethod("Unity_IfLessThan", BindingFlags.Static | BindingFlags.NonPublic);
// case ComparisonOperationType.LessThanOrEqual:
// return GetType().GetMethod("Unity_IfLessThanOrEqual", BindingFlags.Static | BindingFlags.NonPublic);
// default:
// throw new ArgumentOutOfRangeException();
// }
// }
//
// const string functionTemplate = @"
//{
// if({comparitor})
// {
// result = trueValue;
// }
// else
// {
// result = falseValue;
// }
//}
//";
// static string Unity_IfEqual(
// [Slot(0, Binding.None)] DynamicDimensionVector a,
// [Slot(1, Binding.None)] DynamicDimensionVector b,
// [Slot(2, Binding.None)] DynamicDimensionVector trueValue,
// [Slot(3, Binding.None)] DynamicDimensionVector falseValue,
// [Slot(4, Binding.None)] DynamicDimensionVector result)
// {
// return functionTemplate.Replace("{comparitor}", "a == b");
// }
//
// static string Unity_IfNotEqual(
// [Slot(0, Binding.None)] DynamicDimensionVector a,
// [Slot(1, Binding.None)] DynamicDimensionVector b,
// [Slot(2, Binding.None)] DynamicDimensionVector trueValue,
// [Slot(3, Binding.None)] DynamicDimensionVector falseValue,
// [Slot(4, Binding.None)] DynamicDimensionVector result)
// {
// return functionTemplate.Replace("{comparitor}", "a != b");
// }
//
// static string Unity_IfGreaterThan(
// [Slot(0, Binding.None)] DynamicDimensionVector a,
// [Slot(1, Binding.None)] DynamicDimensionVector b,
// [Slot(2, Binding.None)] DynamicDimensionVector trueValue,
// [Slot(3, Binding.None)] DynamicDimensionVector falseValue,
// [Slot(4, Binding.None)] DynamicDimensionVector result)
// {
// return functionTemplate.Replace("{comparitor}", "a > b");
// }
//
// static string Unity_IfGreaterThanOrEqual(
// [Slot(0, Binding.None)] DynamicDimensionVector a,
// [Slot(1, Binding.None)] DynamicDimensionVector b,
// [Slot(2, Binding.None)] DynamicDimensionVector trueValue,
// [Slot(3, Binding.None)] DynamicDimensionVector falseValue,
// [Slot(4, Binding.None)] DynamicDimensionVector result)
// {
// return functionTemplate.Replace("{comparitor}", "a >= b");
// }
//
// static string Unity_IfLessThan(
// [Slot(0, Binding.None)] DynamicDimensionVector a,
// [Slot(1, Binding.None)] DynamicDimensionVector b,
// [Slot(2, Binding.None)] DynamicDimensionVector trueValue,
// [Slot(3, Binding.None)] DynamicDimensionVector falseValue,
// [Slot(4, Binding.None)] DynamicDimensionVector result)
// {
// return functionTemplate.Replace("{comparitor}", "a < b");
// }
//
// static string Unity_IfLessThanOrEqual(
// [Slot(0, Binding.None)] DynamicDimensionVector a,
// [Slot(1, Binding.None)] DynamicDimensionVector b,
// [Slot(2, Binding.None)] DynamicDimensionVector trueValue,
// [Slot(3, Binding.None)] DynamicDimensionVector falseValue,
// [Slot(4, Binding.None)] DynamicDimensionVector result)
// {
// return functionTemplate.Replace("{comparitor}", "a <= b");
// }
// }
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyNode.cs


using System;
using System.Linq;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

return edges.Count == 0;
}
[PropertyControl]
public Guid propertyGuid
{
get { return m_PropertyGuid; }

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/MasterRemapNode.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

}
#if UNITY_EDITOR
[ObjectControl("Remap")]
public MasterRemapGraphAsset remapGraphAsset
{
get

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphNode.cs


using System;
using System.Linq;
using UnityEditor.MaterialGraph.Drawing.Controls;
#if UNITY_EDITOR
using UnityEditor;
#endif

}
#if UNITY_EDITOR
[ObjectControl("Subgraph")]
public MaterialSubGraphAsset subGraphAsset
{
get

39
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphOutputNode.cs


using System;
using System.Reflection;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

name = "SubGraphOutputs";
}
[SubGraphOutputControl]
int controlDummy { get; set; }
public override int AddSlot()
{
var index = GetInputSlots<ISlot>().Count() + 1;

}
public override bool allowedInRemapGraph { get { return false; } }
}
public class SubGraphOutputControlAttribute : Attribute, IControlAttribute
{
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
if (!(node is AbstractSubGraphIONode))
throw new ArgumentException("Node must inherit from AbstractSubGraphIONode.", "node");
return new SubGraphOutputControlView((AbstractSubGraphIONode)node);
}
}
public class SubGraphOutputControlView : VisualElement
{
AbstractSubGraphIONode m_Node;
public SubGraphOutputControlView(AbstractSubGraphIONode node)
{
m_Node = node;
Add(new Button(OnAdd) { text = "Add Slot" });
Add(new Button(OnRemove) { text = "Remove Slot" });
}
void OnAdd()
{
m_Node.AddSlot();
}
void OnRemove()
{
m_Node.RemoveSlot();
}
}
}

53
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


[Serializable]
public class MaterialGraphPresenter : GraphViewPresenter
{
GraphTypeMapper typeMapper { get; set; }
PreviewSystem m_PreviewSystem;
public IGraph graph { get; private set; }

protected MaterialGraphPresenter()
{
typeMapper = new GraphTypeMapper(typeof(MaterialNodePresenter));
typeMapper[typeof(AbstractMaterialNode)] = typeof(MaterialNodePresenter);
typeMapper[typeof(ColorNode)] = typeof(ColorNodePresenter);
typeMapper[typeof(GradientNode)] = typeof(GradientNodePresenter);
// typeMapper[typeof(ScatterNode)] = typeof(ScatterNodePresenter);
//typeMapper[typeof(TextureNode)] = typeof(TextureNodePresenter);
//typeMapper[typeof(SamplerAssetNode)] = typeof(SamplerAssetNodePresenter);
//typeMapper[typeof(TextureSamplerNode)] = typeof(TextureSamplerNodePresenter);
// typeMapper[typeof(Texture2DNode)] = typeof(TextureAssetNodePresenter);
// typeMapper[typeof(TextureLODNode)] = typeof(TextureLODNodePresenter);
typeMapper[typeof(SamplerStateNode)] = typeof(SamplerStateNodePresenter);
// typeMapper[typeof(CubemapNode)] = typeof(CubeNodePresenter);
// typeMapper[typeof(ToggleNode)] = typeof(ToggleNodePresenter);
typeMapper[typeof(UVNode)] = typeof(UVNodePresenter);
typeMapper[typeof(Vector1Node)] = typeof(Vector1NodePresenter);
typeMapper[typeof(Vector2Node)] = typeof(Vector2NodePresenter);
typeMapper[typeof(Vector3Node)] = typeof(Vector3NodePresenter);
typeMapper[typeof(Vector4Node)] = typeof(Vector4NodePresenter);
typeMapper[typeof(PropertyNode)] = typeof(PropertyNodePresenter);
/* typeMapper[typeof(ScaleOffsetNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(RadialShearNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(SphereWarpNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(SphericalIndentationNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(AACheckerboardNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(AACheckerboard3dNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter*/
typeMapper[typeof(SubGraphNode)] = typeof(SubgraphNodePresenter);
typeMapper[typeof(MasterRemapNode)] = typeof(MasterRemapNodePresenter);
// typeMapper[typeof(MasterRemapInputNode)] = typeof(RemapInputNodePresenter);
typeMapper[typeof(AbstractSubGraphIONode)] = typeof(SubgraphIONodePresenter);
// typeMapper[typeof(AbstractSurfaceMasterNode)] = typeof(SurfaceMasterNodePresenter);
typeMapper[typeof(LevelsNode)] = typeof(LevelsNodePresenter);
typeMapper[typeof(ConstantsNode)] = typeof(ConstantsNodePresenter);
//typeMapper[typeof(SwizzleNode)] = typeof(SwizzleNodePresenter);
typeMapper[typeof(BlendModeNode)] = typeof(BlendModeNodePresenter);
// typeMapper[typeof(AddManyNode)] = typeof(AddManyNodePresenter);
typeMapper[typeof(IfNode)] = typeof(IfNodePresenter);
//typeMapper[typeof(CustomCodeNode)] = typeof(CustomCodePresenter);
typeMapper[typeof(Matrix2Node)] = typeof(Matrix2NodePresenter);
typeMapper[typeof(Matrix3Node)] = typeof(Matrix3NodePresenter);
typeMapper[typeof(Matrix4Node)] = typeof(Matrix4NodePresenter);
typeMapper[typeof(MatrixCommonNode)] = typeof(MatrixCommonNodePresenter);
typeMapper[typeof(TransformNode)] = typeof(TransformNodePresenter);
// typeMapper[typeof(ConvolutionFilterNode)] = typeof(ConvolutionFilterNodePresenter);
}
public override List<NodeAnchorPresenter> GetCompatibleAnchors(NodeAnchorPresenter startAnchor, NodeAdapter nodeAdapter)

void NodeAdded(NodeAddedGraphChange change)
{
var nodePresenter = (MaterialNodePresenter)typeMapper.Create(change.node);
var nodePresenter = CreateInstance<MaterialNodePresenter>();
change.node.onModified += OnNodeChanged;
nodePresenter.Initialize(change.node, m_PreviewSystem);
m_Elements.Add(nodePresenter);

42
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
using UnityEngine;

public class MaterialNodeView : Node
{
VisualElement m_ControlsContainer;
List<GraphControlPresenter> m_CurrentControls;
List<VisualElement> m_ControlViews;
Guid m_NodeGuid;
VisualElement m_PreviewToggle;
VisualElement m_ResizeHandle;
Image m_PreviewImage;

name = "controls"
};
leftContainer.Add(m_ControlsContainer);
m_CurrentControls = new List<GraphControlPresenter>();
m_ControlViews = new List<VisualElement>();
m_PreviewToggle = new VisualElement { name = "toggle", text = "" };
m_PreviewToggle.AddManipulator(new Clickable(OnPreviewToggle));

}
void UpdateControls(MaterialNodePresenter nodeData)
void UpdateControls(MaterialNodePresenter nodePresenter)
if (nodeData.controls.SequenceEqual(m_CurrentControls) && nodeData.expanded)
return;
if (!nodePresenter.node.guid.Equals(m_NodeGuid))
{
m_ControlViews.Clear();
foreach (var propertyInfo in nodePresenter.node.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
foreach (IControlAttribute attribute in propertyInfo.GetCustomAttributes(typeof(IControlAttribute), false))
m_ControlViews.Add(attribute.InstantiateControl(nodePresenter.node, propertyInfo));
}
}
if (!nodePresenter.expanded)
{
m_CurrentControls.Clear();
Dirty(ChangeType.Layout);
if (!nodeData.expanded)
return;
foreach (var controlData in nodeData.controls)
}
else if (m_ControlsContainer.childCount != m_ControlViews.Count)
m_ControlsContainer.Add(new IMGUIContainer(controlData.OnGUIHandler)
{
name = "element"
});
m_CurrentControls.Add(controlData);
m_ControlsContainer.Clear();
foreach (var view in m_ControlViews)
m_ControlsContainer.Add(view);
}
}

if (nodePresenter == null)
{
m_ControlsContainer.Clear();
m_CurrentControls.Clear();
m_ControlViews.Clear();
UpdatePreviewTexture(null);
return;
}

UpdatePreviewTexture(nodePresenter.node.previewExpanded ? nodePresenter.previewTexture : null);
m_NodeGuid = nodePresenter.node.guid;
if (GetPresenter<MaterialNodePresenter>().node is PreviewNode)
{
if (!m_ResizeHandleAdded)

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls.meta


fileFormatVersion: 2
guid: 29309be0e1004fad967256187775c528
timeCreated: 1507642261

42
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Gradient.ShaderGraph
文件差异内容过多而无法显示
查看文件

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Gradient.ShaderGraph.meta


fileFormatVersion: 2
guid: 090ac3a2dd039884ba2dfa3b2ca34452
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

53
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ColorControl.cs


using System;
using System.Reflection;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Experimental.UIElements.StyleSheets;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
public class ColorControlAttribute : Attribute, IControlAttribute
{
string m_Label;
public ColorControlAttribute(string label = null)
{
m_Label = label;
}
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new ColorControlView(m_Label, node, propertyInfo);
}
}
public class ColorControlView : VisualElement
{
GUIContent m_Label;
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
public ColorControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
m_Node = node;
m_PropertyInfo = propertyInfo;
if (propertyInfo.PropertyType != typeof(Color))
throw new ArgumentException("Property must be of type Color.", "propertyInfo");
m_Label = new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name));
Add(new IMGUIContainer(OnGUIHandler));
}
void OnGUIHandler()
{
var value = (Color) m_PropertyInfo.GetValue(m_Node, null);
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{
value = EditorGUILayout.ColorField(m_Label, value);
if (changeCheckScope.changed)
m_PropertyInfo.SetValue(m_Node, value, null);
}
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ColorControl.cs.meta


fileFormatVersion: 2
guid: 34e77444559b414f9fe81f9775229abf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/DefaultControl.cs.meta


fileFormatVersion: 2
guid: 20e01cb163f347c7819ae286c33baf85
timeCreated: 1507642280

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/IControlAttribute.cs


using System.Reflection;
using UnityEngine.Experimental.UIElements;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing.Controls
{
public interface IControlAttribute
{
VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo);
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/IControlAttribute.cs.meta


fileFormatVersion: 2
guid: 5f008211c3394775bdefde0b20e5c8ff
timeCreated: 1507642348

165
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/VectorControl.cs


using System;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
public class MultiFloatControlAttribute : Attribute, IControlAttribute
{
string m_Label;
string m_SubLabel1;
string m_SubLabel2;
string m_SubLabel3;
string m_SubLabel4;
public MultiFloatControlAttribute(string label = null, string subLabel1 = "X", string subLabel2 = "Y", string subLabel3 = "Z", string subLabel4 = "W")
{
m_SubLabel1 = subLabel1;
m_SubLabel2 = subLabel2;
m_SubLabel3 = subLabel3;
m_SubLabel4 = subLabel4;
m_Label = label;
}
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
if (!MultiFloatControlView.validTypes.Contains(propertyInfo.PropertyType))
return null;
return new MultiFloatControlView(m_Label, m_SubLabel1, m_SubLabel2, m_SubLabel3, m_SubLabel4, node, propertyInfo);
}
}
public class MultiFloatControlView : VisualElement
{
public static Type[] validTypes = { typeof(float), typeof(Vector2), typeof(Vector3), typeof(Vector4) };
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
float[] m_Values;
GUIContent[] m_Labels;
GUIContent m_Label;
float m_Height;
Action m_Read;
Action m_Write;
public MultiFloatControlView(string label, string subLabel1, string subLabel2, string subLabel3, string subLabel4, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
int components;
SerializedPropertyType serializedPropertyType;
if (propertyInfo.PropertyType == typeof(float))
{
components = 1;
serializedPropertyType = SerializedPropertyType.Float;
m_Read = ReadFloat;
m_Write = WriteFloat;
}
else if (propertyInfo.PropertyType == typeof(Vector2))
{
components = 2;
serializedPropertyType = SerializedPropertyType.Vector2;
m_Read = ReadVector2;
m_Write = WriteVector2;
}
else if (propertyInfo.PropertyType == typeof(Vector3))
{
components = 3;
serializedPropertyType = SerializedPropertyType.Vector3;
m_Read = ReadVector3;
m_Write = WriteVector3;
}
else if (propertyInfo.PropertyType == typeof(Vector4))
{
components = 4;
serializedPropertyType = SerializedPropertyType.Vector4;
m_Read = ReadVector4;
m_Write = WriteVector4;
}
else
{
throw new ArgumentException("Property must be of type float, Vector2, Vector3 or Vector4.", "propertyInfo");
}
m_Label = new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name));
m_Node = node;
m_PropertyInfo = propertyInfo;
m_Values = new float[components];
m_Labels = new GUIContent[components];
m_Labels[0] = new GUIContent(subLabel1);
if (components > 1)
m_Labels[1] = new GUIContent(subLabel2);
if (components > 2)
m_Labels[2] = new GUIContent(subLabel3);
if (components > 3)
m_Labels[3] = new GUIContent(subLabel4);
m_Height = EditorGUI.GetPropertyHeight(serializedPropertyType, m_Label);
Add(new IMGUIContainer(OnGUIHandler));
}
void ReadFloat()
{
var value = (float)m_PropertyInfo.GetValue(m_Node, null);
m_Values[0] = value;
}
void ReadVector2()
{
var value = (Vector2)m_PropertyInfo.GetValue(m_Node, null);
m_Values[0] = value.x;
m_Values[1] = value.y;
}
void ReadVector3()
{
var value = (Vector3)m_PropertyInfo.GetValue(m_Node, null);
m_Values[0] = value.x;
m_Values[1] = value.y;
m_Values[2] = value.z;
}
void ReadVector4()
{
var value = (Vector4)m_PropertyInfo.GetValue(m_Node, null);
m_Values[0] = value.x;
m_Values[1] = value.y;
m_Values[2] = value.z;
m_Values[3] = value.w;
}
void WriteFloat()
{
m_PropertyInfo.SetValue(m_Node, m_Values[0], null);
}
void WriteVector2()
{
m_PropertyInfo.SetValue(m_Node, new Vector2(m_Values[0], m_Values[1]), null);
}
void WriteVector3()
{
m_PropertyInfo.SetValue(m_Node, new Vector3(m_Values[0], m_Values[1], m_Values[2]), null);
}
void WriteVector4()
{
m_PropertyInfo.SetValue(m_Node, new Vector4(m_Values[0], m_Values[1], m_Values[2], m_Values[3]), null);
}
void OnGUIHandler()
{
m_Read();
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{
var position = EditorGUILayout.GetControlRect(true, m_Height, EditorStyles.numberField);
EditorGUI.MultiFloatField(position, m_Label, m_Labels, m_Values);
if (changeCheckScope.changed)
m_Write();
}
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/VectorControl.cs.meta


fileFormatVersion: 2
guid: 8a515dc1bacc453b870777d8da9a7211
timeCreated: 1507642288

52
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumControl.cs


using System;
using System.Reflection;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
public class EnumControlAttribute : Attribute, IControlAttribute
{
string m_Label;
public EnumControlAttribute(string label = null)
{
m_Label = label;
}
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new EnumControlView(m_Label, node, propertyInfo);
}
}
public class EnumControlView : VisualElement
{
GUIContent m_Label;
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
public EnumControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
m_Node = node;
m_PropertyInfo = propertyInfo;
if (!propertyInfo.PropertyType.IsEnum)
throw new ArgumentException("Property must be an enum.", "propertyInfo");
m_Label = new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name));
Add(new IMGUIContainer(OnGUIHandler));
}
void OnGUIHandler()
{
var value = (Enum) m_PropertyInfo.GetValue(m_Node, null);
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{
value = EditorGUILayout.EnumPopup(m_Label, value);
if (changeCheckScope.changed)
m_PropertyInfo.SetValue(m_Node, value, null);
}
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumControl.cs.meta


fileFormatVersion: 2
guid: 3a1e13c5e67541d7ad7ae18ea5a834e4
timeCreated: 1507817885

44
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/PropertyControl.cs


using System;
using System.Linq;
using System.Reflection;
using UnityEngine.Experimental.UIElements;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
public class PropertyControlAttribute : Attribute, IControlAttribute
{
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new PropertyControlView(node);
}
}
public class PropertyControlView : VisualElement
{
PropertyNode m_Node;
public PropertyControlView(AbstractMaterialNode node)
{
m_Node = (PropertyNode) node;
Add(new IMGUIContainer(OnGUIHandler));
}
void OnGUIHandler()
{
var graph = m_Node.owner as AbstractMaterialGraph;
var currentGUID = m_Node.propertyGuid;
var properties = graph.properties.ToList();
var propertiesGUID = properties.Select(x => x.guid).ToList();
var currentSelectedIndex = propertiesGUID.IndexOf(currentGUID);
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{
var value = EditorGUILayout.Popup("Property", currentSelectedIndex, properties.Select(x => x.displayName).ToArray());
if (changeCheckScope.changed)
m_Node.propertyGuid = propertiesGUID[value];
}
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/PropertyControl.cs.meta


fileFormatVersion: 2
guid: bb1167be0ec94c0a849394d34df45a98
timeCreated: 1507819549

89
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/GradientControl.cs


using System;
using System.Reflection;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
public class GradientControlAttribute : Attribute, IControlAttribute
{
string m_Label;
public GradientControlAttribute(string label = null)
{
m_Label = label;
}
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new GradientControlView(m_Label, node, propertyInfo);
}
}
[Serializable]
public class GradientObject : ScriptableObject
{
public Gradient gradient = new Gradient();
}
public class GradientControlView : VisualElement
{
GUIContent m_Label;
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
string m_PrevWindow = "";
[SerializeField]
GradientObject m_GradientObject;
[SerializeField]
SerializedObject m_SerializedObject;
[SerializeField]
SerializedProperty m_SerializedProperty;
public GradientControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
m_Label = new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name));
m_Node = node;
m_PropertyInfo = propertyInfo;
if (propertyInfo.PropertyType != typeof(Gradient))
throw new ArgumentException("Property must be of type Gradient.", "propertyInfo");
m_GradientObject = ScriptableObject.CreateInstance<GradientObject>();
m_GradientObject.gradient = new Gradient();
m_SerializedObject = new SerializedObject(m_GradientObject);
m_SerializedProperty = m_SerializedObject.FindProperty("gradient");
Add(new IMGUIContainer(OnGUIHandler));
}
void OnGUIHandler()
{
m_SerializedObject.Update();
var gradient = (Gradient)m_PropertyInfo.GetValue(m_Node, null);
m_GradientObject.gradient.SetKeys(gradient.colorKeys, gradient.alphaKeys);
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{
EditorGUILayout.PropertyField(m_SerializedProperty, m_Label, true, null);
m_SerializedObject.ApplyModifiedProperties();
if (changeCheckScope.changed)
m_PropertyInfo.SetValue(m_Node, m_GradientObject.gradient, null);
}
var e = Event.current;
if (EditorWindow.focusedWindow != null && m_PrevWindow != EditorWindow.focusedWindow.ToString() && EditorWindow.focusedWindow.ToString() != "(UnityEditor.GradientPicker)")
{
m_PropertyInfo.SetValue(m_Node, m_GradientObject.gradient, null);
m_PrevWindow = EditorWindow.focusedWindow.ToString();
Debug.Log("Update Gradient Shader");
}
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/GradientControl.cs.meta


fileFormatVersion: 2
guid: 41930fdac13e47db8faedb82e6411a4f
timeCreated: 1507882043

53
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ObjectControl.cs


using System;
using System.Reflection;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.MaterialGraph;
using Object = UnityEngine.Object;
namespace UnityEditor.MaterialGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
public class ObjectControlAttribute : Attribute, IControlAttribute
{
string m_Label;
public ObjectControlAttribute(string label = null)
{
m_Label = label;
}
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new ObjectControlView(m_Label, node, propertyInfo);
}
}
public class ObjectControlView : VisualElement
{
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
GUIContent m_Label;
public ObjectControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
if (!typeof(Object).IsAssignableFrom(propertyInfo.PropertyType))
throw new ArgumentException("Property must be assignable to UnityEngine.Object.");
m_Node = node;
m_PropertyInfo = propertyInfo;
m_Label = new GUIContent(label ?? propertyInfo.Name);
Add(new IMGUIContainer(OnGUIHandler));
}
void OnGUIHandler()
{
var value = (Object) m_PropertyInfo.GetValue(m_Node, null);
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{
value = EditorGUILayout.MiniThumbnailObjectField(m_Label, value, m_PropertyInfo.PropertyType);
if (changeCheckScope.changed)
m_PropertyInfo.SetValue(m_Node, value, null);
}
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ObjectControl.cs.meta


fileFormatVersion: 2
guid: 3f483132ae7b4689b20fd6b8c59633b5
timeCreated: 1507900115

29
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/DefaultControl.cs


using System;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.MaterialGraph;
using Object = UnityEngine.Object;
namespace UnityEditor.MaterialGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
public class DefaultControlAttribute : Attribute, IControlAttribute
{
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
if (propertyInfo.PropertyType == typeof(Color))
return new ColorControlView(null, node, propertyInfo);
if (typeof(Enum).IsAssignableFrom(propertyInfo.PropertyType))
return new EnumControlView(null, node, propertyInfo);
if (propertyInfo.PropertyType == typeof(Gradient))
return new GradientControlView(null, node, propertyInfo);
if (MultiFloatControlView.validTypes.Contains(propertyInfo.PropertyType))
return new MultiFloatControlView(null, "X", "Y", "Z", "W", node, propertyInfo);
if (typeof(Object).IsAssignableFrom(propertyInfo.PropertyType))
return new ObjectControlView(null, node, propertyInfo);
return null;
}
}
}

12
MaterialGraphProject/Assets/NewNodes/Editor/ConstantsNodePresenter.cs.meta


fileFormatVersion: 2
guid: 68be9386ef4794d49967bf453668964e
timeCreated: 1495448531
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
MaterialGraphProject/Assets/NewNodes/Editor/BlendModeNodePresenter.cs.meta


fileFormatVersion: 2
guid: cebc29fc489af774fbf2b756ba815122
timeCreated: 1495456482
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
MaterialGraphProject/Assets/NewNodes/Editor/ToggleNodePresenter.cs.meta


fileFormatVersion: 2
guid: 55391b421fcbe4e60bf16325132025ff
timeCreated: 1495456482
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
MaterialGraphProject/Assets/NewNodes/Editor/TransformNodePresenter.cs.meta


fileFormatVersion: 2
guid: 01ea0408c41734e0b8b28e0983f7a700
timeCreated: 1476732809
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

43
MaterialGraphProject/Assets/NewNodes/Editor/BlendModeNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class BlendModeNodeControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as BlendModeNode;
if (cNode == null)
return;
cNode.blendMode = (BlendModesEnum)EditorGUILayout.EnumPopup("", cNode.blendMode);
}
/* public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
}
*/
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class BlendModeNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<BlendModeNodeControlPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
}

49
MaterialGraphProject/Assets/NewNodes/Editor/ConstantsNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEngine.MaterialGraph;
using UnityEditor.Experimental.UIElements.GraphView;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class ConstantsContolPresenter : GraphControlPresenter
{
private string[] m_ConstantTypeNames;
private string[] constantTypeNames
{
get
{
if (m_ConstantTypeNames == null)
m_ConstantTypeNames = Enum.GetNames(typeof(ConstantType));
return m_ConstantTypeNames;
}
}
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as UnityEngine.MaterialGraph.ConstantsNode;
if (cNode == null)
return;
cNode.constant = (ConstantType)EditorGUILayout.Popup((int)cNode.constant, constantTypeNames, EditorStyles.popup);
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class ConstantsNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<ConstantsContolPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
}

41
MaterialGraphProject/Assets/NewNodes/Editor/TransformNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine.MaterialGraph;
using UnityEngine;
namespace UnityEditor.MaterialGraph.Drawing
{
class TransformControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as TransformNode;
if (tNode == null)
return;
//EditorGUILayout.BeginHorizontal ();
tNode.spaceFrom = (SimpleMatrixType)EditorGUILayout.EnumPopup("From", tNode.spaceFrom);
tNode.spaceTo = (SimpleMatrixType)EditorGUILayout.EnumPopup("To", tNode.spaceTo);
//EditorGUILayout.BeginHorizontal ();
}
public override float GetHeight()
{
return (EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class TransformNodePresenter : PropertyNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<TransformControlPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter>(base.GetControlData()) { instance };
}
}
}

45
MaterialGraphProject/Assets/NewNodes/Editor/ToggleNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
/* [Serializable]
class ToggleNodeControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as ToggleNode;
if (cNode == null)
return;
cNode.value = EditorGUILayout.Toggle(cNode.value);
cNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), cNode.exposedState);
}
/* public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
}
*
public override float GetHeight()
{
return 2 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class ToggleNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<ToggleNodeControlPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}*/
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs.meta


fileFormatVersion: 2
guid: eaa1f14b82a26aa49b8a51ce08653c87
timeCreated: 1477985625
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

49
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
public class PropertyControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as PropertyNode;
if (tNode == null)
return;
var graph = node.owner as AbstractMaterialGraph;
var currentGUID = tNode.propertyGuid;
var properties = graph.properties.ToList();
var propertiesGUID = properties.Select(x => x.guid).ToList();
var currentSelectedIndex = propertiesGUID.IndexOf(currentGUID);
var newIndex = EditorGUILayout.Popup("Property", currentSelectedIndex, properties.Select(x => x.displayName).ToArray());
if (newIndex != currentSelectedIndex)
tNode.propertyGuid = propertiesGUID[newIndex];
}
public override float GetHeight()
{
return (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) * 2 + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class PropertyNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<PropertyControlPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes.meta


fileFormatVersion: 2
guid: 7e4695133ddd49cf97b1629ca5537e5b
timeCreated: 1502981029
正在加载...
取消
保存