public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // First get the attribute since it contains the range for the slider var ffeAttribute = attribute as FlagsFromEnumAttribute; EditorGUI.BeginProperty(position, label, property); if (property.propertyType != SerializedPropertyType.Integer) { EditorGUI.LabelField(position, label.text, "Use FlagFromEnum with integer."); } else if (ffeAttribute.EnumType == null || !ffeAttribute.EnumType.IsEnum) { EditorGUI.LabelField(position, label.text, "Set FlagFromEnum argument with enum type."); } else { position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(property.displayName)); var enumInfo = EnumUtils.GetDisplayInfo(ffeAttribute.EnumType); var realMask = property.intValue; var oldDisplayedMask = enumInfo.RealToDisplayedMaskField(realMask); var newDisplayedMask = EditorGUI.MaskField(position, oldDisplayedMask, enumInfo.displayedMaskNames); property.intValue = enumInfo.DisplayedToRealMaskField(newDisplayedMask, (uint)newDisplayedMask > (uint)oldDisplayedMask); } property.serializedObject.ApplyModifiedProperties(); EditorGUI.EndProperty(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // First get the attribute since it contains the range for the slider var attr = attribute as CustomOrderedEnumAttribute; EditorGUI.BeginProperty(position, label, property); position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(property.displayName)); // determine which enum type to display Type displayedEnumType = null; if (property.propertyType == SerializedPropertyType.Enum) { if (attr.overrideEnumType != null && attr.overrideEnumType.IsEnum) { displayedEnumType = attr.overrideEnumType; } else { displayedEnumType = fieldInfo.FieldType; } } else if (property.propertyType == SerializedPropertyType.Integer) { if (attr.overrideEnumType != null && attr.overrideEnumType.IsEnum) { displayedEnumType = attr.overrideEnumType; } } // display enum popup if displayedEnumType is determined, otherwise, display the default property field if (displayedEnumType == null) { EditorGUI.PropertyField(position, property); } else { var enumInfo = EnumUtils.GetDisplayInfo(displayedEnumType); var displayedNames = enumInfo.displayedNames; var displayedValues = enumInfo.displayedValues; if (!enumInfo.value2displayedIndex.ContainsKey(property.intValue)) { displayedNames = displayedNames.Concat(new string[] { property.intValue.ToString() }).ToArray(); displayedValues = displayedValues.Concat(new int[] { property.intValue }).ToArray(); } property.intValue = EditorGUI.IntPopup(position, property.intValue, displayedNames, displayedValues); } property.serializedObject.ApplyModifiedProperties(); EditorGUI.EndProperty(); }
private bool TryGetEnumInfo(out EnumUtils.EnumDisplayInfo info) { var ffeAttribute = attribute as FlagsFromEnumAttribute; if (ffeAttribute.EnumType == null || !ffeAttribute.EnumType.IsEnum) { info = null; return(false); } info = EnumUtils.GetDisplayInfo(ffeAttribute.EnumType); return(info != null); }