On Collection Changed Attribute

OnCollectionChanged can be put on collections, and provides an event callback when the collection is about to be changed through the inspector, and when the collection has been changed through the inspector. Additionally, it provides a CollectionChangeInfo struct containing information about the exact changes made to the collection. This attribute works for all collections with a collection resolver, amongst them arrays, lists, dictionaries, hashsets, stacks and linked lists.

[InfoBox("Change the collection to get callbacks detailing the changes that are being made.")]
[OnCollectionChanged("Before", "After")]
public List<string> list = new List<string>() { "str1", "str2", "str3" };

[OnCollectionChanged("Before", "After")]
public HashSet<string> hashset = new HashSet<string>() { "str1", "str2", "str3" };

[OnCollectionChanged("Before", "After")]
public Dictionary<string, string> dictionary = new Dictionary<string, string>() { { "key1", "str1" }, { "key2", "str2" }, { "key3", "str3" } };

public void Before(CollectionChangeInfo info, object value)
{
    Debug.Log("Received callback BEFORE CHANGE with the following info: " + info + ", and the following collection instance: " + value);
}

public void After(CollectionChangeInfo info, object value)
{
    Debug.Log("Received callback AFTER CHANGE with the following info: " + info + ", and the following collection instance: " + value);
}