Skip to content

Hash Set

The serializable hash set allows to have the functionality of System.Collections.HashSet but also allows to automatically serialize its values.

To create a serializable hash set, simply inherit from TSerializableHashSet<T>. For example, to create a hash set that uses string types:

public MyHashSet : TSerializableHash<string>
{ }

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

public MyComponent : MonoBehaviour
{
    public MyHashSet hashSet = new MyHashSet();

    private void Awake()
    {
        // Add element:
        this.hashSet.Add("Hello World");

        // Print if it can find the elements
        Debug.Log(this.hashSet.Contains("Hello World"));
        Debug.Log(this.hashSet.Contains("Foo"));
    }
}