Пример #1
0
        /// <summary>
        /// Overriding base function for laying out all the children when UpdateCollection is called.
        /// </summary>
        protected override void LayoutChildren()
        {
            var     nodeGrid = new Vector3[NodeList.Count];
            Vector3 newPos;

            // Now lets lay out the grid
            if (Layout == LayoutOrder.RowThenColumn)
            {
                columns = Mathf.CeilToInt((float)NodeList.Count / rows);
            }
            else if (Layout == LayoutOrder.ColumnThenRow)
            {
                rows = Mathf.CeilToInt((float)NodeList.Count / columns);
            }
            HalfCell = new Vector2(CellWidth * 0.5f, CellHeight * 0.5f);

            // First start with a grid then project onto surface
            ResolveGridLayout(nodeGrid, layout);

            switch (SurfaceType)
            {
            case ObjectOrientationSurfaceType.Plane:
                for (int i = 0; i < NodeList.Count; i++)
                {
                    ObjectCollectionNode node = NodeList[i];
                    newPos   = nodeGrid[i];
                    newPos.z = distance;
                    node.Transform.localPosition = newPos;
                    UpdateNodeFacing(node);
                    NodeList[i] = node;
                }
                break;

            case ObjectOrientationSurfaceType.Cylinder:
                for (int i = 0; i < NodeList.Count; i++)
                {
                    ObjectCollectionNode node = NodeList[i];
                    newPos = VectorExtensions.CylindricalMapping(nodeGrid[i], radius);
                    node.Transform.localPosition = newPos;
                    UpdateNodeFacing(node);
                    NodeList[i] = node;
                }
                break;

            case ObjectOrientationSurfaceType.Sphere:

                for (int i = 0; i < NodeList.Count; i++)
                {
                    ObjectCollectionNode node = NodeList[i];
                    newPos = VectorExtensions.SphericalMapping(nodeGrid[i], radius);
                    node.Transform.localPosition = newPos;
                    UpdateNodeFacing(node);
                    NodeList[i] = node;
                }
                break;

            case ObjectOrientationSurfaceType.Radial:
                int curColumn = 0;
                int curRow    = 1;

                for (int i = 0; i < NodeList.Count; i++)
                {
                    ObjectCollectionNode node = NodeList[i];
                    newPos = VectorExtensions.RadialMapping(nodeGrid[i], radialRange, radius, curRow, rows, curColumn, Columns);

                    if (curColumn == (Columns - 1))
                    {
                        curColumn = 0;
                        ++curRow;
                    }
                    else
                    {
                        ++curColumn;
                    }

                    node.Transform.localPosition = newPos;
                    UpdateNodeFacing(node);
                    NodeList[i] = node;
                }
                break;
            }
        }