LoginSignup
11
10

More than 5 years have passed since last update.

UnityでListの中身をDebug.Logに表示する

Posted at

ListをそのままDebug.Log(List);とすると、型を教えてくれるだけだ。

ListDebugLog.cs
// Use this for initialization
void Start(){
    for(int i = 0; i < 10; i++)
    {
        list.Add(i);
    }

    SwhoListDebugLog(list);
}

public void ShowListDebugLog<T>(List<T> list)
{
    Debug.Log(list);
}

ListDebugLog1.png

とても不便なので、こんな感じに実装したことを備忘録代わりにここに記述しておく。

ListContentsDebugLog.cs
List<int> list = new List<int>();

// Use this for initialization
void Start () {
    for(int i = 0; i < 10; i++)
    {
        list.Add(i);
    }

    ShowListContentsInTheDebugLog(list);
}

public void ShowListContentsInTheDebugLog<T>(List<T> list)
{
    string log = "";

    foreach(var content in list.Select((val, idx) => new {val, idx}))
    {
        if (content.idx == list.Count - 1)
            log += content.val.ToString();
        else
            log += content.val.ToString() + ", ";
    }

Debug.Log(log);
}

これよりも、もっと便利な書き方があれば是非教えて頂きたい。

11
10
3

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
11
10