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++); } }
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); } }
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); } }
/// <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; }
protected virtual void MoveItems(ObjectCollection collection) { // do nothing }
protected virtual void ReplaceItems(ObjectCollection oldItems, ObjectCollection newItems) { RemoveItems(oldItems); AddItems(newItems); }
protected void ResetViewOrder(IEnumerable items) { var collection = new ObjectCollection(items); ResetViewOrder(collection); }
protected void MoveItems(ObjectCollection collection) { ResetViewOrder(collection); }
protected void AddItems(IEnumerable items) { var collection = new ObjectCollection(items); AddItems(collection); }