Matt Dean
7 年前
当前提交
5a69c812
共有 7 个文件被更改,包括 156 次插入 和 129 次删除
-
16MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Utility/ColorspaceConversion.cs
-
110MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/TransformNode.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
-
2MaterialGraphProject/Assets/UnityShaderEditor/package.json
-
81MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumConversionControl.cs
-
70MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ColorspaceConversionControl.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumConversionControl.cs.meta
|
|||
{ |
|||
"name": "com.unity.shadergraph", |
|||
"description": "Shader Graph", |
|||
"version": "0.1.3", |
|||
"version": "0.1.6", |
|||
"unity": "2018.1", |
|||
"dependencies": { |
|||
} |
|
|||
using System; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Controls |
|||
{ |
|||
public interface IEnumConversion |
|||
{ |
|||
Enum from { get; set; } |
|||
Enum to { get; set; } |
|||
} |
|||
|
|||
[AttributeUsage(AttributeTargets.Property)] |
|||
public class EnumConversionControlAttribute : Attribute, IControlAttribute |
|||
{ |
|||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
return new EnumConversionControlView(node, propertyInfo); |
|||
} |
|||
} |
|||
|
|||
public class EnumConversionControlView : VisualElement |
|||
{ |
|||
AbstractMaterialNode m_Node; |
|||
PropertyInfo m_PropertyInfo; |
|||
|
|||
IEnumConversion value |
|||
{ |
|||
get { return (IEnumConversion)m_PropertyInfo.GetValue(m_Node, null); } |
|||
set { m_PropertyInfo.SetValue(m_Node, value, null); } |
|||
} |
|||
|
|||
public EnumConversionControlView(AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
if (!propertyInfo.PropertyType.GetInterfaces().Any(t => t == typeof(IEnumConversion))) |
|||
throw new ArgumentException("Property type must implement IEnumConversion."); |
|||
|
|||
m_Node = node; |
|||
m_PropertyInfo = propertyInfo; |
|||
var currentValue = value; |
|||
|
|||
var ec = (IEnumConversion) propertyInfo.GetValue(m_Node, null); |
|||
propertyInfo.SetValue(m_Node, ec, null); |
|||
|
|||
var fromField = new EnumField(currentValue.from); |
|||
fromField.OnValueChanged(OnFromChanged); |
|||
Add(fromField); |
|||
|
|||
var arrowLabel = new Label("➔"); |
|||
Add(arrowLabel); |
|||
|
|||
var toField = new EnumField(currentValue.to); |
|||
toField.OnValueChanged(OnToChanged); |
|||
Add(toField); |
|||
} |
|||
|
|||
void OnFromChanged(ChangeEvent<Enum> evt) |
|||
{ |
|||
var currentValue = value; |
|||
if (!Equals(currentValue.from, evt.newValue)) |
|||
{ |
|||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change Colorspace From"); |
|||
currentValue.from = evt.newValue; |
|||
value = currentValue; |
|||
} |
|||
} |
|||
|
|||
void OnToChanged(ChangeEvent<Enum> evt) |
|||
{ |
|||
var currentValue = value; |
|||
if (!Equals(currentValue.to, evt.newValue)) |
|||
{ |
|||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change Colorspace To"); |
|||
currentValue.to = evt.newValue; |
|||
value = currentValue; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Reflection; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Controls |
|||
{ |
|||
[AttributeUsage(AttributeTargets.Property)] |
|||
public class ColorspaceConversionControlAttribute : Attribute, IControlAttribute |
|||
{ |
|||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
return new ColorspaceConversionControlView(node, propertyInfo); |
|||
} |
|||
} |
|||
|
|||
public class ColorspaceConversionControlView : VisualElement |
|||
{ |
|||
AbstractMaterialNode m_Node; |
|||
PropertyInfo m_PropertyInfo; |
|||
|
|||
ColorspaceConversion conversion |
|||
{ |
|||
get { return (ColorspaceConversion)m_PropertyInfo.GetValue(m_Node, null); } |
|||
set { m_PropertyInfo.SetValue(m_Node, value, null); } |
|||
} |
|||
|
|||
public ColorspaceConversionControlView(AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
m_Node = node; |
|||
m_PropertyInfo = propertyInfo; |
|||
var value = conversion; |
|||
|
|||
var fromField = new EnumField(value.from); |
|||
fromField.OnValueChanged(OnFromChanged); |
|||
Add(fromField); |
|||
|
|||
var arrowLabel = new Label("➔"); |
|||
Add(arrowLabel); |
|||
|
|||
var toField = new EnumField(value.to); |
|||
toField.OnValueChanged(OnToChanged); |
|||
Add(toField); |
|||
} |
|||
|
|||
void OnFromChanged(ChangeEvent<Enum> evt) |
|||
{ |
|||
var value = conversion; |
|||
var newValue = (Colorspace)evt.newValue; |
|||
if (value.from != newValue) |
|||
{ |
|||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change Colorspace From"); |
|||
value.from = newValue; |
|||
conversion = value; |
|||
} |
|||
} |
|||
|
|||
void OnToChanged(ChangeEvent<Enum> evt) |
|||
{ |
|||
var value = conversion; |
|||
var newValue = (Colorspace)evt.newValue; |
|||
if (value.to != newValue) |
|||
{ |
|||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change Colorspace To"); |
|||
value.to = newValue; |
|||
conversion = value; |
|||
} |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue