Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Button("Update List")]
- public void UpdateDictionary()
- {
- ref var data = ref GetData(out _);
- var dictionary = data.UpdateAtLevel;
- // Create values
- if(dictionary.Count == 0)
- {
- foreach (Transform child in transform)
- {
- dictionary.Add(child.GetSiblingIndex(), child.gameObject);
- }
- }
- // Add new values
- else if(transform.childCount > dictionary.Count)
- {
- for (int i = transform.childCount - (transform.childCount - dictionary.Count); i < transform.childCount; i++)
- {
- dictionary.Add(dictionary.Keys.Last() + 1, transform.GetChild(i).gameObject);
- }
- }
- // Remove null values
- else if(transform.childCount < dictionary.Count)
- {
- var nullValues = new List<int>();
- // get null values
- foreach (var item in dictionary)
- {
- if(item.Value.Equals(null))
- {
- nullValues.Add(item.Key);
- }
- }
- // remove 'em
- foreach (var item in nullValues)
- {
- dictionary.Remove(item);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement