コード例 #1
0
 private Rect GetDisplayRect()
 {
     return(baseAttribute.buttonLocation == BoolAsButtonAttribute.ButtonLocation.Label
                                 ? EditorGUIHelper.GetLabelRect(0)
                         : baseAttribute.buttonLocation == BoolAsButtonAttribute.ButtonLocation.Field || baseAttribute.buttonLocation == BoolAsButtonAttribute.ButtonLocation.FieldWithLabel
                                 ? EditorGUIHelper.GetFieldRect(0)
                                 : EditorGUIHelper.GetLineRect(0));
 }
コード例 #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUIHelper.UpdateRectData(position);

            EditorGUI.LabelField(EditorGUIHelper.GetLabelRect(0), label);

            Rect rect = GetContentRect(0, label);
            Type type = GetEnumType();

            if (!type.IsEnum)
            {
                Rect fieldRect = rect;
                fieldRect.height = EditorGUIHelper.GetPropertyHeight(2);

                EditorGUI.HelpBox(fieldRect, "EnumFlags attribute must be used on an enum.", MessageType.Error);
            }
            else
            {
                EditorGUIHelper.EnumMaskPopup(type, rect, property, options);
            }
        }
コード例 #3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            bool enabledPrior = GUI.enabled;

            EditorGUIHelper.UpdateRectData(position);

            //	Display additional label for FieldWithLabel
            if (baseAttribute.buttonLocation == BoolAsButtonAttribute.ButtonLocation.FieldWithLabel)
            {
                EditorGUI.LabelField(EditorGUIHelper.GetLabelRect(0), label);
            }

            //	Verify that property type is bool
            if (isWrongType(property))
            {
                Rect helpRect = EditorGUIHelper.GetFieldRect(0);
                helpRect.height = EditorGUIHelper.GetPropertyHeight(2);

                EditorGUI.PrefixLabel(EditorGUIHelper.GetLineRect(0), label);
                EditorGUI.HelpBox(helpRect, "BoolAsButton Attribute can only be used on Booleans. (" + property.name + ")", MessageType.Error);
                return;
            }

            //	Layout settings, in regards to multi-object selections
            Rect     displayPos  = GetDisplayRect();
            bool?    selection   = GetSelection(property);
            GUIStyle buttonStyle = GetButtonStyle(selection);
            string   labelText   = GetLabelText(selection, label);

            //	Display toggle and label overlaying the toggle
            EditorGUI.BeginChangeCheck();
            boolValue = EditorGUI.Toggle(displayPos, property.boolValue, buttonStyle);
            if (EditorGUI.EndChangeCheck())
            {
                if (!String.IsNullOrEmpty(baseAttribute.onPress))
                {
                    switch (baseAttribute.boolStyle)
                    {
                    case BoolAsButtonAttribute.BoolStyle.Button:
                        foreach (SerializedProperty prop in EditorGUIHelper.Multiple(property))
                        {
                            SerializedPropertyUtility.InvokeMethod(prop, baseAttribute.onPress);

                            //	Buttons get turned off immediately
                            prop.boolValue = false;
                        }
                        break;

                    case BoolAsButtonAttribute.BoolStyle.Toggleable:
                        foreach (SerializedProperty prop in EditorGUIHelper.Multiple(property))
                        {
                            //	Update value for use in the method
                            prop.boolValue = boolValue;
                            prop.serializedObject.ApplyModifiedProperties();

                            SerializedPropertyUtility.InvokeMethod(prop, baseAttribute.onPress);
                        }
                        break;
                    }
                }
                else
                {
                    property.boolValue = boolValue;
                }
            }

            //	Draw the button label on top of the button
            EditorGUI.LabelField(displayPos, new GUIContent(labelText, baseAttribute.tooltip), EditorGUIHelper.LabelCenteredStyle);

            GUI.enabled = enabledPrior;
        }
コード例 #4
0
 public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
 {
     return(EditorGUIHelper.GetPropertyHeight(isWrongType(property) ? 2 : 1));
 }
コード例 #5
0
 /// <summary>
 ///		Gets a content Rect appropriate, based on the presence of a label.
 ///		If no label, returns a full LineRect.  Otherwise, returns a FieldRect.
 /// </summary>
 /// <param name="line"></param>
 /// <param name="label"></param>
 /// <returns></returns>
 public static Rect GetContentRect(int line, GUIContent label)
 {
     return(HasLabel(label)
                         ? EditorGUIHelper.GetFieldRect(line)
                         : EditorGUIHelper.GetLineRect(line, false));
 }
コード例 #6
0
 public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
 {
     //	Two lines tall for error message
     return(EditorGUIHelper.GetPropertyHeight(fieldInfo.FieldType.IsEnum ? 1 : 2));
 }