Exemplo n.º 1
0
            public CollectionNodeDynamic(CollectionNode node)
            {
                transform = node.transform;
                Name      = node.Name;
                Offset    = node.Offset;
                Radius    = node.Radius;

                localPositionOnStartup    = transform.localPosition;
                localEulerAnglesOnStartup = transform.localEulerAngles;
            }
Exemplo n.º 2
0
        /// <summary>
        /// Update collection is called from the editor button on the inspector.
        /// This function rebuilds / updates the layout.
        /// </summary>
        public void UpdateCollection()
        {
            // Check for empty nodes and remove them
            List <CollectionNode> emptyNodes = new List <CollectionNode>();

            for (int i = 0; i < NodeList.Count; i++)
            {
                if (NodeList[i].transform == null || (IgnoreInactiveTransforms && !NodeList[i].transform.gameObject.activeSelf))
                {
                    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 < this.transform.childCount; i++)
            {
                Transform child = this.transform.GetChild(i);

                if (!ContainsNode(child) && (child.gameObject.activeSelf || !IgnoreInactiveTransforms))
                {
                    CollectionNode node = new CollectionNode();

                    node.Name      = child.name;
                    node.transform = child;
                    NodeList.Add(node);
                }
            }

            switch (SortType)
            {
            case SortTypeEnum.None:
                break;

            case SortTypeEnum.Transform:
                NodeList.Sort(delegate(CollectionNode c1, CollectionNode c2) { return(c1.transform.GetSiblingIndex().CompareTo(c2.transform.GetSiblingIndex())); });
                break;

            case SortTypeEnum.Alphabetical:
                NodeList.Sort(delegate(CollectionNode c1, CollectionNode c2) { return(c1.Name.CompareTo(c2.Name)); });
                break;

            case SortTypeEnum.AlphabeticalReversed:
                NodeList.Sort(delegate(CollectionNode c1, CollectionNode c2) { return(c1.Name.CompareTo(c2.Name)); });
                NodeList.Reverse();
                break;

            case SortTypeEnum.TransformReversed:
                NodeList.Sort(delegate(CollectionNode c1, CollectionNode c2) { return(c1.transform.GetSiblingIndex().CompareTo(c2.transform.GetSiblingIndex())); });
                NodeList.Reverse();
                break;
            }

            _columns       = Mathf.CeilToInt(NodeList.Count / Rows);
            _width         = _columns * CellWidth;
            _height        = Rows * CellHeight;
            _halfCell      = new Vector2(CellWidth / 2f, CellHeight / 2f);
            _circumference = 2f * Mathf.PI * Radius;

            LayoutChildren();

            if (OnCollectionUpdated != null)
            {
                OnCollectionUpdated.Invoke(this);
            }
        }