|
|
|
|
|
|
|
|
|
|
public class EnumControlView : VisualElement |
|
|
|
{ |
|
|
|
GUIContent m_Label; |
|
|
|
AbstractMaterialNode m_Node; |
|
|
|
PropertyInfo m_PropertyInfo; |
|
|
|
|
|
|
|
|
|
|
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 Label(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name))); |
|
|
|
var enumField = new EnumField((Enum) m_PropertyInfo.GetValue(m_Node, null)); |
|
|
|
enumField.OnValueChanged(OnValueChanged); |
|
|
|
|
|
|
void OnValueChanged(ChangeEvent<Enum> evt) |
|
|
|
{ |
|
|
|
var value = (Enum) m_PropertyInfo.GetValue(m_Node, null); |
|
|
|
if (evt.newValue.Equals(value)) |
|
|
|
if (!evt.newValue.Equals(value)) |
|
|
|
{ |
|
|
|
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name); |
|
|
|
m_PropertyInfo.SetValue(m_Node, evt.newValue, null); |
|
|
|