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:

         private HashSet SetGameObjectForKey(GameObject root, AnimationClip animClip, MainlineKey mainlineKey, float time = -1)
         {
             HashSet paths = new HashSet();
             //Could do this recursively - this is easier
             Stack toProcess = new Stack(mainlineKey.GetChildren(null));

             while (toProcess.Count > 0)
             {
                 var next = toProcess.Pop();

                 paths.Add(next.RelativePath);
                 SetGameObjectForRef(root, next, time);
                 SetSpriteEvent(animClip, time, next);

                 var children = mainlineKey.GetChildren(next);
                 foreach (var child in children) toProcess.Push(child);
             }

             return paths;
         }