Skip to content

Link List

The serializable linked list allows to have the functionality of System.Collections.LinkedList but also allows to automatically serialize its values.

To create a serializable linked list, simply inherit from TSerializableLinkList<T>. For example, to create a hash set that uses GameObject types:

public MyLinkedList : TSerializableLinkList<GameObject>
{ }

You can now create a list that automatically serializes its values and use it as:

public MyComponent : MonoBehaviour
{
    public MyLinkedList list = new MyLinkedList();

    public GameObject objectA;
    public GameObject objectB;
    public GameObject objectC;

    private void Awake()
    {
        // Add element:
        this.list.Add(this.objectA);
        this.list.AddLast(this.objectB);
        this.list.AddFirst(this.objectC);

        // Print the first element:
        Debug.Log(this.list.First().name);
    }
}