Matt Dean
7 年前
当前提交
13948f2d
共有 5 个文件被更改,包括 187 次插入 和 1 次删除
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ColorMaskNode.cs
-
107MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ChannelMaskNode.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ChannelMaskNode.cs.meta
-
65MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelEnumControl.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelEnumControl.cs.meta
|
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
public enum TextureChannel |
|||
{ |
|||
Red, |
|||
Green, |
|||
Blue, |
|||
Alpha |
|||
} |
|||
|
|||
[Title("Artistic/Mask/Channel Mask")] |
|||
public class ChannelMaskNode : CodeFunctionNode |
|||
{ |
|||
public ChannelMaskNode() |
|||
{ |
|||
name = "Channel Mask"; |
|||
} |
|||
|
|||
[SerializeField] |
|||
private TextureChannel m_Channel = TextureChannel.Red; |
|||
|
|||
[ChannelEnumControl("Channel")] |
|||
public TextureChannel channel |
|||
{ |
|||
get { return m_Channel; } |
|||
set |
|||
{ |
|||
if (m_Channel == value) |
|||
return; |
|||
|
|||
m_Channel = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
switch (m_Channel) |
|||
{ |
|||
case TextureChannel.Green: |
|||
return GetType().GetMethod("Unity_ChannelMask_Green", BindingFlags.Static | BindingFlags.NonPublic); |
|||
case TextureChannel.Blue: |
|||
return GetType().GetMethod("Unity_ChannelMask_Blue", BindingFlags.Static | BindingFlags.NonPublic); |
|||
case TextureChannel.Alpha: |
|||
return GetType().GetMethod("Unity_ChannelMask_Alpha", BindingFlags.Static | BindingFlags.NonPublic); |
|||
default: |
|||
return GetType().GetMethod("Unity_ChannelMask_Red", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
} |
|||
|
|||
static string Unity_ChannelMask_Red( |
|||
[Slot(0, Binding.None)] DynamicDimensionVector In, |
|||
[Slot(1, Binding.None)] out Vector4 Out) |
|||
{ |
|||
Out = Vector4.zero; |
|||
return |
|||
@"
|
|||
{ |
|||
Out = In.xxxx; |
|||
}";
|
|||
} |
|||
|
|||
static string Unity_ChannelMask_Green( |
|||
[Slot(0, Binding.None)] DynamicDimensionVector In, |
|||
[Slot(1, Binding.None)] out Vector4 Out) |
|||
{ |
|||
Out = Vector4.zero; |
|||
return |
|||
@"
|
|||
{ |
|||
Out = In.yyyy; |
|||
}";
|
|||
} |
|||
|
|||
static string Unity_ChannelMask_Blue( |
|||
[Slot(0, Binding.None)] DynamicDimensionVector In, |
|||
[Slot(1, Binding.None)] out Vector4 Out) |
|||
{ |
|||
Out = Vector4.zero; |
|||
return |
|||
@"
|
|||
{ |
|||
Out = In.zzzz; |
|||
}";
|
|||
} |
|||
|
|||
static string Unity_ChannelMask_Alpha( |
|||
[Slot(0, Binding.None)] DynamicDimensionVector In, |
|||
[Slot(1, Binding.None)] out Vector4 Out) |
|||
{ |
|||
Out = Vector4.zero; |
|||
return |
|||
@"
|
|||
{ |
|||
Out = In.wwww; |
|||
}";
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e3fd76d77a796b641ba3e9149086efc2 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Controls |
|||
{ |
|||
[AttributeUsage(AttributeTargets.Property)] |
|||
public class ChannelEnumControlAttribute : Attribute, IControlAttribute |
|||
{ |
|||
string m_Label; |
|||
|
|||
public ChannelEnumControlAttribute(string label = null) |
|||
{ |
|||
m_Label = label; |
|||
} |
|||
|
|||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
return new ChannelEnumControlView(m_Label, node, propertyInfo); |
|||
} |
|||
} |
|||
|
|||
public class ChannelEnumControlView : VisualElement |
|||
{ |
|||
GUIContent m_Label; |
|||
AbstractMaterialNode m_Node; |
|||
PropertyInfo m_PropertyInfo; |
|||
|
|||
string[] popupEntries; |
|||
|
|||
public ChannelEnumControlView(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 entries = (Enum) m_PropertyInfo.GetValue(m_Node, null); |
|||
var value = (int)m_PropertyInfo.GetValue(m_Node, null); |
|||
|
|||
using (var changeCheckScope = new EditorGUI.ChangeCheckScope()) |
|||
{ |
|||
int count = (int)SlotValueHelper.GetChannelCount(m_Node.FindSlot<MaterialSlot>(0).concreteValueType); |
|||
popupEntries = new string[count]; |
|||
|
|||
string[] enumNames = Enum.GetNames(entries.GetType()); |
|||
for (int i = 0; i < popupEntries.Length; i++) |
|||
popupEntries[i] = enumNames[i]; |
|||
value = EditorGUILayout.Popup(m_Label, value, popupEntries); |
|||
|
|||
if (changeCheckScope.changed) |
|||
{ |
|||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name); |
|||
m_PropertyInfo.SetValue(m_Node, value, null); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 74fdde12d8253bd4c874acc555be0585 |
|||
timeCreated: 1507817885 |
撰写
预览
正在加载...
取消
保存
Reference in new issue