Beispiel #1
0
        //This is hard to make self documenting because of the ordering.
        //If a hex is not a part of the map, it should be destroyed.
        //However, you can't remove the hexagon from the HexDict while
        //iterating through the HexDict, it breaks the foreach loop
        //So there's an extra list to add the key to, in order to afterwards
        //remove that key from the hex dict

        /// <summary>
        /// Go through every hex in the HexDict and delete if it not part of the map
        /// </summary>
        private void _DeleteUnusedHexagons()
        {
            List <Vector3Int> destroyedHexes = new List <Vector3Int>();

            foreach (KeyValuePair <Vector3Int, IHexagon> hex in HexDict)
            {
                if (_ShouldDeleteThisHex(hex.Value))
                {
                    _DeleteHex(hex.Value);
                    destroyedHexes.Add(hex.Key);
                }
            }

            foreach (Vector3Int coords in destroyedHexes)
            {
                HexDict.Remove(coords);
            }
        }