static SerializedDictionaryDrawer()
        {
            storage = new DrawerDataStorage <ReorderableListBase, CreationArgs>(false, (p, a) =>
            {
                var pairsProperty = a.pairsProperty;
                var errorProperty = a.errorProperty;

                var list = new ToolboxEditorList(pairsProperty, "Pair", true, true, false);
                list.drawHeaderCallback += (rect) =>
                {
                    //cache preprocessed label to get prefab related functions
                    var label = EditorGUI.BeginProperty(rect, null, p);
                    //create additional warning message if there is key collision
                    if (errorProperty.boolValue)
                    {
                        label.image = EditorGuiUtility.GetHelpIcon(MessageType.Warning);
                        label.text += string.Format(" [{0}]", Style.warningMessage);
                    }
                    EditorGUI.LabelField(rect, label);
                    EditorGUI.EndProperty();
                };
                list.drawFooterCallback += (rect) =>
                {
                    list.DrawStandardFooter(rect);
                };
                list.drawElementCallback += (rect, index, isActive, isFocused) =>
                {
                    list.DrawStandardElement(rect, index, isActive, isFocused, true);
                };
                return(list);
            });
        }
Beispiel #2
0
        /// <summary>
        /// Draws provided property as a warning label.
        /// </summary>
        public static void DrawEmptyProperty(Rect position, SerializedProperty property, GUIContent label)
        {
            label = label ?? new GUIContent(property.displayName);
#if UNITY_2019_1_OR_NEWER
            label.image = EditorGuiUtility.GetHelpIcon(MessageType.Warning);
#endif
            EditorGUI.LabelField(position, label);
        }
Beispiel #3
0
        protected virtual void DrawInvalidDrawerLabel(Rect position, string label)
        {
            var content = new GUIContent(label);

#if UNITY_2019_1_OR_NEWER
            content.image = EditorGuiUtility.GetHelpIcon(MessageType.Warning);
#endif
            EditorGUI.LabelField(position, content);
        }
Beispiel #4
0
        static SerializedDictionaryDrawer()
        {
            storage = new DrawerDataStorage <ReorderableListBase, CreationArgs>(false, (p, a) =>
            {
                var pairsProperty = a.pairsProperty;
                var errorProperty = a.errorProperty;

                var list = new ToolboxEditorList(pairsProperty, "Pair", true, true, false);
                list.drawHeaderCallback += (rect) =>
                {
                    //cache preprocessed label to get prefab related functions
                    var label = EditorGUI.BeginProperty(rect, null, p);
                    //create additional warning message if there is key collision
                    if (errorProperty.boolValue)
                    {
                        label.image = EditorGuiUtility.GetHelpIcon(MessageType.Warning);
                        label.text += string.Format(" [{0}]", Style.warningMessage);
                    }
                    EditorGUI.LabelField(rect, label);
                    EditorGUI.EndProperty();
                };
                list.drawFooterCallback += (rect) =>
                {
                    list.DrawStandardFooter(rect);
                };
                list.drawElementCallback += (rect, index, isActive, isFocused) =>
                {
                    var element = pairsProperty.GetArrayElementAtIndex(index);
                    var content = list.GetElementContent(element, index);

                    using (var propertyScope = new PropertyScope(element, content))
                    {
                        if (!propertyScope.IsVisible)
                        {
                            return;
                        }

                        //draw key/value children and use new, shortened labels
                        EditorGUI.indentLevel++;
                        EditorGUILayout.PropertyField(element.FindPropertyRelative("key"), new GUIContent("K"));
                        EditorGUILayout.PropertyField(element.FindPropertyRelative("value"), new GUIContent("V"));
                        EditorGUI.indentLevel--;
                    }
                };
                return(list);
            });
        }