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:

         public static void BakeTransforms(this Ref childRef, out Vector3 localPosition, out Vector3 localEulerAngles, out Vector3 localScale)
         {
             TimelineKey key = childRef.Referenced;

             localPosition = Vector3.zero;
             localScale = Vector3.one;
             localEulerAngles = Vector3.zero;

             var unmapped = childRef.Unmapped;
             var spatial = childRef.Referenced as SpatialTimelineKey;
             if (spatial != null)
             {
                 localPosition = unmapped.Position;

                 var spriteKey = key as SpriteTimelineKey;
                 if (spriteKey != null)
                 {
                     var sinA = Mathf.Sin(unmapped.Angle);
                     var cosA = Mathf.Cos(unmapped.Angle);

                     var pvt = spriteKey.GetPivotOffetFromMiddle();

                     pvt.x *= unmapped.Scale.x;
                     pvt.y *= unmapped.Scale.y;

                     var rotPX = pvt.x * cosA - pvt.y * sinA;
                     var rotPY = pvt.x * sinA + pvt.y * cosA;

                     localPosition.x += rotPX;
                     localPosition.y += rotPY;

                     localScale.x = unmapped.Scale.x;
                     localScale.y = unmapped.Scale.y;
                     localPosition.z = ((ObjectRef)childRef).ZIndex * -Z_SPACING;
                 }

                 localPosition *= PIXEL_SCALE;
                 localEulerAngles = new Vector3(0, 0, unmapped.Angle_Deg);
             }
         }