private void Awake()
 {
     if (transform.childCount > 0)
     {
         foreach (DataBinder binder in GetComponentsInChildren <DataBinder>())
         {
             Binders.Add(binder);
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of <see cref="InstrumentationManager"/> class.
        /// </summary>
        private InstrumentationManager()
        {
            //
            // First off, check whether the configuration section is present. If
            // it is, proceed with configuring InstrumentationManager.
            if (ConfigurationManager.ConfigurationSection != null)
            {
                //
                // Adding persisters.
                foreach (PersisterElement persister in ConfigurationManager.ConfigurationSection.Persisters)
                {
                    IPersister persisterInstance =
                        ObjectFactory.CreatePersister(persister);
                    persisterInstance.Configure(persister.CustomProperties.ToStringDictionary());

                    Persisters.Add(persister.Name, persisterInstance);
                } // foreach

                //
                // Adding formatters.
                foreach (FormatterElement formatter in ConfigurationManager.ConfigurationSection.Formatters)
                {
                    IFormatter formatterInstance = ObjectFactory.CreateFormatter(formatter);
                    FormattingManager.AddFormatter(formatterInstance);
                }

                //
                // Creating binders.
                foreach (BindingElement binding in ConfigurationManager.ConfigurationSection.Bindings)
                {
                    Binders.Add(binding.PersisterName, CreateBinder(binding));
                }

                isInstrumentationEnabled = true;
            } // if
        }
    //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);
                    }
                }
            }
        }
    }