Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

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

             //one liner for figuring out the desired pivot (should be moved into a utility function)
             Vector2 pivot = new Vector2(((int)childAlignment % 3) * 0.5f, ((int)childAlignment / 3) * 0.5f);

             //this seems to work ok-ish
             Vector3 lastPos = new Vector3(
                 GetStartOffset(0, GetTotalPreferredSize(0)),
                 GetStartOffset(1, GetTotalPreferredSize(1)),
                 0f
             );

             // 0 = first, 1 = last child
             float lerp = 0;
             //no need to catch divide by 0 as childCount > 0
             float step = 1f / transform.childCount;

             //normalize and create a distance between items
             var dist = itemAxis.normalized * itemSize;

             for (int i = 0; i < transform.childCount; i++) {
                 RectTransform child = (RectTransform)transform.GetChild(i);
                 if (child != null) {
                     //stop the user from altering certain values in the editor
                     m_Tracker.Add(this, child,
                     DrivenTransformProperties.Anchors |
                     DrivenTransformProperties.AnchoredPosition |
                     DrivenTransformProperties.Pivot);
                     Vector3 vPos = lastPos + dist;

                     child.localPosition = lastPos = vPos + (lerp - centerpoint) * CurveOffset;

                     child.pivot = pivot;
                     //child anchors are not yet calculated, each child should set it's own size for now
                     child.anchorMin = child.anchorMax = new Vector2(0.5f, 0.5f);
                     lerp += step;
                 }
             }

         }