LoginSignup
5
5

More than 5 years have passed since last update.

[Unity][C#]DictionaryをInspectorに表示する

Last updated at Posted at 2016-05-11

なんのことはない。

UnityのInspectorにList以外のGeneric型を表示できないけど、Dictionaryを表示したい。
そんな時はListとKeyValuePairを利用する。

public class Hoge : MonoBehaviour
{
#if DEBUG
    // Inspectorに表示するためのListを用意する
    public List<string> infos;
#endif

    private void Awake()
    {
#if DEBUG
        infos = new List<string>();
#endif
    }

    private void Start()
    {
#if DEBUG
        // KeyValuePairの値をstring変換してAddするだけ
        KeyValuePair<string, string> pair = new KeyValuePair<string, string>("foo", "bar");
        infos.Add(pair.ToString());
#endif
    }
}
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5