Example #1
0
        /// <summary>
        /// Rebuilds / updates the collection layout.
        /// Update collection is called from the editor button on the inspector.
        /// </summary>
        public virtual void UpdateCollection()
        {
            PruneEmptyNodes();

            // Check when children change and adjust
            for (int i = 0; i < transform.childCount; i++)
            {
                Transform child = transform.GetChild(i);
#if UNITY_EDITOR
                UnityEditor.Undo.RecordObject(child, "ObjectCollection modify transform");
#endif // UNITY_EDITOR
                if (!ContainsNode(child) && (child.gameObject.activeSelf || !IgnoreInactiveTransforms))
                {
                    NodeList.Add(new ObjectCollectionNode {
                        Name = child.name, Transform = child
                    });
                }
            }

            SortNodes();

            LayoutChildren();

            OnCollectionUpdated?.Invoke(this);
        }
        /// <summary>
        /// Rebuilds / updates the collection layout.
        /// Update collection is called from the editor button on the inspector.
        /// </summary>
        public virtual void UpdateCollection()
        {
            // Check for empty nodes and remove them
            var emptyNodes = new List <ObjectCollectionNode>();

            for (int i = 0; i < NodeList.Count; i++)
            {
                if (NodeList[i].Transform == null || (IgnoreInactiveTransforms && !NodeList[i].Transform.gameObject.activeSelf) || NodeList[i].Transform.parent == null || !(NodeList[i].Transform.parent.gameObject == gameObject))
                {
                    emptyNodes.Add(NodeList[i]);
                }
            }

            // Now delete the empty nodes
            for (int i = 0; i < emptyNodes.Count; i++)
            {
                NodeList.Remove(emptyNodes[i]);
            }

            emptyNodes.Clear();

            // Check when children change and adjust
            for (int i = 0; i < transform.childCount; i++)
            {
                Transform child = transform.GetChild(i);

                if (!ContainsNode(child) && (child.gameObject.activeSelf || !IgnoreInactiveTransforms))
                {
                    NodeList.Add(new ObjectCollectionNode {
                        Name = child.name, Transform = child
                    });
                }
            }

            switch (SortType)
            {
            case CollationOrder.ChildOrder:
                NodeList.Sort((c1, c2) => (c1.Transform.GetSiblingIndex().CompareTo(c2.Transform.GetSiblingIndex())));
                break;

            case CollationOrder.Alphabetical:
                NodeList.Sort((c1, c2) => (string.CompareOrdinal(c1.Name, c2.Name)));
                break;

            case CollationOrder.AlphabeticalReversed:
                NodeList.Sort((c1, c2) => (string.CompareOrdinal(c1.Name, c2.Name)));
                NodeList.Reverse();
                break;

            case CollationOrder.ChildOrderReversed:
                NodeList.Sort((c1, c2) => (c1.Transform.GetSiblingIndex().CompareTo(c2.Transform.GetSiblingIndex())));
                NodeList.Reverse();
                break;
            }

            LayoutChildren();

            OnCollectionUpdated?.Invoke(this);
        }
 //Mark collection as completed so threads that wait for new items
 //will read collection to the end and leave enumeration
 public void CompleteAdding()
 {
     this.completed = true;
     lock (_eventLocker)
     {
         OnCollectionUpdated?.Invoke();
     }
 }
 //Add new item to the collection
 //and notify waiting threads about new item
 public void Add(T item)
 {
     lock (_locker)
     {
         this._list.Add(item);
         lock (_eventLocker)
         {
             OnCollectionUpdated?.Invoke();
         }
     }
 }