Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

DictionaryDisplayForTypeAttribute

class in UnityEngine

/

Inherits from:DictionaryDisplayAttribute

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

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. It's the only way to configure a dictionary that you can't attach a field attribute to, such as the inner dictionary of a Dictionary<int, Dictionary<string, float>> or a third-party dictionary type.

The targetType you pass determines which dictionaries the attribute matches and which settings apply:

  • A fully specified dictionary type, such as Dictionary<string, float>, matches that exact dictionary and applies the layout, labels, and key-column fraction.
  • A key or value element type matches any dictionary that uses that type as its key or value, and applies the layout only. Labels and the key-column fraction don't apply in this case, because they would otherwise affect every dictionary that uses that type.

When more than one source can set a dictionary's presentation, Unity uses the first source that applies, from highest precedence to lowest:

  1. The user's own choices: the layout from the header context menu and the column width from dragging the divider. These choices persist and override every attribute until the user selects Reset to Defaults.
  2. A field-level DictionaryDisplayAttribute on the dictionary field sets the layout, labels, and width.
  3. An assembly-level DictionaryDisplayForType on the exact Dictionary<TKey, TValue> sets the layout, labels, and width.
  4. An assembly-level DictionaryDisplayForType on the value type, then on the key type, sets the layout only.
  5. The built-in defaults: DictionaryLayout.TwoColumns layout, Key and Value labels, and a 0.5 key-column fraction.
using System.Collections.Generic;
using UnityEngine;

// Label and lay out the inner Dictionary<string, float> of a nested dictionary, // which has no field to decorate directly. [assembly: DictionaryDisplayForType(typeof(Dictionary<string, float>), layout = DictionaryLayout.OneColumnWithValueVisible, keyLabel = "Bone", valueLabel = "Weight", keyColumnFraction = 0.4f)]

public class Rig : MonoBehaviour { [SerializeField] private Dictionary<int, Dictionary<string, float>> boneWeightsPerLod = new Dictionary<int, Dictionary<string, float>>(); }

Properties

Property Description
targetTypeThe type this attribute configures: a fully specified dictionary type (for example, Dictionary<string, float>), or a key or value element type.

Constructors

Constructor Description
DictionaryDisplayForTypeAttributeCreates an attribute that configures the dictionary identified by targetType.

Inherited Members

Properties

PropertyDescription
keyColumnFractionThe initial width of the key column, as a fraction of the total dictionary width. Clamped to the range [0.01, 0.99].
keyLabelThe text displayed above the key column.
layoutThe column layout the Inspector uses to present the dictionary.
valueLabelThe text displayed above the value column.