//Updates the data of each databinder and plays the update animation if it is an animated list private IEnumerator UpdateWithAnimation(JSONNode json) { //find what is lowest, the size fo the requested list or the current list int lowestCount = json.Count < Binders.Count ? json.Count : Binders.Count; float animationTimer = 0; foreach (DataBinder binder in Binders) { binder.GetComponent <Animator>().SetTrigger(m_animationTriggerUpdate); animationTimer = binder.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).length; } yield return(new WaitForSeconds(animationTimer / 2)); for (int i = 0; i < lowestCount; i++) { Binders[i].RegisterData(json[i]); Binders[i].BindData(); } //if there are more binders then needed, destroy the extra if (json.Count < Binders.Count) { for (int i = json.Count - 1; i < Binders.Count; i++) { DestroyImmediate(Binders[i].gameObject); Binders.RemoveAt(i); } } //if there are too few binders, generate new ones as needed else if (json.Count > Binders.Count) { int numberToGenerate = json.Count; if (m_isCapped) { if (numberToGenerate > m_maxCount) { numberToGenerate = m_maxCount; } } for (int i = Binders.Count - 1; i < numberToGenerate; i++) { DataBinder newInstance = Generator.GenerateSingleDataBinder(json[i], m_databinderPrefabToGenerate, m_holder); Binders.Add(newInstance); if (m_isAnimatedList) { if (m_databinderPrefabToGenerate.GetComponent <Animator>() == null) { Debug.LogError($"The prefab {m_databinderPrefabToGenerate.name} is missing an animator and you are trying to animate it"); } else { newInstance.GetComponent <Animator>().SetTrigger(m_animationTriggerIn); } } } } }