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:

         /// Creates an event to change the sprite for the specified Ref (if applicable)
         private void SetSpriteEvent(AnimationClip clip, float time, Ref reference)
         {
             var spriteKey = reference.Referenced as SpriteTimelineKey;
             //Only add event for SpriteTimelineKey objects
             if (spriteKey != null)
             {
                 if (time < 0) time = spriteKey.Time;
                 if (!spriteChangeKeys.ContainsKey(reference.RelativePath))
                 {
                     spriteChangeKeys[reference.RelativePath] = new List();
                 }

                 //Add the key to the dictionary to later build all the curves at once.
                 spriteChangeKeys[reference.RelativePath].Add(new SpriteChangeKey() { Time = time, Sprite = AssetUtils.GetSpriteAtPath(spriteKey.File.Name, spriteBaseFolder) });
             }
         }