예제 #1
0
        protected void ResetViewOrder(ObjectCollection collection)
        {
            int index = 0;

            foreach (var item in collection)
            {
                // get view
                GameObject view;
                if (!bindingDictionary.TryGetValue(item, out view))
                {
                    Debug.LogErrorFormat("Unknown item {0}", item);
                    continue;
                }

                view.transform.SetSiblingIndex(index++);
            }
        }
예제 #2
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);
            }
        }
예제 #3
0
        protected virtual void AddItems(ObjectCollection collection)
        {
            foreach (var item in collection)
            {
                // get TSource
                var source = GetSource(item);

                TTarget target;
                if (sourceToTargetMap.TryGetValue(source, out target))
                {
                    if (referenceCountDictionary == null)
                    {
                        // lazy initialization
                        InitReferenceCount();
                    }

                    // increase reference count
                    referenceCountDictionary[target]++;
                    continue;
                }

                // call create
                target = CreateTarget(source);

                // add it
                targetCollection.Add(target);
                sourceToTargetMap.Add(source, target);

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

            if (referenceCountDictionary != null)
            {
                Assert.AreEqual(sourceToTargetMap.Count, referenceCountDictionary.Count);
            }
        }
예제 #4
0
        /// <summary>
        /// Begins synchronizing.
        /// </summary>
        public void BeginSync()
        {
            if (isSyncing)
            {
                // already started
                return;
            }

            // register event
            sourceCollection.CollectionChanged += OnSourceCollectionChanged;

            // clear targets
            ClearItems();

            // add all
            var items = new ObjectCollection(sourceCollection);

            AddItems(items);

            // set flag
            isSyncing = true;
        }
예제 #5
0
 protected virtual void MoveItems(ObjectCollection collection)
 {
     // do nothing
 }
예제 #6
0
 protected virtual void ReplaceItems(ObjectCollection oldItems, ObjectCollection newItems)
 {
     RemoveItems(oldItems);
     AddItems(newItems);
 }
예제 #7
0
        protected void ResetViewOrder(IEnumerable items)
        {
            var collection = new ObjectCollection(items);

            ResetViewOrder(collection);
        }
예제 #8
0
 protected void MoveItems(ObjectCollection collection)
 {
     ResetViewOrder(collection);
 }
예제 #9
0
        protected void AddItems(IEnumerable items)
        {
            var collection = new ObjectCollection(items);

            AddItems(collection);
        }