Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created November 7, 2025 21:00
Show Gist options
  • Save unitycoder/77760d708d7fae212b3f057a4efdc10c to your computer and use it in GitHub Desktop.
Save unitycoder/77760d708d7fae212b3f057a4efdc10c to your computer and use it in GitHub Desktop.
List of lists in Inspector (Unity Editor Inspector Field)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Example : MonoBehaviour
{
public List<ListWrapper<Vector3>> example = new List<ListWrapper<Vector3>>();
public void ExampleFunctions()
{
example.Add(new ListWrapper<Vector3>("if you wish to name it"));
example.Add(new ListWrapper<Vector3>());
example[1].Name = "You can name it like this as well";
foreach (ListWrapper<Vector3> vector3s in example)
{
vector3s.Add (new Vector3 (0, 0, 0));
foreach (Vector3 vector3 in vector3s)
{
//stuff etc.
}
}
}
}
// https://discussions.unity.com/t/list-of-lists-in-inspector/688016/14
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class ListWrapper<T> : IEnumerable<T>
{
[HideInInspector]
public string Name;
[SerializeField]
private List<T> list;
public int Count { get { return list.Count; } }
public ListWrapper()
{
list = new List<T>();
}
public ListWrapper(string name)
{
list = new List<T>();
Name = name;
}
public void Add(T item)
{
list.Add(item);
}
public void Clear()
{
list.Clear();
}
public void RemoveAt (int index)
{
list.RemoveAt(index);
}
public bool Remove (T item)
{
return list.Remove(item);
}
public bool Contains (T item)
{
return list.Contains(item);
}
public T this[int key]
{
get { return list[key]; }
set { list[key] = value; }
}
public IEnumerator<T> GetEnumerator()
{
return ((IEnumerable<T>)list).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)list).GetEnumerator();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment