Configures how the Inspector presents a serialized Dictionary<TKey, TValue> identified by type, for dictionaries that have no field to decorate.
DictionaryDisplayForType is the assembly-level form of DictionaryDisplayAttribute. It has the same presentation settings: layout, keyLabel, valueLabel, and keyColumnFraction. The difference is that you name the dictionary to configure with a typeof argument instead of attaching the attribute to a field.
This attribute targets assemblies, so you apply it with an assembly-level attribute declaration. Use it to:
Dictionary<int, Dictionary<string, StatModifier>>.The targetType must be a fully specified Dictionary<TKey, TValue>, such as Dictionary<string, StatModifier>. The attribute applies to every dictionary of that exact type, wherever it appears, and sets the layout, labels, and key-column fraction. Unity ignores a target that isn't a fully specified dictionary type.
You can only declare a rule for a dictionary when the attribute's assembly defines the dictionary's key type, its value type, or a type nested inside either. For example, an assembly that defines StatModifier can target Dictionary<string, StatModifier>, Dictionary<int, StatModifier[]>, or Dictionary<int, List<StatModifier>>. This prevents a rule in one assembly from changing a dictionary built only from types it doesn't define, such as Dictionary<int, int>. If the target uses no type from the attribute's assembly, Unity ignores the rule and logs a warning in the console.
When more than one source can set a dictionary's presentation, Unity uses the first source that applies, from highest precedence to lowest:
DictionaryDisplayForType on the exact Dictionary<TKey, TValue> sets the layout, labels, and width.using System.Collections.Generic; using UnityEngine;
// One declaration configures every Dictionary<string, StatModifier> in the assembly: the nested // dictionary in Equipment and the field in Buff, without repeating [DictionaryDisplay]. This // assembly defines StatModifier, so the attribute is allowed to target this dictionary. [assembly: DictionaryDisplayForType(typeof(Dictionary<string, StatModifier>), layout = DictionaryLayout.OneColumnWithValueVisible, keyLabel = "Stat", valueLabel = "Modifier", keyColumnFraction = 0.4f)]
[System.Serializable] public struct StatModifier { public float amount; public bool isPercentage; }
public class Equipment : MonoBehaviour { // Nested inner dictionary: a value, so it has no field to decorate. [SerializeField] private Dictionary<int, Dictionary<string, StatModifier>> modifiersPerSlot = new(); }
public class Buff : MonoBehaviour { // A direct field of the same type, styled by the same declaration. [SerializeField] private Dictionary<string, StatModifier> statModifiers = new(); }
| Property | Description |
|---|---|
| targetType | The dictionary type this attribute configures. Must be a fully specified Dictionary<TKey, TValue>, for example Dictionary<string, StatModifier>. |
| Constructor | Description |
|---|---|
| DictionaryDisplayForTypeAttribute | Creates an attribute that configures the dictionary type identified by targetType. |
| 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. |