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 static void LoadResourceAssets()
         {
             var skin = EditorGUIUtility.isProSkin ? s_DarkSkin : s_LightSkin;
             s_Cached = new Texture2D[ skin.Length ];

             for( int i = 0; i < s_Cached.Length; ++i )
             {
                 // Get image data (PNG) from base64 encoded strings.
                 byte[] imageData = Convert.FromBase64String( skin[ i ] );

                 // Gather image size from image data.
                 int texWidth, texHeight;
                 GetImageSize( imageData, out texWidth, out texHeight );

                 // Generate texture asset.
                 var tex = new Texture2D( texWidth, texHeight, TextureFormat.ARGB32, false, true );
                 tex.hideFlags = HideFlags.HideAndDontSave;
                 tex.name = "(Generated) ReorderableList:" + i;
                 tex.filterMode = FilterMode.Point;
                 tex.LoadImage( imageData );

                 s_Cached[ i ] = tex;
             }

             s_LightSkin = null;
             s_DarkSkin = null;
         }