目次
「DictionaryDrawerSettings」属性
「DictionaryDrawerSettings」属性を使用すると
Dictionary の表示を調整できます
using Sirenix.OdinInspector; using System.Collections.Generic; public class Example : SerializedMonoBehaviour { [DictionaryDrawerSettings( DisplayMode = DictionaryDisplayOptions.Foldout )] public Dictionary<int, string> dict1; [DictionaryDrawerSettings( DisplayMode = DictionaryDisplayOptions.CollapsedFoldout )] public Dictionary<int, string> dict2; [DictionaryDrawerSettings( IsReadOnly = true )] public Dictionary<int, string> dict3; [DictionaryDrawerSettings( KeyLabel = "ID", ValueLabel = "名前" )] public Dictionary<int, string> dict4; }
使い方
DisplayMode を設定すると、
折りたたんだ状態で表示されるかどうかを設定できます
[DictionaryDrawerSettings( DisplayMode = DictionaryDisplayOptions.Foldout )] public Dictionary<int, string> dict1; [DictionaryDrawerSettings( DisplayMode = DictionaryDisplayOptions.CollapsedFoldout )] public Dictionary<int, string> dict2;
IsReadOnly を設定すると、
キーの追加や削除、変更ができなくなります
[DictionaryDrawerSettings( IsReadOnly = true )] public Dictionary<int, string> dict3;
KeyLabel や ValueLabel を設定すると、
各ラベルの表記を変更できます
[DictionaryDrawerSettings( KeyLabel = "ID", ValueLabel = "名前" )] public Dictionary<int, string> dict4;
参考サイト様
Odin Inspector and Serializer | Improve your workflow in Unity