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);
            });
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
            });
        }