Ejemplo n.º 1
0
        public override void OnGUI(Rect position, UnityEditor.SerializedProperty property, GUIContent label)
        {
            InitializeKeycodeList();

            int     val        = property.hasMultipleDifferentValues ? int.MinValue : property.intValue;
            KeyCode keyCodeVal = (KeyCode)val;

            label = UnityEditor.EditorGUI.BeginProperty(position, label, property);
            EditorGUI.BeginChangeCheck();
            KeyCode newVal = ListGUI.Popup(position, label, keyCodeVal, s_KeyCodes);

            if (EditorGUI.EndChangeCheck() && newVal != keyCodeVal)
            {
                property.intValue = (int)newVal;
            }
            UnityEditor.EditorGUI.EndProperty();
        }
Ejemplo n.º 2
0
        public static Enum EnumField(Rect position, GUIContent label, Enum selected, GUIStyle style)
        {
            Type enumType = selected.GetType();

            EnumInfoCache.Info info = EnumInfoCache.Instance.GetInfo(enumType);
            if ((info.Flags & EnumInfoCache.TypeFlags.Flags) != 0)
            {
                int  mask     = info.MapToFlagInput(selected);
                int  nextMask = EditorGUI.MaskField(position, label, mask, info.FlagNames);
                Enum result   = info.MapFromFlagOutput(selected, mask, nextMask);
                return(result);
            }
            else if ((info.Flags & EnumInfoCache.TypeFlags.Labeled) != 0)
            {
                return(ListGUI.Popup(position, label, selected, info.LabeledList, style));
            }
            else
            {
                return(EditorGUI.EnumPopup(position, label, selected, style));
            }
        }