コード例 #1
0
        public static void PropertyField_Layout(SerializedProperty property, bool includeChildren)
        {
            SpecialCaseDrawerAttribute specialCaseAttribute = PropertyUtility.GetAttribute <SpecialCaseDrawerAttribute>(property);

            if (specialCaseAttribute != null)
            {
                specialCaseAttribute.GetDrawer().OnGUI(property);
            }
            else
            {
                GUIContent label = new GUIContent(PropertyUtility.GetLabel(property));
                bool       anyDrawerAttribute = PropertyUtility.GetAttributes <DrawerAttribute>(property).Any();

                var style = new GUIStyle();
                style.normal.textColor = Color.white;
                style.fontStyle        = FontStyle.Bold;
                style.fontSize         = 13;
                style.contentOffset    = new Vector2(10, 0);
                if (!anyDrawerAttribute)
                {
                    // Drawer attributes check for visibility, enableability and validator themselves,
                    // so if a property doesn't have a DrawerAttribute we need to check for these explicitly

                    // Check if visible
                    bool visible = PropertyUtility.IsVisible(property);
                    if (!visible)
                    {
                        return;
                    }

                    // Validate
                    ValidatorAttribute[] validatorAttributes = PropertyUtility.GetAttributes <ValidatorAttribute>(property);
                    foreach (var validatorAttribute in validatorAttributes)
                    {
                        validatorAttribute.GetValidator().ValidateProperty(property);
                    }

                    // Check if enabled and draw
                    EditorGUI.BeginChangeCheck();
                    bool enabled = PropertyUtility.IsEnabled(property);
                    GUI.enabled = enabled;
                    //EditorGUILayout.BeginHorizontal();
                    //EditorGUILayout.LabelField(property.name, style , GUILayout.MinWidth(152));

                    EditorGUILayout.PropertyField(property, label, includeChildren);
                    //EditorGUILayout.EndHorizontal();
                    GUI.enabled = true;

                    // Call OnValueChanged callbacks
                    if (EditorGUI.EndChangeCheck())
                    {
                        PropertyUtility.CallOnValueChangedCallbacks(property);
                    }
                }
                else
                {
                    // We don't need to check for enableIfAttribute

                    //EditorGUILayout.BeginHorizontal();
                    //EditorGUILayout.LabelField(property.name, style , GUILayout.MinWidth(152));

                    EditorGUILayout.PropertyField(property, label, includeChildren);
                    //EditorGUILayout.EndHorizontal();
                }
            }
        }
コード例 #2
0
        protected void DrawSerializedProperties()
        {
            serializedObject.Update();

            // Draw non-grouped serialized properties
            foreach (var property in GetNonGroupedProperties(_serializedProperties))
            {
                if (property.name.Equals("m_Script", System.StringComparison.Ordinal))
                {
                    GUI.enabled = false;
                    EditorGUILayout.PropertyField(property);
                    GUI.enabled = true;
                }
                else
                {
                    NaughtyEditorGUI.PropertyField_Layout(property, true);
                }
            }

            // Draw grouped serialized properties
            foreach (var group in GetGroupedProperties(_serializedProperties))
            {
                IEnumerable <SerializedProperty> visibleProperties = group.Where(p => PropertyUtility.IsVisible(p));
                if (!visibleProperties.Any())
                {
                    continue;
                }

                EColor newColor = EColor.Gray;
                foreach (var property in visibleProperties)
                {
                    newColor = PropertyUtility.GetAttribute <BoxGroupAttribute>(property).myColor;
                    if (newColor != EColor.Gray)
                    {
                        break;
                    }
                }
                bool show = BeginBoxGroup_Layout(group.Key, newColor);
                if (show)
                {
                    foreach (var property in visibleProperties)
                    {
                        NaughtyEditorGUI.PropertyField_Layout(property, true);
                    }
                }

                NaughtyEditorGUI.EndBoxGroup_Layout();
            }

            serializedObject.ApplyModifiedProperties();
        }