浏览代码
Merge branch 'attribute-controls'
Merge branch 'attribute-controls'
# Conflicts: # MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs/main
Peter Bay Bastian
7 年前
当前提交
9f5fba90
共有 54 个文件被更改,包括 1086 次插入 和 629 次删除
-
5MaterialGraphProject/Assets/NewNodes/Editor/Keep/BlendModeNode.cs
-
2MaterialGraphProject/Assets/NewNodes/Editor/Keep/ConstantsNode.cs
-
223MaterialGraphProject/Assets/NewNodes/Editor/Keep/GradientNode.cs
-
3MaterialGraphProject/Assets/NewNodes/Editor/Keep/SamplerStateNode.cs
-
3MaterialGraphProject/Assets/NewNodes/Editor/Keep/TransformNode.cs
-
28MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/ColorNode.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/UVNode.cs
-
46MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix2Node.cs
-
56MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix3Node.cs
-
62MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix4Node.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/MatrixCommonNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector1Node.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector2Node.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector3Node.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector4Node.cs
-
261MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Logic/IFNode.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/MasterRemapNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphNode.cs
-
39MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphOutputNode.cs
-
53MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
-
42MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls.meta
-
42MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Gradient.ShaderGraph
-
9MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Gradient.ShaderGraph.meta
-
53MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ColorControl.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ColorControl.cs.meta
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/DefaultControl.cs.meta
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/IControlAttribute.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/IControlAttribute.cs.meta
-
165MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/VectorControl.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/VectorControl.cs.meta
-
52MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumControl.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumControl.cs.meta
-
44MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/PropertyControl.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/PropertyControl.cs.meta
-
89MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/GradientControl.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/GradientControl.cs.meta
-
53MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ObjectControl.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ObjectControl.cs.meta
-
29MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/DefaultControl.cs
-
12MaterialGraphProject/Assets/NewNodes/Editor/ConstantsNodePresenter.cs.meta
-
12MaterialGraphProject/Assets/NewNodes/Editor/BlendModeNodePresenter.cs.meta
-
12MaterialGraphProject/Assets/NewNodes/Editor/ToggleNodePresenter.cs.meta
-
12MaterialGraphProject/Assets/NewNodes/Editor/TransformNodePresenter.cs.meta
-
43MaterialGraphProject/Assets/NewNodes/Editor/BlendModeNodePresenter.cs
-
49MaterialGraphProject/Assets/NewNodes/Editor/ConstantsNodePresenter.cs
-
41MaterialGraphProject/Assets/NewNodes/Editor/TransformNodePresenter.cs
-
45MaterialGraphProject/Assets/NewNodes/Editor/ToggleNodePresenter.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs.meta
-
49MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes.meta
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 29309be0e1004fad967256187775c528 |
|||
timeCreated: 1507642261 |
42
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Gradient.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 090ac3a2dd039884ba2dfa3b2ca34452 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 34e77444559b414f9fe81f9775229abf |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 20e01cb163f347c7819ae286c33baf85 |
|||
timeCreated: 1507642280 |
|
|||
using System.Reflection; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing.Controls |
|||
{ |
|||
public interface IControlAttribute |
|||
{ |
|||
VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5f008211c3394775bdefde0b20e5c8ff |
|||
timeCreated: 1507642348 |
|
|||
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(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8a515dc1bacc453b870777d8da9a7211 |
|||
timeCreated: 1507642288 |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3a1e13c5e67541d7ad7ae18ea5a834e4 |
|||
timeCreated: 1507817885 |
|
|||
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]; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: bb1167be0ec94c0a849394d34df45a98 |
|||
timeCreated: 1507819549 |
|
|||
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"); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 41930fdac13e47db8faedb82e6411a4f |
|||
timeCreated: 1507882043 |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3f483132ae7b4689b20fd6b8c59633b5 |
|||
timeCreated: 1507900115 |
|
|||
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; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 68be9386ef4794d49967bf453668964e |
|||
timeCreated: 1495448531 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: cebc29fc489af774fbf2b756ba815122 |
|||
timeCreated: 1495456482 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 55391b421fcbe4e60bf16325132025ff |
|||
timeCreated: 1495456482 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 01ea0408c41734e0b8b28e0983f7a700 |
|||
timeCreated: 1476732809 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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 }; |
|||
} |
|||
} |
|||
} |
|
|||
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 }; |
|||
} |
|||
} |
|||
} |
|
|||
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 }; |
|||
} |
|||
} |
|||
} |
|
|||
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 }; |
|||
} |
|||
}*/ |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: eaa1f14b82a26aa49b8a51ce08653c87 |
|||
timeCreated: 1477985625 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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 }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7e4695133ddd49cf97b1629ca5537e5b |
|||
timeCreated: 1502981029 |
撰写
预览
正在加载...
取消
保存
Reference in new issue