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 Material OnAssignMaterialModel(Material defaultMaterial, Renderer renderer)
         {
             if (!UseThisImporter())
                 return null;

             // This is the only reliable place to assign materials in the import chain.
             // It kind of sucks because we have to go about making the mesh/material association in a roundabout way.

             // Note: This seems dangerous, but getting to the name of the base gameObject appears to be take some work.
             // The root gameObject, at this point, seems to have "_root" appeneded to it.
             // Once the model if finished being imported it drops this postifx
             // This is something that could change without our knowledge
             string rootName = renderer.transform.root.gameObject.name;
             int rootIndex = rootName.LastIndexOf("_root");
             if (rootIndex != -1)
             {
                 rootName = rootName.Remove(rootIndex);
             }

             ImportTiled2Unity importer = new ImportTiled2Unity();
             return importer.FixMaterialForMeshRenderer(rootName, renderer);
         }