Exemplo n.º 1
0
        protected void AddItems(ObjectCollection collection)
        {
            // create view items
            foreach (var item in collection)
            {
                GameObject view;
                if (bindingDictionary.TryGetValue(item, out view))
                {
                    if (viewReferenceCountDictionary == null)
                    {
                        // lazy initialization
                        InitViewReferenceCount();
                    }

                    // increase reference count
                    viewReferenceCountDictionary[view]++;

                    continue;
                }

                // create view
                view = factory.CreateItemView(item);

                // set source
                var dataContext = view.GetComponent <IDataContext>();
                dataContext.Source = item;

                // add to dictionary
                bindingDictionary.Add(item, view);

                if (viewReferenceCountDictionary != null)
                {
                    // set reference count to 1
                    viewReferenceCountDictionary.Add(view, 1);
                }
            }

            if (viewReferenceCountDictionary != null)
            {
                Assert.AreEqual(bindingDictionary.Count, viewReferenceCountDictionary.Count);
            }
        }