|
|
|
|
|
|
using System; |
|
|
|
using System.Reflection; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEditor.Graphing; |
|
|
|
using UnityEngine.Experimental.UIElements; |
|
|
|
|
|
|
|
namespace UnityEditor.ShaderGraph.Drawing.Controls |
|
|
|
|
|
|
{ |
|
|
|
string m_Label; |
|
|
|
int m_SlotId; |
|
|
|
public ChannelEnumControlAttribute(string label = null) |
|
|
|
public ChannelEnumControlAttribute(string label = null, int slotId = 0) |
|
|
|
m_SlotId = slotId; |
|
|
|
return new ChannelEnumControlView(m_Label, node, propertyInfo); |
|
|
|
return new ChannelEnumControlView(m_Label, m_SlotId, node, propertyInfo); |
|
|
|
public class ChannelEnumControlView : VisualElement |
|
|
|
public class ChannelEnumControlView : VisualElement, INodeModificationListener |
|
|
|
int m_SlotId; |
|
|
|
string[] popupEntries; |
|
|
|
|
|
|
|
public ChannelEnumControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo) |
|
|
|
public ChannelEnumControlView(string label, int slotId, AbstractMaterialNode node, PropertyInfo propertyInfo) |
|
|
|
m_SlotId = slotId; |
|
|
|
if (!propertyInfo.PropertyType.IsEnum) |
|
|
|
throw new ArgumentException("Property must be an enum.", "propertyInfo"); |
|
|
|
m_Label = new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name)); |
|
|
|
|
|
|
void OnGUIHandler() |
|
|
|
{ |
|
|
|
var entries = (Enum) m_PropertyInfo.GetValue(m_Node, null); |
|
|
|
var value = (int)m_PropertyInfo.GetValue(m_Node, null); |
|
|
|
UpdatePopup(); |
|
|
|
} |
|
|
|
|
|
|
|
public void OnNodeModified(ModificationScope scope) |
|
|
|
{ |
|
|
|
if(scope == ModificationScope.Graph) |
|
|
|
UpdatePopup(); |
|
|
|
} |
|
|
|
private void UpdatePopup() |
|
|
|
{ |
|
|
|
var value = (int)m_PropertyInfo.GetValue(m_Node, null); |
|
|
|
int count = (int)SlotValueHelper.GetChannelCount(m_Node.FindSlot<MaterialSlot>(0).concreteValueType); |
|
|
|
popupEntries = new string[count]; |
|
|
|
|
|
|
|
int count = (int)SlotValueHelper.GetChannelCount(m_Node.FindSlot<MaterialSlot>(m_SlotId).concreteValueType); |
|
|
|
if (value >= count) |
|
|
|
{ |
|
|
|
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name); |
|
|
|
m_PropertyInfo.SetValue(m_Node, 0, null); |
|
|
|
return; |
|
|
|
} |
|
|
|
var entries = (Enum)m_PropertyInfo.GetValue(m_Node, null); |
|
|
|
string[] popupEntries = new string[count]; |
|
|
|
|
|
|
|
if (changeCheckScope.changed) |
|
|
|
{ |
|
|
|
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name); |
|
|
|