Adding & Removing Elements
9_ScriptableDictionaries


Last updated
9_ScriptableDictionaries


Last updated
private void Start()
{
_element = GetComponent<Element>();
//Try to add the first element of this type
if (!_scriptableDictionary.TryAdd(_element.ElementType, 1))
{
//If its already in, just increment the count
_scriptableDictionary[_element.ElementType]++;
}
}
private void OnDestroy()
{
//Decrement the count of the element
_scriptableDictionary[_element.ElementType]--;
//If the count is 0, remove the element from the dictionary
if (_scriptableDictionary[_element.ElementType] == 0)
{
_scriptableDictionary.Remove(_element.ElementType);
}
}