RadialLayout.CalculateRadial C# (CSharp) Method

CalculateRadial() public method

public CalculateRadial ( ) : void
return void
    void CalculateRadial()
    {
        m_Tracker.Clear();
        if (transform.childCount == 0)
            return;

        int activeChildren = 0;
        for (int i = 0; i < transform.childCount; i++)
        {
             if( transform.GetChild(i).gameObject.activeSelf )
                 activeChildren++;
        }

        float fOffsetAngle = ((MaxAngle - MinAngle)) / (activeChildren - 1);

        if( MaxAngle - MinAngle == 360 )
            fOffsetAngle = ((MaxAngle - MinAngle)) / (activeChildren);

        float fAngle = StartAngle;
        for (int i = 0; i < activeChildren; i++)
        {
            RectTransform child = (RectTransform)transform.GetChild(i);
            if (child != null)
            {
                //Adding the elements to the tracker stops the user from modifiying their positions via the editor.
                m_Tracker.Add(this, child,
                              DrivenTransformProperties.Anchors |
                              DrivenTransformProperties.AnchoredPosition |
                              DrivenTransformProperties.Pivot);
                Vector3 vPos = new Vector3(Mathf.Cos(fAngle * Mathf.Deg2Rad), Mathf.Sin(fAngle * Mathf.Deg2Rad), 0);
                child.localPosition = vPos * fDistance;
                //Force objects to be center aligned, this can be changed however I'd suggest you keep all of the objects with the same anchor points.
                child.anchorMin = child.anchorMax = child.pivot = new Vector2(0.5f, 0.5f);
                fAngle -= fOffsetAngle;
            }
        }
    }

Usage Example

    private IEnumerator Fan(bool up)
    {
        var condition = up ? layout.MaxAngle < 360 : layout.MaxAngle > 0;

        if (layout.MaxAngle > 360)
        {
            layout.MaxAngle = 360;
        }
        else if (layout.MaxAngle <= 0)
        {
            layout.MaxAngle = 0;
        }
        while (condition)
        {
            if (up)
            {
                layout.MaxAngle += step;
            }
            else if (!up)
            {
                layout.MaxAngle -= step;
            }

            layout.CalculateRadial();

            if (layout.MaxAngle > 360)
            {
                layout.MaxAngle = 360;
            }
            else if (layout.MaxAngle < 0)
            {
                layout.MaxAngle = 0;
            }
            yield return(null);
        }

        yield return(null);
    }