Configures how the Inspector presents a serialized Dictionary<TKey, TValue> field: its column layout, the key and value header labels, and the initial key-column width.
By default, the Inspector draws a serialized Dictionary<TKey, TValue> field as two columns with the headers Key and Value, and the key column takes up half of the available width. Apply DictionaryDisplay to a dictionary field to change the layout, override one or both header labels, or set the initial key-column width.
This attribute targets fields. It only takes effect when the field is a serialized dictionary that the built-in dictionary drawer renders in the Inspector.
Every setting is an optional named property:
NaN is treated as 0.5.The layout, labels, and key-column fraction only set the initial presentation. After the user changes the layout from the header context menu or drags the column divider, Unity persists their choice and ignores the attribute on subsequent draws. To return to the attribute's values, the user selects Reset to Defaults from the header context menu.
To configure a dictionary that has no field to decorate, such as the inner dictionary of a Dictionary<int, Dictionary<string, float>> or a third-party dictionary type, use DictionaryDisplayForTypeAttribute at assembly level instead.
using System.Collections.Generic; using UnityEngine;
public class LootTable : MonoBehaviour { // Replace the default "Key" and "Value" column headers, and start with a wider key column. [DictionaryDisplay(keyLabel = "Item", valueLabel = "Drop chance", keyColumnFraction = 0.6f)] [SerializeField] private Dictionary<string, float> drops = new Dictionary<string, float>();
// Stack each value under its key in a single column, and keep every value visible. [DictionaryDisplay(layout = DictionaryLayout.OneColumnWithValueVisible, keyLabel = "Name", valueLabel = "Item")] [SerializeField] private Dictionary<int, GameObject> rewards = new Dictionary<int, GameObject>(); }
| Property | Description |
|---|---|
| keyColumnFraction | The initial width of the key column, as a fraction of the total dictionary width. Clamped to the range [0.01, 0.99]. |
| keyLabel | The text displayed above the key column. |
| layout | The column layout the Inspector uses to present the dictionary. |
| valueLabel | The text displayed above the value column. |